From 2e265a6106150ac868855a519605ef80a69b1854 Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Thu, 18 Jan 2024 11:07:46 +0000 Subject: [PATCH] stress-mmap: add opt-in randomized madvise on pages Currently mapped pages have randomized madvise set after each mmap operation, however, this can skew the bogo-op metrics for mmap'ings which the original stressor was intended to exercise. Make this optional opt-in with the new --mmap-madvise option. Signed-off-by: Colin Ian King --- core-opts.c | 1 + core-opts.h | 11 ++++++----- stress-mmap.c | 19 ++++++++++++++++--- stress-ng.1 | 3 +++ 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/core-opts.c b/core-opts.c index a281e6d27..1b95f5a3b 100644 --- a/core-opts.c +++ b/core-opts.c @@ -501,6 +501,7 @@ const struct option stress_long_options[] = { { "mmap-async", 0, 0, OPT_mmap_async }, { "mmap-bytes", 1, 0, OPT_mmap_bytes }, { "mmap-file", 0, 0, OPT_mmap_file }, + { "mmap-madvise", 0, 0, OPT_mmap_madvise }, { "mmap-mprotect", 0, 0, OPT_mmap_mprotect }, { "mmap-odirect", 0, 0, OPT_mmap_odirect }, { "mmap-ops", 1, 0, OPT_mmap_ops }, diff --git a/core-opts.h b/core-opts.h index dd7d58426..7e1a18ae4 100644 --- a/core-opts.h +++ b/core-opts.h @@ -757,16 +757,17 @@ typedef enum { OPT_mlockmany_procs, OPT_mmap, - OPT_mmap_ops, + OPT_mmap_async, OPT_mmap_bytes, OPT_mmap_file, - OPT_mmap_async, - OPT_mmap_mprotect, - OPT_mmap_osync, - OPT_mmap_odirect, + OPT_mmap_madvise, OPT_mmap_mergeable, OPT_mmap_mlock, OPT_mmap_mmap2, + OPT_mmap_mprotect, + OPT_mmap_odirect, + OPT_mmap_ops, + OPT_mmap_osync, OPT_mmapaddr, OPT_mmapaddr_mlock, diff --git a/stress-mmap.c b/stress-mmap.c index 57d6febfc..0e5f75bd2 100644 --- a/stress-mmap.c +++ b/stress-mmap.c @@ -42,6 +42,7 @@ static const stress_help_t help[] = { { NULL, "mmap-async", "using asynchronous msyncs for file based mmap" }, { NULL, "mmap-bytes N", "mmap and munmap N bytes for each stress iteration" }, { NULL, "mmap-file", "mmap onto a file using synchronous msyncs" }, + { NULL, "mmap-madvise", "enable random madvise on mmap'd region" }, { NULL, "mmap-mergeable","where possible, flag mmap'd pages as mergeable" }, { NULL, "mmap-mlock", "attempt to mlock mmap'd pages" }, { NULL, "mmap-mprotect", "enable mmap mprotect stressing" }, @@ -60,6 +61,7 @@ typedef struct { size_t mmap_bytes; bool mmap_async; bool mmap_file; + bool mmap_madvise; bool mmap_mergeable; bool mmap_mlock; bool mmap_mprotect; @@ -275,6 +277,11 @@ static int stress_set_mmap_odirect(const char *opt) return stress_set_setting_true("mmap-odirect", opt); } +static int stress_set_mmap_madvise(const char *opt) +{ + return stress_set_setting_true("mmap-madvise", opt); +} + static int stress_set_mmap_mlock(const char *opt) { return stress_set_setting_true("mmap-mlock", opt); @@ -592,7 +599,8 @@ static int stress_mmap_child(stress_args_t *args, void *ctxt) (void)shim_memset(buf, 0xff, sz); (void)shim_msync((void *)buf, sz, ms_flags); } - (void)stress_madvise_random(buf, sz); + if (context->mmap_madvise) + (void)stress_madvise_random(buf, sz); if (context->mmap_mergeable) (void)stress_madvise_mergeable(buf, sz); (void)stress_mincore_touch_pages(buf, sz); @@ -647,7 +655,8 @@ static int stress_mmap_child(stress_args_t *args, void *ctxt) PROT_READ, MAP_FIXED, -1, 0)); } #endif - (void)stress_madvise_random(mappings[page], page_size); + if (context->mmap_madvise) + (void)stress_madvise_random(mappings[page], page_size); stress_mmap_mprotect(args->name, mappings[page], page_size, page_size, context->mmap_mprotect); } @@ -693,7 +702,8 @@ static int stress_mmap_child(stress_args_t *args, void *ctxt) if (context->mmap_mlock) (void)shim_mlock(mappings[page], page_size); (void)stress_mincore_touch_pages(mappings[page], page_size); - (void)stress_madvise_random(mappings[page], page_size); + if (context->mmap_madvise) + (void)stress_madvise_random(mappings[page], page_size); if (context->mmap_mergeable) (void)stress_madvise_mergeable(mappings[page], page_size); stress_mmap_mprotect(args->name, mappings[page], @@ -896,6 +906,7 @@ static int stress_mmap(stress_args_t *args) context.mmap_bytes = DEFAULT_MMAP_BYTES; context.mmap_async = false; context.mmap_file = false; + context.mmap_madvise = false; context.mmap_mergeable = false; context.mmap_mlock = false; context.mmap_mprotect = false; @@ -908,6 +919,7 @@ static int stress_mmap(stress_args_t *args) (void)stress_get_setting("mmap-file", &context.mmap_file); (void)stress_get_setting("mmap-osync", &mmap_osync); (void)stress_get_setting("mmap-odirect", &mmap_odirect); + (void)stress_get_setting("mmap-madvise", &context.mmap_madvise); (void)stress_get_setting("mmap-mergeable", &context.mmap_mergeable); (void)stress_get_setting("mmap-mlock", &context.mmap_mlock); (void)stress_get_setting("mmap-mmap2", &mmap_mmap2); @@ -1044,6 +1056,7 @@ static const stress_opt_set_func_t opt_set_funcs[] = { { OPT_mmap_async, stress_set_mmap_async }, { OPT_mmap_bytes, stress_set_mmap_bytes }, { OPT_mmap_file, stress_set_mmap_file }, + { OPT_mmap_madvise, stress_set_mmap_madvise }, { OPT_mmap_mergeable, stress_set_mmap_mergeable }, { OPT_mmap_mlock, stress_set_mmap_mlock }, { OPT_mmap_mmap2, stress_set_mmap_mmap2 }, diff --git a/stress-ng.1 b/stress-ng.1 index a76a79d49..85d276b9c 100644 --- a/stress-ng.1 +++ b/stress-ng.1 @@ -4211,6 +4211,9 @@ and GBytes using the suffix b, k, m or g. enable file based memory mapping and by default use synchronous msync'ing on each page. .TP +.B \-\-mmap\-madvise +enable randomized madvise(2) settings on pages. +.TP .B \-\-mmap\-mergeable mark pages as mergeable via madvise(2) where possible. .TP