* [PATCH] trace-replay: fill pages after allocation
@ 2024-04-07 10:20 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2024-04-07 10:20 UTC (permalink / raw)
To: spew
This makes it easier to track memory usage via `time -v'
with the GNU time(1) command (not the `time' sh builtin).
---
lib/Devel/Mwrap/trace-replay.h | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/lib/Devel/Mwrap/trace-replay.h b/lib/Devel/Mwrap/trace-replay.h
index c43cc0f..944db60 100644
--- a/lib/Devel/Mwrap/trace-replay.h
+++ b/lib/Devel/Mwrap/trace-replay.h
@@ -78,6 +78,20 @@ static void store_ptr(uintptr_t old, void *cur)
kh_val(old2cur, k) = (uintptr_t)cur;
}
+static size_t page_size;
+
+static void fill(char *c, size_t n)
+{
+ static uintptr_t max_seen;
+
+ if (n > page_size)
+ if (((uintptr_t)c - page_size + n) < max_seen)
+ max_seen = (uintptr_t)c + n * page_size;
+
+ for (size_t i = 0; i < n; i += page_size)
+ c[i] = 0x1;
+}
+
int main(int argc, char *argv[])
{
tr_ms = create_mspace(0, 0);
@@ -93,6 +107,7 @@ int main(int argc, char *argv[])
} as;
int truncated = 0;
+ page_size = getpagesize();
old2cur = ptrmap_init();
// don't fill buf all the way so we can do small reads in ENSURE_FILL:
@@ -140,6 +155,7 @@ int main(int argc, char *argv[])
err(1, "malloc(%zu) => %p",
as.do_malloc.size,
(void *)as.do_malloc.ret);
+ fill(cur, as.do_malloc.size);
store_ptr(as.do_malloc.ret, cur);
break;
@@ -150,6 +166,7 @@ int main(int argc, char *argv[])
err(1, "calloc(%zu) => %p",
as.do_calloc.size,
(void *)as.do_calloc.ret);
+ fill(cur, as.do_calloc.size);
store_ptr(as.do_calloc.ret, cur);
break;
@@ -174,6 +191,7 @@ int main(int argc, char *argv[])
cur,
as.do_realloc.size,
(void *)as.do_realloc.ret);
+ fill(rp, as.do_realloc.size);
store_ptr(as.do_realloc.ret, rp);
break;
case TR_MEMALIGN:
@@ -190,6 +208,7 @@ int main(int argc, char *argv[])
as.do_memalign.size,
(void *)as.do_memalign.ret);
}
+ fill(cur, as.do_memalign.size);
store_ptr(as.do_memalign.ret, cur);
break;
default:
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2024-04-07 10:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-07 10:20 [PATCH] trace-replay: fill pages after allocation Eric Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).