Skip to content

Commit

Permalink
stress-mmap: add opt-in randomized madvise on pages
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ColinIanKing committed Jan 18, 2024
1 parent aef94fd commit 2e265a6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions core-opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
11 changes: 6 additions & 5 deletions core-opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 16 additions & 3 deletions stress-mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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 },
Expand Down
3 changes: 3 additions & 0 deletions stress-ng.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2e265a6

Please sign in to comment.