From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] trace-replay: fill pages after allocation
Date: Sun, 7 Apr 2024 10:20:15 +0000 [thread overview]
Message-ID: <20240407102015.832776-1-e@80x24.org> (raw)
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:
reply other threads:[~2024-04-07 10:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240407102015.832776-1-e@80x24.org \
--to=e@80x24.org \
--cc=spew@80x24.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).