Skip to content

Commit

Permalink
stress-mmap: add new option --mmap-write-check for opt-in write + checks
Browse files Browse the repository at this point in the history
Performing per-page value writes and read checks will force newly memory
mapped pages to be created and faulted-in. While this is a useful test
scenario, it does add a lot of overhead int the mmap stressor, and the
main aim of the stressor is to exercise mapping/remapping operations
rather than a per-page memory santiy check (there are lots of other
stressors such as the vm stressor) to do that already. Make this check
an opt-in with the new --mmap-write-check option.

Signed-off-by: Colin Ian King <[email protected]>
  • Loading branch information
ColinIanKing committed Jan 18, 2024
1 parent 26ee22d commit a2931fd
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 23 deletions.
1 change: 1 addition & 0 deletions core-opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ const struct option stress_long_options[] = {
{ "mmap-mergeable", 0, 0, OPT_mmap_mergeable },
{ "mmap-mlock", 0, 0, OPT_mmap_mlock },
{ "mmap-mmap2", 0, 0, OPT_mmap_mmap2 },
{ "mmap-write-check", 0, 0, OPT_mmap_write_check },
{ "mmapaddr", 1, 0, OPT_mmapaddr },
{ "mmapaddr-mlock", 0, 0, OPT_mmapaddr_mlock },
{ "mmapaddr-ops", 1, 0, OPT_mmapaddr_ops },
Expand Down
1 change: 1 addition & 0 deletions core-opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ typedef enum {
OPT_mmap_odirect,
OPT_mmap_ops,
OPT_mmap_osync,
OPT_mmap_write_check,

OPT_mmapaddr,
OPT_mmapaddr_mlock,
Expand Down
1 change: 1 addition & 0 deletions kernel-coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ do_stress --mmap -1 --mmap-mprotect
do_stress --mmap -1 --mmap-odirect
do_stress --mmap -1 --mmap-osync
do_stress --mmap -1 --mmap-mmap2
do_stress --mmap -1 --mmap-write-check
do_stress --mmap -1 --thrash

do_stress --mmapaddr -1 --mmapaddr-mlock
Expand Down
57 changes: 35 additions & 22 deletions stress-mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,20 @@
#define DEFAULT_MMAP_BYTES (256 * MB)

static const stress_help_t help[] = {
{ NULL, "mmap N", "start N workers stressing mmap and munmap" },
{ 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-mmap2", "use mmap2 instead of mmap (when available)" },
{ NULL, "mmap-mprotect", "enable mmap mprotect stressing" },
{ NULL, "mmap-odirect", "enable O_DIRECT on file" },
{ NULL, "mmap-ops N", "stop after N mmap bogo operations" },
{ NULL, "mmap-osync", "enable O_SYNC on file" },
{ NULL, NULL, NULL }
{ NULL, "mmap N", "start N workers stressing mmap and munmap" },
{ 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-mmap2", "use mmap2 instead of mmap (when available)" },
{ NULL, "mmap-mprotect", "enable mmap mprotect stressing" },
{ NULL, "mmap-odirect", "enable O_DIRECT on file" },
{ NULL, "mmap-ops N", "stop after N mmap bogo operations" },
{ NULL, "mmap-osync", "enable O_SYNC on file" },
{ NULL, "mmap-write-check", "set check value in each page and perform sanity read check" },
{ NULL, NULL, NULL }
};

typedef void * (*mmap_func_t)(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
Expand All @@ -66,6 +67,7 @@ typedef struct {
bool mmap_mergeable;
bool mmap_mlock;
bool mmap_mprotect;
bool mmap_write_check;
mmap_func_t mmap;
size_t mmap_prot_count;
int *mmap_prot_perms;
Expand Down Expand Up @@ -293,6 +295,11 @@ static int stress_set_mmap_mmap2(const char *opt)
return stress_set_setting_true("mmap-mmap2", opt);
}

static int stress_set_mmap_write_check(const char *opt)
{
return stress_set_setting_true("mmap-write-check", opt);
}

/*
* stress_mmap_mprotect()
* cycle through page settings on a region of mmap'd memory
Expand Down Expand Up @@ -612,11 +619,13 @@ static int stress_mmap_child(stress_args_t *args, void *ctxt)
}

/* Ensure we can write to the mapped pages */
stress_mmap_set_light(buf, sz, page_size);
if (g_opt_flags & OPT_FLAGS_VERIFY) {
if (stress_mmap_check_light(buf, sz, page_size) < 0)
pr_fail("%s: mmap'd region of %zu bytes does "
"not contain expected data\n", args->name, sz);
if (context->mmap_write_check) {
stress_mmap_set_light(buf, sz, page_size);
if (g_opt_flags & OPT_FLAGS_VERIFY) {
if (stress_mmap_check_light(buf, sz, page_size) < 0)
pr_fail("%s: mmap'd region of %zu bytes does "
"not contain expected data\n", args->name, sz);
}
}

/*
Expand Down Expand Up @@ -711,10 +720,12 @@ static int stress_mmap_child(stress_args_t *args, void *ctxt)
page_size, page_size, context->mmap_mprotect);
mapped[page] = PAGE_MAPPED;
/* Ensure we can write to the mapped page */
stress_mmap_set_light(mappings[page], page_size, page_size);
if (stress_mmap_check_light(mappings[page], page_size, page_size) < 0)
pr_fail("%s: mmap'd region of %zu bytes does "
"not contain expected data\n", args->name, page_size);
if (context->mmap_write_check) {
stress_mmap_set_light(mappings[page], page_size, page_size);
if (stress_mmap_check_light(mappings[page], page_size, page_size) < 0)
pr_fail("%s: mmap'd region of %zu bytes does "
"not contain expected data\n", args->name, page_size);
}
if (mmap_file) {
(void)shim_memset(mappings[page], (int)n, page_size);
(void)shim_msync((void *)mappings[page], page_size, ms_flags);
Expand Down Expand Up @@ -925,6 +936,7 @@ static int stress_mmap(stress_args_t *args)
(void)stress_get_setting("mmap-mlock", &context.mmap_mlock);
(void)stress_get_setting("mmap-mmap2", &mmap_mmap2);
(void)stress_get_setting("mmap-mprotect", &context.mmap_mprotect);
(void)stress_get_setting("mmap-write-check", &context.mmap_write_check);

for (all_flags = 0, i = 0; i < SIZEOF_ARRAY(mmap_prot); i++)
all_flags |= mmap_prot[i];
Expand Down Expand Up @@ -1064,6 +1076,7 @@ static const stress_opt_set_func_t opt_set_funcs[] = {
{ OPT_mmap_mprotect, stress_set_mmap_mprotect },
{ OPT_mmap_odirect, stress_set_mmap_odirect },
{ OPT_mmap_osync, stress_set_mmap_osync },
{ OPT_mmap_write_check, stress_set_mmap_write_check },
{ 0, NULL }
};

Expand Down
9 changes: 8 additions & 1 deletion stress-ng.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1)
.TH STRESS-NG 1 "9 December 2023"
.TH STRESS-NG 1 "18 January 2023"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
Expand Down Expand Up @@ -4239,6 +4239,13 @@ stop mmap stress workers after N bogo operations.
.B \-\-mmap\-osync
enable file based memory mapping and used O_SYNC synchronous I/O
integrity completion.
.TP
.B \-\-mmap\-write\-check
write into each page a unique 64 bit check value for all pages and
then read the value for a sanity check. This will force newly memory mapped
pages to be faulted-in which slows down mmap bogo-op rate. This can also
cause lock contention on page allocation and page unmapping on systems
with many CPU threads and with cgroup memory accounting.
.RE
.TP
.B Random memory map/unmap stressor
Expand Down

0 comments on commit a2931fd

Please sign in to comment.