selftests: mm: fix and speedup "droppable" test
Subsystems (3)
David Hildenbrand (Arm)
maintainerPATCH 1/1 selftests: mm: fix and speedup "droppable" test
The droppable test currently relies on creating memory pressure in a child process to trigger dropping the droppable pages.
That not only takes a long time on some machines (allocating and filling all that memory), on large machines this will not work as we hardcode the area size to 134217728 bytes.
... further, we rely on timeouts to detect that memory was not dropped, which is really suboptimal.
Instead, let's just use MADV_PAGEOUT on a 2 MiB region. MADV_PAGEOUT works with droppable memory even without swap.
There is the low chance of MADV_PAGEOUT failing to drop a page because of speculative references. We'll wait 1s and retry 10 times to rule that unlikely case out as best as we can.
On a machine without swap:
$ ./droppable TAP version 13 1..1 ok 1 madvise(MADV_PAGEOUT) behavior # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
--- tools/testing/selftests/mm/droppable.c | 46 +++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 20 deletions(-)
tools/testing/selftests/mm/droppable.c +26 -20
@@ -17,10 +17,10 @@int main (int argc,char *argv[]) { -size_t alloc_size =134217728 ; -size_t page_size =getpagesize (); +const size_t alloc_size =2 *1024 *1024 ; +int retry_count =10 ; +bool dropped;void *alloc; -pid_t child;ksft_print_header ();ksft_set_plan (1 );
@@ -35,26 +35,32 @@ int main(int argc, char *argv[])exit (KSFT_FAIL ); }memset (alloc,'A' , alloc_size); -for (size_t i =0 ; i < alloc_size; i += page_size) -assert (*(uint8_t *)(alloc + i)); - - child =fork (); -assert (child >=0 ); -if (!child) { -for (;;) - *(char *)malloc (page_size) ='B' ; - } -for (bool done = false; !done;) { -for (size_t i =0 ; i < alloc_size; i += page_size) { -if (!*(uint8_t *)(alloc + i)) { - done = true; -break ; +while (retry_count--) { +if (madvise (alloc, alloc_size,MADV_PAGEOUT )) { +if (errno ==EINVAL ) { +ksft_test_result_skip ("madvise(MADV_PAGEOUT) not supported\n" ); +exit (KSFT_SKIP ); } +ksft_test_result_fail ("madvise(MADV_PAGEOUT) error: %s\n" ,strerror (errno)); +exit (KSFT_FAIL ); } + + dropped =memchr (alloc,'A' , alloc_size) ==NULL ; + +/* +* Speculative reference can temporarily prevent some +* pages from getting dropped. So sleep and retry. +* +* If a page is not droppable for 10s, something +* is seriously messed up and we want to fail. +*/ +if (dropped) +break ; +sleep (1 ); } -kill (child,SIGTERM ); -ksft_test_result_pass ("MAP_DROPPABLE: PASS\n" ); -exit (KSFT_PASS ); +ksft_test_result (dropped,"madvise(MADV_PAGEOUT) behavior\n" ); + +ksft_finished (); }
---
base-commit: d401506a8ee8ac6bc4a7767c17da036e9434a4a3
change-id: 20260611-droppable_test-3737bd791dfb
--
Cheers,
David
Quoted 25 lines · David Hildenbrand (Arm)
The droppable test currently relies on creating memory pressure in a child process to trigger dropping the droppable pages.
That not only takes a long time on some machines (allocating and filling all that memory), on large machines this will not work as we hardcode the area size to 134217728 bytes.
... further, we rely on timeouts to detect that memory was not dropped, which is really suboptimal.
Instead, let's just use
MADV_PAGEOUTon a 2 MiB region.MADV_PAGEOUTworks with droppable memory even without swap.There is the low chance of
MADV_PAGEOUTfailing to drop a page because of speculative references. We'll wait 1s and retry 10 times to rule that unlikely case out as best as we can.On a machine without swap:
$ ./droppable TAP version 13 1..1 ok 1 madvise(MADV_PAGEOUT) behavior # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
Quoted 4 lines
Reported-by Aishwarya TCV <[email protected]>Fixes 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings")Signed-off-by David Hildenbrand (Arm) <[email protected]>---
I ran this test before and after applying the patch and recorded the execution time over 5 runs on an Orion O6 board.
Before the patch, average execution time = 3.87 s
After the patch, average execution time = 0.02 s
Test results remain unaffected after this patch is applied and speedup is observed.
Quoted 84 lines
tools/testing/selftests/mm/droppable.c | 46 +++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 20 deletions(-)tools/testing/selftests/mm/droppable.c +26
-21@@ -17,10 +17,10 @@int main (int argc,char *argv[]) { -size_t alloc_size =134217728 ; -size_t page_size =getpagesize (); +const size_t alloc_size =2 *1024 *1024 ; +int retry_count =10 ; +bool dropped;void *alloc; -pid_t child;ksft_print_header ();ksft_set_plan (1 );@@ -35,26 +35,32 @@ int main(int argc, char *argv[])exit (KSFT_FAIL ); }memset (alloc,'A' , alloc_size); -for (size_t i =0 ; i < alloc_size; i += page_size) -assert (*(uint8_t *)(alloc + i)); - - child =fork (); -assert (child >=0 ); -if (!child) { -for (;;) - *(char *)malloc (page_size) ='B' ; - } -for (bool done = false; !done;) { -for (size_t i =0 ; i < alloc_size; i += page_size) { -if (!*(uint8_t *)(alloc + i)) { - done = true; -break ; +while (retry_count--) { +if (madvise (alloc, alloc_size,MADV_PAGEOUT )) { +if (errno ==EINVAL ) { +ksft_test_result_skip ("madvise(MADV_PAGEOUT) not supported\n" ); +exit (KSFT_SKIP ); } +ksft_test_result_fail ("madvise(MADV_PAGEOUT) error: %s\n" ,strerror (errno)); +exit (KSFT_FAIL ); } + + dropped =memchr (alloc,'A' , alloc_size) ==NULL ; + +/* +* Speculative reference can temporarily prevent some +* pages from getting dropped. So sleep and retry. +* +* If a page is not droppable for 10s, something +* is seriously messed up and we want to fail. +*/ +if (dropped) +break ; +sleep (1 ); } -kill (child,SIGTERM ); -ksft_test_result_pass ("MAP_DROPPABLE: PASS\n" ); -exit (KSFT_PASS ); +ksft_test_result (dropped,"madvise(MADV_PAGEOUT) behavior\n" ); + +ksft_finished (); } ---base-commit:
d401506a8ee8ac6bc4a7767c17da036e9434a4a3change-id: 20260611-droppable_test-3737bd791dfb
--
Cheers,
David
David Hildenbrand (Arm)
maintainerQuoted 28 lines · Sarthak Sharma
Quoted 25 lines · David Hildenbrand (Arm)
The droppable test currently relies on creating memory pressure in a child process to trigger dropping the droppable pages.
That not only takes a long time on some machines (allocating and filling all that memory), on large machines this will not work as we hardcode the area size to 134217728 bytes.
... further, we rely on timeouts to detect that memory was not dropped, which is really suboptimal.
Instead, let's just use
MADV_PAGEOUTon a 2 MiB region.MADV_PAGEOUTworks with droppable memory even without swap.There is the low chance of
MADV_PAGEOUTfailing to drop a page because of speculative references. We'll wait 1s and retry 10 times to rule that unlikely case out as best as we can.On a machine without swap:
$ ./droppable TAP version 13 1..1 ok 1 madvise(MADV_PAGEOUT) behavior # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
Quoted 8 lines
Quoted 4 lines
Reported-by Aishwarya TCV <[email protected]>Fixes 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings")Signed-off-by David Hildenbrand (Arm) <[email protected]>---
I ran this test before and after applying the patch and recorded the execution time over 5 runs on an Orion O6 board.
Thanks!
Quoted 1 line
Before the patch, average execution time = 3.87 s
Out of interest, how much memory did your machine have?
I ran into this myself on a 200gig machine, and there was essentially no progress ...
Signature · 3 lines
Cheers, David
Quoted 38 lines · David Hildenbrand (Arm)
Quoted 28 lines · Sarthak Sharma
Quoted 25 lines · David Hildenbrand (Arm)
The droppable test currently relies on creating memory pressure in a child process to trigger dropping the droppable pages.
That not only takes a long time on some machines (allocating and filling all that memory), on large machines this will not work as we hardcode the area size to 134217728 bytes.
... further, we rely on timeouts to detect that memory was not dropped, which is really suboptimal.
Instead, let's just use
MADV_PAGEOUTon a 2 MiB region.MADV_PAGEOUTworks with droppable memory even without swap.There is the low chance of
MADV_PAGEOUTfailing to drop a page because of speculative references. We'll wait 1s and retry 10 times to rule that unlikely case out as best as we can.On a machine without swap:
$ ./droppable TAP version 13 1..1 ok 1 madvise(MADV_PAGEOUT) behavior # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0Quoted 8 lines
Quoted 4 lines
Reported-by Aishwarya TCV <[email protected]>Fixes 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings")Signed-off-by David Hildenbrand (Arm) <[email protected]>---
I ran this test before and after applying the patch and recorded the execution time over 5 runs on an Orion O6 board.
Quoted 8 lines
Thanks!
Quoted 1 line
Before the patch, average execution time = 3.87 s
Out of interest, how much memory did your machine have?
I ran into this myself on a 200gig machine, and there was essentially no progress ...
Same here ... With the old test, I waited a quite a while and didn't see any progress ... on a 512 GiB machine.
Quoted 38 lines · David Hildenbrand (Arm)
Quoted 28 lines · Sarthak Sharma
Quoted 25 lines · David Hildenbrand (Arm)
The droppable test currently relies on creating memory pressure in a child process to trigger dropping the droppable pages.
That not only takes a long time on some machines (allocating and filling all that memory), on large machines this will not work as we hardcode the area size to 134217728 bytes.
... further, we rely on timeouts to detect that memory was not dropped, which is really suboptimal.
Instead, let's just use
MADV_PAGEOUTon a 2 MiB region.MADV_PAGEOUTworks with droppable memory even without swap.There is the low chance of
MADV_PAGEOUTfailing to drop a page because of speculative references. We'll wait 1s and retry 10 times to rule that unlikely case out as best as we can.On a machine without swap:
$ ./droppable TAP version 13 1..1 ok 1 madvise(MADV_PAGEOUT) behavior # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0Quoted 8 lines
Quoted 4 lines
Reported-by Aishwarya TCV <[email protected]>Fixes 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings")Signed-off-by David Hildenbrand (Arm) <[email protected]>---
I ran this test before and after applying the patch and recorded the execution time over 5 runs on an Orion O6 board.
Quoted 9 lines
Thanks!
Quoted 1 line
Before the patch, average execution time = 3.87 s
Out of interest, how much memory did your machine have?
I ran into this myself on a 200gig machine, and there was essentially no progress ...
My board has about 15 GiB of RAM.
Quoted 25 lines · David Hildenbrand (Arm)
The droppable test currently relies on creating memory pressure in a child process to trigger dropping the droppable pages.
That not only takes a long time on some machines (allocating and filling all that memory), on large machines this will not work as we hardcode the area size to 134217728 bytes.
... further, we rely on timeouts to detect that memory was not dropped, which is really suboptimal.
Instead, let's just use
MADV_PAGEOUTon a 2 MiB region.MADV_PAGEOUTworks with droppable memory even without swap.There is the low chance of
MADV_PAGEOUTfailing to drop a page because of speculative references. We'll wait 1s and retry 10 times to rule that unlikely case out as best as we can.On a machine without swap:
$ ./droppable TAP version 13 1..1 ok 1 madvise(MADV_PAGEOUT) behavior # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
Quoted 4 lines
Reported-by Aishwarya TCV <[email protected]>Fixes 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings")Signed-off-by David Hildenbrand (Arm) <[email protected]>---
Cool! Tested with swap both off and on, and it passed either way :D
That's what I'd expect, VM_DROPPABLE folios stay anon + non-swapbacked, so reclaim can discard them instead of swapping them out :)
Quoted 87 lines · David Hildenbrand (Arm)
The droppable test currently relies on creating memory pressure in a child process to trigger dropping the droppable pages.
That not only takes a long time on some machines (allocating and filling all that memory), on large machines this will not work as we hardcode the area size to 134217728 bytes.
... further, we rely on timeouts to detect that memory was not dropped, which is really suboptimal.
Instead, let's just use
MADV_PAGEOUTon a 2 MiB region.MADV_PAGEOUTworks with droppable memory even without swap.There is the low chance of
MADV_PAGEOUTfailing to drop a page because of speculative references. We'll wait 1s and retry 10 times to rule that unlikely case out as best as we can.On a machine without swap:
$ ./droppable TAP version 13 1..1 ok 1 madvise(MADV_PAGEOUT) behavior # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0Reported-by Aishwarya TCV <[email protected]>Fixes 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings")Signed-off-by David Hildenbrand (Arm) <[email protected]>--- tools/testing/selftests/mm/droppable.c | 46 +++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 20 deletions(-)tools/testing/selftests/mm/droppable.c +19
-17@@ -17,10 +17,10 @@int main (int argc,char *argv[]) { -size_t alloc_size =134217728 ; -size_t page_size =getpagesize (); +const size_t alloc_size =2 *1024 *1024 ; +int retry_count =10 ; +bool dropped;void *alloc; -pid_t child;ksft_print_header ();ksft_set_plan (1 );@@ -35,26 +35,32 @@ int main(int argc, char *argv[])exit (KSFT_FAIL ); }memset (alloc,'A' , alloc_size); -for (size_t i =0 ; i < alloc_size; i += page_size) -assert (*(uint8_t *)(alloc + i)); - - child =fork (); -assert (child >=0 ); -if (!child) { -for (;;) - *(char *)malloc (page_size) ='B' ; - } -for (bool done = false; !done;) { -for (size_t i =0 ; i < alloc_size; i += page_size) { -if (!*(uint8_t *)(alloc + i)) { - done = true; -break ; +while (retry_count--) { +if (madvise (alloc, alloc_size,MADV_PAGEOUT )) { +if (errno ==EINVAL ) { +ksft_test_result_skip ("madvise(MADV_PAGEOUT) not supported\n" ); +exit (KSFT_SKIP ); } +ksft_test_result_fail ("madvise(MADV_PAGEOUT) error: %s\n" ,strerror (errno)); +exit (KSFT_FAIL ); } + + dropped =memchr (alloc,'A' , alloc_size) ==NULL ; + +/* +* Speculative reference can temporarily prevent some +* pages from getting dropped. So sleep and retry. +* +* If a page is not droppable for 10s, something +* is seriously messed up and we want to fail.
tools/testing/selftests/mm/droppable.c int main(int argc, char *argv[]) · line 63
Quoted 10 lines
tools/testing/selftests/mm/droppable.c +5
-3+*/ +if (dropped) +break ; +sleep (1 ); } -kill (child,SIGTERM ); -ksft_test_result_pass ("MAP_DROPPABLE: PASS\n" ); -exit (KSFT_PASS ); +ksft_test_result (dropped,"madvise(MADV_PAGEOUT) behavior\n" );
You meant "MAP_DROPPABLE" behaviour? Perhaps that can be folded in.
Otherwise LGTM.
Quoted 17 lines
tools/testing/selftests/mm/droppable.c +2
-1+ +ksft_finished (); } ---base-commit:
d401506a8ee8ac6bc4a7767c17da036e9434a4a3change-id: 20260611-droppable_test-3737bd791dfb
--
Cheers,
David
David Hildenbrand (Arm)
maintainerQuoted 13 lines
Quoted 13 lines
tools/testing/selftests/mm/droppable.c +10
-1+/* +* Speculative reference can temporarily prevent some +* pages from getting dropped. So sleep and retry. +* +* If a page is not droppable for 10s, something +* is seriously messed up and we want to fail. +*/ +if (dropped) +break ; +sleep (1 ); } -kill (child,SIGTERM );
Quoted 5 lines
tools/testing/selftests/mm/droppable.c int main(int argc, char *argv[]) · line 63
Quoted 3 lines
tools/testing/selftests/mm/droppable.c +1
-2-ksft_test_result_pass ("MAP_DROPPABLE: PASS\n" ); -exit (KSFT_PASS ); +ksft_test_result (dropped,"madvise(MADV_PAGEOUT) behavior\n" );You meant "
MAP_DROPPABLE" behaviour? Perhaps that can be folded in.
No, I did mean "madvise(MADV_PAGEOUT)" behaves as expected with droppable pages.
Reasoning being that we might want to add some other tests in the future that trigger reclaim differently.
Thanks!
Signature · 3 lines
Cheers, David
Quoted 19 lines · David Hildenbrand (Arm)
Quoted 13 lines
Quoted 13 lines
tools/testing/selftests/mm/droppable.c +10
-1+/* +* Speculative reference can temporarily prevent some +* pages from getting dropped. So sleep and retry. +* +* If a page is not droppable for 10s, something +* is seriously messed up and we want to fail. +*/ +if (dropped) +break ; +sleep (1 ); } -kill (child,SIGTERM );Quoted 5 lines
tools/testing/selftests/mm/droppable.c int main(int argc, char *argv[]) · line 63
Quoted 3 lines
tools/testing/selftests/mm/droppable.c +1
-2-ksft_test_result_pass ("MAP_DROPPABLE: PASS\n" ); -exit (KSFT_PASS ); +ksft_test_result (dropped,"madvise(MADV_PAGEOUT) behavior\n" );You meant "
MAP_DROPPABLE" behaviour? Perhaps that can be folded in.
Quoted 4 lines
No, I did mean "
madvise(MADV_PAGEOUT)" behaves as expected with droppable pages.Reasoning being that we might want to add some other tests in the future that trigger reclaim differently.
Makes sense.
Quoted 3 lines
Thanks!
Quoted 19 lines · On Thu, 11 Jun 2026 12:01:55 +0200 "David Hildenbrand (Arm)"…
The droppable test currently relies on creating memory pressure in a child process to trigger dropping the droppable pages.
That not only takes a long time on some machines (allocating and filling all that memory), on large machines this will not work as we hardcode the area size to 134217728 bytes.
... further, we rely on timeouts to detect that memory was not dropped, which is really suboptimal.
Instead, let's just use
MADV_PAGEOUTon a 2 MiB region.MADV_PAGEOUTworks with droppable memory even without swap.There is the low chance of
MADV_PAGEOUTfailing to drop a page because of speculative references. We'll wait 1s and retry 10 times to rule that unlikely case out as best as we can.On a machine without swap:
Quoted 8 lines
$ ./droppable TAP version 13 1..1 ok 1 madvise(MADV_PAGEOUT) behavior # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0Reported-by Aishwarya TCV <[email protected]>Fixes 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings")
Because this is a fix for a test, I think not Cc-ing stable@ is ok. Further, arguably this is not a fix but an improvement? No strong opinion, just thinking loud.
Quoted 1 line
Signed-off-by David Hildenbrand (Arm) <[email protected]>
Quoted 36 lines
--- tools/testing/selftests/mm/droppable.c | 46 +++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 20 deletions(-)tools/testing/selftests/mm/droppable.c +3
-12@@ -17,10 +17,10 @@int main (int argc,char *argv[]) { -size_t alloc_size =134217728 ; -size_t page_size =getpagesize (); +const size_t alloc_size =2 *1024 *1024 ; +int retry_count =10 ; +bool dropped;void *alloc; -pid_t child;ksft_print_header ();ksft_set_plan (1 );@@ -35,26 +35,32 @@ int main(int argc, char *argv[])exit (KSFT_FAIL ); }memset (alloc,'A' , alloc_size); -for (size_t i =0 ; i < alloc_size; i += page_size) -assert (*(uint8_t *)(alloc + i)); - - child =fork (); -assert (child >=0 ); -if (!child) { -for (;;) - *(char *)malloc (page_size) ='B' ; - }
tools/testing/selftests/mm/droppable.c int main(int argc, char *argv[]) · line 43
Quoted 10 lines
tools/testing/selftests/mm/droppable.c +5
-5-for (bool done = false; !done;) { -for (size_t i =0 ; i < alloc_size; i += page_size) { -if (!*(uint8_t *)(alloc + i)) { - done = true; -break ; +while (retry_count--) { +if (madvise (alloc, alloc_size,MADV_PAGEOUT )) { +if (errno ==EINVAL ) { +ksft_test_result_skip ("madvise(MADV_PAGEOUT) not supported\n" ); +exit (KSFT_SKIP );
This check is for a case that this test is running against an old kernel that doesn't have MADV_PAGEOUT?
Assuming so, I was first thinking this check might not really needed, assuming the test runner would pick the kselftest code from the running kernel's source code. But I recalled some people do get kselftest code from random place. So this check seems nice to me.
Just thinking loud.
Thanks,
SJ
[...]
David Hildenbrand (Arm)
maintainerQuoted 27 lines · SeongJae Park
Quoted 25 lines · On Thu, 11 Jun 2026 12:01:55 +0200 "David Hildenbrand (Arm)"…
The droppable test currently relies on creating memory pressure in a child process to trigger dropping the droppable pages.
That not only takes a long time on some machines (allocating and filling all that memory), on large machines this will not work as we hardcode the area size to 134217728 bytes.
... further, we rely on timeouts to detect that memory was not dropped, which is really suboptimal.
Instead, let's just use
MADV_PAGEOUTon a 2 MiB region.MADV_PAGEOUTworks with droppable memory even without swap.There is the low chance of
MADV_PAGEOUTfailing to drop a page because of speculative references. We'll wait 1s and retry 10 times to rule that unlikely case out as best as we can.On a machine without swap:
$ ./droppable TAP version 13 1..1 ok 1 madvise(MADV_PAGEOUT) behavior # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
Quoted 6 lines
Quoted 2 lines
Reported-by Aishwarya TCV <[email protected]>Fixes 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings")Because this is a fix for a test, I think not Cc-ing stable@ is ok. Further, arguably this is not a fix but an improvement? No strong opinion, just thinking loud.
The test will hang forever on very large machines and timeout on large machines, so it's a fix not just an improvement.
I think Andrew just automatically CCs stable on any test fixes, so yeah, CC; stable makes sense for this one as well.
Quoted 41 lines
Quoted 2 lines
Signed-off-by David Hildenbrand (Arm) <[email protected]>Reviewed-by SeongJae Park <[email protected]>Quoted 36 lines
--- tools/testing/selftests/mm/droppable.c | 46 +++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 20 deletions(-)tools/testing/selftests/mm/droppable.c +3
-12@@ -17,10 +17,10 @@int main (int argc,char *argv[]) { -size_t alloc_size =134217728 ; -size_t page_size =getpagesize (); +const size_t alloc_size =2 *1024 *1024 ; +int retry_count =10 ; +bool dropped;void *alloc; -pid_t child;ksft_print_header ();ksft_set_plan (1 );@@ -35,26 +35,32 @@ int main(int argc, char *argv[])exit (KSFT_FAIL ); }memset (alloc,'A' , alloc_size); -for (size_t i =0 ; i < alloc_size; i += page_size) -assert (*(uint8_t *)(alloc + i)); - - child =fork (); -assert (child >=0 ); -if (!child) { -for (;;) - *(char *)malloc (page_size) ='B' ; - }
Quoted 13 lines
tools/testing/selftests/mm/droppable.c int main(int argc, char *argv[]) · line 43
Quoted 10 lines
tools/testing/selftests/mm/droppable.c +5
-5-for (bool done = false; !done;) { -for (size_t i =0 ; i < alloc_size; i += page_size) { -if (!*(uint8_t *)(alloc + i)) { - done = true; -break ; +while (retry_count--) { +if (madvise (alloc, alloc_size,MADV_PAGEOUT )) { +if (errno ==EINVAL ) { +ksft_test_result_skip ("madvise(MADV_PAGEOUT) not supported\n" ); +exit (KSFT_SKIP );This check is for a case that this test is running against an old kernel that doesn't have
MADV_PAGEOUT?
Yes!
Quoted 5 lines
Assuming so, I was first thinking this check might not really needed, assuming the test runner would pick the kselftest code from the running kernel's source code. But I recalled some people do get kselftest code from random place. So this check seems nice to me.
Yeah, we try to handle older kernels on a best-effort basis. This one is rather simple :)
Thanks!
Signature · 3 lines
Cheers, David
Quoted 2 lines · David Hildenbrand (Arm)
The droppable test currently relies on creating memory pressure in a child process to trigger dropping the droppable pages.
Good lord.
Quoted 4 lines
That not only takes a long time on some machines (allocating and filling all that memory), on large machines this will not work as we hardcode the area size to 134217728 bytes.
:)
Quoted 3 lines
... further, we rely on timeouts to detect that memory was not dropped, which is really suboptimal.
:))
Quoted 3 lines
Instead, let's just use
MADV_PAGEOUTon a 2 MiB region.MADV_PAGEOUTworks with droppable memory even without swap.
Good idea.
Quoted 5 lines
There is the low chance of
MADV_PAGEOUTfailing to drop a page because of speculative references. We'll wait 1s and retry 10 times to rule that unlikely case out as best as we can.
Quoted 7 lines
On a machine without swap:
$ ./droppable TAP version 13 1..1 ok 1 madvise(MADV_PAGEOUT) behavior # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
On my box, before:
$ time ./droppable TAP version 13 1..1 ok 1 MAP_DROPPABLE: PASS ./droppable 5.89s user 0.01s system 99% cpu 5.921 total
After:
$ time ./droppable TAP version 13 1..1 ok 1 madvise(MADV_PAGEOUT) behavior # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0 ./droppable 0.00s user 0.00s system 87% cpu 0.001 total
That's um. That's quite a difference.
It's good that we're doing something about slower tests :)
Quoted 4 lines
Reported-by Aishwarya TCV <[email protected]>Fixes 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings")Signed-off-by David Hildenbrand (Arm) <[email protected]>
Big improvement, thanks :)
Feel free to add:
Quoted 9 lines
--- tools/testing/selftests/mm/droppable.c | 46 +++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 20 deletions(-)tools/testing/selftests/mm/droppable.c +0
-0
tools/testing/selftests/mm/droppable.c line 20
Quoted 6 lines
tools/testing/selftests/mm/droppable.c +1
-2@@ -17,10 +17,10 @@int main (int argc,char *argv[]) { -size_t alloc_size =134217728 ; -size_t page_size =getpagesize (); +const size_t alloc_size =2 *1024 *1024 ;
I guess regardless of page size this suffices as an arbitrary range over which to check things work.
Quoted 62 lines
tools/testing/selftests/mm/droppable.c +25
-19+int retry_count =10 ; +bool dropped;void *alloc; -pid_t child;ksft_print_header ();ksft_set_plan (1 );@@ -35,26 +35,32 @@ int main(int argc, char *argv[])exit (KSFT_FAIL ); }memset (alloc,'A' , alloc_size); -for (size_t i =0 ; i < alloc_size; i += page_size) -assert (*(uint8_t *)(alloc + i)); - - child =fork (); -assert (child >=0 ); -if (!child) { -for (;;) - *(char *)malloc (page_size) ='B' ; - } -for (bool done = false; !done;) { -for (size_t i =0 ; i < alloc_size; i += page_size) { -if (!*(uint8_t *)(alloc + i)) { - done = true; -break ; +while (retry_count--) { +if (madvise (alloc, alloc_size,MADV_PAGEOUT )) { +if (errno ==EINVAL ) { +ksft_test_result_skip ("madvise(MADV_PAGEOUT) not supported\n" ); +exit (KSFT_SKIP ); } +ksft_test_result_fail ("madvise(MADV_PAGEOUT) error: %s\n" ,strerror (errno)); +exit (KSFT_FAIL ); } + + dropped =memchr (alloc,'A' , alloc_size) ==NULL ; + +/* +* Speculative reference can temporarily prevent some +* pages from getting dropped. So sleep and retry. +* +* If a page is not droppable for 10s, something +* is seriously messed up and we want to fail. +*/ +if (dropped) +break ; +sleep (1 ); } -kill (child,SIGTERM ); -ksft_test_result_pass ("MAP_DROPPABLE: PASS\n" ); -exit (KSFT_PASS ); +ksft_test_result (dropped,"madvise(MADV_PAGEOUT) behavior\n" ); + +ksft_finished (); } ---base-commit:
d401506a8ee8ac6bc4a7767c17da036e9434a4a3
Quoted 8 lines
change-id: 20260611-droppable_test-3737bd791dfb
--
Cheers,
David
Thanks, Lorenzo
David Hildenbrand (Arm)
maintainerQuoted 9 lines
Quoted 9 lines
tools/testing/selftests/mm/droppable.c | 46 +++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 20 deletions(-)tools/testing/selftests/mm/droppable.c +0
-0@@ -17,10 +17,10 @@
Quoted 8 lines
tools/testing/selftests/mm/droppable.c line 20
Quoted 5 lines
tools/testing/selftests/mm/droppable.c +1
-2int main (int argc,char *argv[]) { -size_t alloc_size =134217728 ; -size_t page_size =getpagesize (); +const size_t alloc_size =2 *1024 *1024 ;I guess regardless of page size this suffices as an arbitrary range over which to check things work.
Yes, that was my thinking. "some pages".
I was briefly wondering whether to add separate tests for THP vs. !THP, but decided to leave that for another day :)
Signature · 3 lines
Cheers, David
Lorenzo Stoakes
reviewerQuoted 18 lines · David Hildenbrand (Arm)
Quoted 9 lines
Quoted 9 lines
tools/testing/selftests/mm/droppable.c | 46 +++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 20 deletions(-)tools/testing/selftests/mm/droppable.c +0
-0@@ -17,10 +17,10 @@Quoted 8 lines
tools/testing/selftests/mm/droppable.c line 20
Quoted 5 lines
tools/testing/selftests/mm/droppable.c +1
-2int main (int argc,char *argv[]) { -size_t alloc_size =134217728 ; -size_t page_size =getpagesize (); +const size_t alloc_size =2 *1024 *1024 ;I guess regardless of page size this suffices as an arbitrary range over which to check things work.
Quoted 4 lines
Yes, that was my thinking. "some pages".
I was briefly wondering whether to add separate tests for THP vs. !THP, but decided to leave that for another day :)
Yeah we (or Claude ;) can expand and extend later, key thing here is to get the slowness sorted... :)
Quoted 5 lines
--
Cheers,David
Cheers, Lorenzo
Quoted 10 lines · David Hildenbrand (Arm)
The droppable test currently relies on creating memory pressure in a child process to trigger dropping the droppable pages.
That not only takes a long time on some machines (allocating and filling all that memory), on large machines this will not work as we hardcode the area size to 134217728 bytes.
... further, we rely on timeouts to detect that memory was not dropped, which is really suboptimal.
Quoted 6 lines
Instead, let's just use
MADV_PAGEOUTon a 2 MiB region.MADV_PAGEOUTworks with droppable memory even without swap.There is the low chance of
MADV_PAGEOUTfailing to drop a page because of speculative references. We'll wait 1s and retry 10 times to rule that unlikely case out as best as we can.
Wow, thanks! I wish I had realized the MADV_PAGEOUT behavior while developing VM_DROPPABLE in the first place. That would have made development a lot easier. I wound up just running this in a memory limited VM to test out the different behaviors, which worked decent enough for verifying things. It would be interesting to me to now experiment with vgetrandom behavior over intentionally MADV_PAGEOUT'd droppable mappings, to fuzz that the careful bookchecking of that works as intended against droppable mappings. Anyway, thanks and: