Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/mm: hugetlb_fault_after_madv: use default hugetlb page size

Patch series "selftests/mm: hugetlb_fault_after_madv improvements".

Mario brought to my attention that the hugetlb_fault_after_madv test is
currently always skipped on s390x. Let's adjust the test to be
independent of the default hugetlb page size and while at it, also improve
the test output.


This patch (of 2):

We currently assume that the hugetlb page size is 2 MiB, which is why we
mmap() a 2 MiB range.

Is the default hugetlb size is larger, mmap() will fail because the range
is not suitable. If the default hugetlb size is smaller (e.g., s390x),
mmap() will fail because we would need more than one hugetlb page, but
just asserted that we have exactly one.

So let's simply use the default hugetlb page size instead of hard-coded 2
MiB, so the test isn't unconditionally skipped on architectures like
s390x.

Before this patch on s390x:
$ ./hugetlb_fault_after_madv
1..0 # SKIP Failed to allocated huge page

With this change on s390x:
$ ./hugetlb_fault_after_madv

While at it, make "huge_ptr" static.

Link: https://lkml.kernel.org/r/20240926152044.2205129-1-david@redhat.com
Link: https://lkml.kernel.org/r/20240926152044.2205129-2-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Reported-by: Mario Casquero <mcasquer@redhat.com>
Tested-by: Mario Casquero <mcasquer@redhat.com>
Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
Reviewed-by: Breno Leitao <leitao@debian.org>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

David Hildenbrand and committed by
Andrew Morton
3b2faed0 1cd1a4e7

+9 -5
+9 -5
tools/testing/selftests/mm/hugetlb_fault_after_madv.c
··· 9 9 #include "vm_util.h" 10 10 #include "../kselftest.h" 11 11 12 - #define MMAP_SIZE (1 << 21) 13 12 #define INLOOP_ITER 100 14 13 15 - char *huge_ptr; 14 + static char *huge_ptr; 15 + static size_t huge_page_size; 16 16 17 17 /* Touch the memory while it is being madvised() */ 18 18 void *touch(void *unused) ··· 30 30 usleep(rand() % 10); 31 31 32 32 for (int i = 0; i < INLOOP_ITER; i++) 33 - madvise(huge_ptr, MMAP_SIZE, MADV_DONTNEED); 33 + madvise(huge_ptr, huge_page_size, MADV_DONTNEED); 34 34 35 35 return NULL; 36 36 } ··· 47 47 48 48 srand(getpid()); 49 49 50 + huge_page_size = default_huge_page_size(); 51 + if (!huge_page_size) 52 + ksft_exit_skip("Could not detect default hugetlb page size."); 53 + 50 54 free_hugepages = get_free_hugepages(); 51 55 if (free_hugepages != 1) { 52 56 ksft_exit_skip("This test needs one and only one page to execute. Got %lu\n", ··· 58 54 } 59 55 60 56 while (max--) { 61 - huge_ptr = mmap(NULL, MMAP_SIZE, PROT_READ | PROT_WRITE, 57 + huge_ptr = mmap(NULL, huge_page_size, PROT_READ | PROT_WRITE, 62 58 MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, 63 59 -1, 0); 64 60 ··· 70 66 71 67 pthread_join(thread1, NULL); 72 68 pthread_join(thread2, NULL); 73 - munmap(huge_ptr, MMAP_SIZE); 69 + munmap(huge_ptr, huge_page_size); 74 70 } 75 71 76 72 return KSFT_PASS;