Skip to content

Commit 8c52409

Browse files
selftests/mm: hugetlb_fault_after_madv: use default hugetlb page size
JIRA: https://issues.redhat.com/browse/RHEL-60023 commit 3b2faed Author: David Hildenbrand <david@redhat.com> AuthorDate: Thu Sep 26 17:20:43 2024 +0200 Commit: Andrew Morton <akpm@linux-foundation.org> CommitDate: Tue Nov 5 16:56:25 2024 -0800 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> Signed-off-by: David Hildenbrand <david@redhat.com>
1 parent bfd80b5 commit 8c52409

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tools/testing/selftests/mm/hugetlb_fault_after_madv.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
#include "vm_util.h"
1010
#include "../kselftest.h"
1111

12-
#define MMAP_SIZE (1 << 21)
1312
#define INLOOP_ITER 100
1413

15-
char *huge_ptr;
14+
static char *huge_ptr;
15+
static size_t huge_page_size;
1616

1717
/* Touch the memory while it is being madvised() */
1818
void *touch(void *unused)
@@ -30,7 +30,7 @@ void *madv(void *unused)
3030
usleep(rand() % 10);
3131

3232
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);
3434

3535
return NULL;
3636
}
@@ -47,14 +47,18 @@ int main(void)
4747

4848
srand(getpid());
4949

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+
5054
free_hugepages = get_free_hugepages();
5155
if (free_hugepages != 1) {
5256
ksft_exit_skip("This test needs one and only one page to execute. Got %lu\n",
5357
free_hugepages);
5458
}
5559

5660
while (max--) {
57-
huge_ptr = mmap(NULL, MMAP_SIZE, PROT_READ | PROT_WRITE,
61+
huge_ptr = mmap(NULL, huge_page_size, PROT_READ | PROT_WRITE,
5862
MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB,
5963
-1, 0);
6064

@@ -66,7 +70,7 @@ int main(void)
6670

6771
pthread_join(thread1, NULL);
6872
pthread_join(thread2, NULL);
69-
munmap(huge_ptr, MMAP_SIZE);
73+
munmap(huge_ptr, huge_page_size);
7074
}
7175

7276
return KSFT_PASS;

0 commit comments

Comments
 (0)