selftests/mm: hugetlb_madv_vs_map: add underflow test
Subsystems (3)
PATCH v4 1/1 selftests/mm: hugetlb_madv_vs_map: add underflow test
Add a test that checks for underflows when a parent unmaps the page first. Also check that when the child exits the reserve count is correct.
---
v4: address Mike's comments
v3: address Mike's comments
v2: refactor tests into 2 functions
.../testing/selftests/mm/hugepage_settings.c | 9 ++ .../testing/selftests/mm/hugepage_settings.h | 1 + .../selftests/mm/hugetlb_madv_vs_map.c | 145 +++++++++++++++--- 3 files changed, 134 insertions(+), 21 deletions(-)
tools/testing/selftests/mm/hugepage_settings.c +9 -0
@@ -449,6 +449,15 @@ unsigned long hugetlb_free_pages(unsigned long size)return read_num (path); } +unsigned long hugetlb_nr_resv_pages (unsigned long size) +{ +char path[PATH_MAX ]; + +hugetlb_sysfs_path (path,sizeof (path), size,"resv_hugepages" ); + +return read_num (path); +} +static bool __hugetlb_setup (unsigned long size,unsigned long nr) {unsigned long free =hugetlb_free_pages (size);
tools/testing/selftests/mm/hugepage_settings.h +1 -0
@@ -98,6 +98,7 @@ unsigned long default_huge_page_size(void);unsigned long hugetlb_nr_pages (unsigned long size);void hugetlb_set_nr_pages (unsigned long size,unsigned long nr);unsigned long hugetlb_free_pages (unsigned long size); +unsigned long hugetlb_nr_resv_pages (unsigned long size);static inline void hugetlb_save_settings (void ) {
tools/testing/selftests/mm/hugetlb_madv_vs_map.c +124 -21
181 lines not on this page · raw message
Signature · 5 lines
2.39.1 -- Guillaume Morin <[email protected]>
Quoted 8 lines · Guillaume Morin
Add a test that checks for underflows when a parent unmaps the page first. Also check that when the child exits the reserve count is correct.
Signed-off-by Guillaume Morin <[email protected]Cc Breno Leitao <[email protected]>Cc Mike Rapoport <[email protected]>
With some small nits below fixed
tools/testing/selftests/mm/hugetlb_madv_vs_map.c int main(void) · line 101
Quoted 11 lines
---
v4: address Mike's comments
v3: address Mike's comments
v2: refactor tests into 2 functionstools/testing/selftests/mm/hugetlb_madv_vs_map.c +1
-1@@ -100,7 +98,7 @@ int main(void) -1, 0);if ((unsigned long )huge_ptr ==-1 ) -ksft_exit_fail_msg ("Failed to allocate huge page\n" ); +ksft_exit_fail_perror ("Failed to allocate huge page\n" );
Nit: _perror() does not need "\n".
Quoted 13 lines
tools/testing/selftests/mm/hugetlb_madv_vs_map.c +7
-0pthread_create (&thread1,NULL , madv,NULL );pthread_create (&thread2,NULL , touch,NULL );@@ -120,5 +118,110 @@ int main(void) }ksft_test_result_pass ("No unexpected huge page allocations\n" ); +} + +/* We create a child process, then unmap the page in the parent while the child +* waits and verify that there is no underflow of the reserved count. We also +* verify that after the child exits, the reserved count is properly restored. +*/ +void test_underflow (void )
tools/testing/selftests/mm/hugetlb_madv_vs_map.c int main(void) · line 137
Quoted 10 lines
tools/testing/selftests/mm/hugetlb_madv_vs_map.c +10
-0+{ +pid_t pid; +int pipe_fds[2 ]; +unsigned long nr_reserved =0 ; + + huge_ptr =mmap (NULL , mmap_size,PROT_READ |PROT_WRITE , +MAP_PRIVATE |MAP_ANONYMOUS |MAP_HUGETLB ,-1 ,0 ); + +if ((unsigned long )huge_ptr ==-1 ) +ksft_exit_fail_perror ("Failed to allocate huge page\n" );
Ditto.
Quoted 6 lines
tools/testing/selftests/mm/hugetlb_madv_vs_map.c +6
-0+ + nr_reserved =hugetlb_nr_resv_pages (default_huge_page_size ()); +if (nr_reserved !=1 ) +ksft_exit_fail_msg ("Unexpected number of reserved pages: %lu, expected 1\n" , + nr_reserved); +
Signature · 2 lines
Sincerely yours, Mike.
Quoted 6 lines · Guillaume Morin
Add a test that checks for underflows when a parent unmaps the page first. Also check that when the child exits the reserve count is correct.
it seems you are missing a > at the end of your email.
Quoted 2 lines
Cc Breno Leitao <[email protected]>Cc Mike Rapoport <[email protected]>
Quoted 15 lines
tools/testing/selftests/mm/hugetlb_madv_vs_map.c +0
-7@@ -3,25 +3,16 @@* A test case that must run on a system with one and only one huge page available. * # echo 1 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages * -* During setup, the test allocates the only available page, and starts three threads: -* - thread1: -* * madvise(MADV_DONTNEED) on the allocated huge page -* - thread 2: -* * Write to the allocated huge page -* - thread 3: -* * Try to allocated an extra huge page (which must not available)
tools/testing/selftests/mm/hugetlb_madv_vs_map.c line 10
Quoted 10 lines
tools/testing/selftests/mm/hugetlb_madv_vs_map.c +2
-5-* -* The test fails if thread3 is able to allocate a page. -* -* Touching the first page after thread3's allocation will raise a SIGBUS -* * Author: Breno Leitao <[email protected]> */ +#include <limits.h> #include <pthread.h> +#include <signal.h>
nit: Are limits.h and signal.h ever used by yor new code?