From 90cb458cd5288ab65b4da0a494c0cf270a090acb Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Tue, 4 Nov 2025 15:23:52 -0800 Subject: [PATCH] Make mmap_stress not exceed a fixed amount of time. There's a scenarion where mmap_stress gets enough resources that twoe of the threads will starve the others, which then all take a very long time catching up committing changes. Because this test program didn't finish until all the threads had completed a fixed amount of work, essentially these threads all ended up tripping over eachother. In CI this would exceed 6h+, while originally I intended this to run in about 100s or so. Instead, cap the run time to ~30s by default. If threads exceed this time, they will immediately exit, which causes any clog in contention between the threads to drain relatively quickly. Signed-off-by: Auke Kok --- tests/src/mmap_stress.c | 23 ++++++++++++++++------- tests/tests/mmap.sh | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/tests/src/mmap_stress.c b/tests/src/mmap_stress.c index 94a41484..c541bd6b 100644 --- a/tests/src/mmap_stress.c +++ b/tests/src/mmap_stress.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -29,7 +30,7 @@ #include static int size = 0; -static int count = 0; /* XXX make this duration instead */ +static int duration = 0; struct thread_info { int nr; @@ -41,6 +42,8 @@ static void *run_test_func(void *ptr) void *buf = NULL; char *addr = NULL; struct thread_info *tinfo = ptr; + uint64_t seconds = 0; + struct timespec ts; int c = 0; int fd; ssize_t read, written, ret; @@ -61,9 +64,15 @@ static void *run_test_func(void *ptr) usleep(100000); /* 0.1sec to allow all threads to start roughly at the same time */ + clock_gettime(CLOCK_REALTIME, &ts); /* record start time */ + seconds = ts.tv_sec + duration; + for (;;) { - if (++c > count) - break; + if (++c % 16 == 0) { + clock_gettime(CLOCK_REALTIME, &ts); + if (ts.tv_sec >= seconds) + break; + } switch (rand() % 4) { case 0: /* pread */ @@ -120,7 +129,7 @@ int main(int argc, char **argv) int i; if (argc != 8) { - fprintf(stderr, "%s requires 7 arguments - size count file1 file2 file3 file4 file5\n", argv[0]); + fprintf(stderr, "%s requires 7 arguments - size duration file1 file2 file3 file4 file5\n", argv[0]); exit(-1); } @@ -130,9 +139,9 @@ int main(int argc, char **argv) exit(-1); } - count = atoi(argv[2]); - if (count < 0) { - fprintf(stderr, "invalid count, must be greater than 0\n"); + duration = atoi(argv[2]); + if (duration < 0) { + fprintf(stderr, "invalid duration, must be greater than or equal to 0\n"); exit(-1); } diff --git a/tests/tests/mmap.sh b/tests/tests/mmap.sh index bf465ce9..4b14d516 100644 --- a/tests/tests/mmap.sh +++ b/tests/tests/mmap.sh @@ -5,7 +5,7 @@ t_require_commands mmap_stress mmap_validate scoutfs xfs_io echo "== mmap_stress" -mmap_stress 8192 2000 "$T_D0/mmap_stress" "$T_D1/mmap_stress" "$T_D2/mmap_stress" "$T_D3/mmap_stress" "$T_D4/mmap_stress" | sed 's/:.*//g' | sort +mmap_stress 8192 30 "$T_D0/mmap_stress" "$T_D1/mmap_stress" "$T_D2/mmap_stress" "$T_D3/mmap_stress" "$T_D4/mmap_stress" | sed 's/:.*//g' | sort echo "== basic mmap/read/write consistency checks" mmap_validate 256 1000 "$T_D0/mmap_val1" "$T_D1/mmap_val1"