Skip to content

Commit b665eed

Browse files
Dev Jainakpm00
authored andcommitted
selftests/mm: hugetlb_madv_vs_map: avoid test skipping by querying hugepage size at runtime
Currently, the size used in mmap() is statically defined, leading to skipping of the test on a hugepage size other than 2 MB, since munmap() won't free the hugepage for a size greater than 2 MB. Hence, query the size at runtime. Also, there is no reason why a hugepage allocation should fail, since we are using a simple mmap() using MAP_HUGETLB; hence, instead of skipping the test, make it fail. Link: https://lkml.kernel.org/r/20240509095447.3791573-1-dev.jain@arm.com Signed-off-by: Dev Jain <dev.jain@arm.com> Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com> Cc: Anshuman Khandual <anshuman.khandual@arm.com> Cc: Shuah Khan <shuah@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 88e4f52 commit b665eed

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

tools/testing/selftests/mm/hugetlb_madv_vs_map.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
#include "vm_util.h"
2828
#include "../kselftest.h"
2929

30-
#define MMAP_SIZE (1 << 21)
3130
#define INLOOP_ITER 100
3231

32+
size_t mmap_size;
3333
char *huge_ptr;
3434

3535
/* Touch the memory while it is being madvised() */
@@ -44,7 +44,7 @@ void *touch(void *unused)
4444
void *madv(void *unused)
4545
{
4646
for (int i = 0; i < INLOOP_ITER; i++)
47-
madvise(huge_ptr, MMAP_SIZE, MADV_DONTNEED);
47+
madvise(huge_ptr, mmap_size, MADV_DONTNEED);
4848

4949
return NULL;
5050
}
@@ -59,7 +59,7 @@ void *map_extra(void *unused)
5959
void *ptr;
6060

6161
for (int i = 0; i < INLOOP_ITER; i++) {
62-
ptr = mmap(NULL, MMAP_SIZE, PROT_READ | PROT_WRITE,
62+
ptr = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE,
6363
MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB,
6464
-1, 0);
6565

@@ -93,14 +93,16 @@ int main(void)
9393
free_hugepages);
9494
}
9595

96+
mmap_size = default_huge_page_size();
97+
9698
while (max--) {
97-
huge_ptr = mmap(NULL, MMAP_SIZE, PROT_READ | PROT_WRITE,
99+
huge_ptr = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE,
98100
MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB,
99101
-1, 0);
100102

101103
if ((unsigned long)huge_ptr == -1) {
102-
ksft_exit_skip("Failed to allocated huge page\n");
103-
return KSFT_SKIP;
104+
ksft_test_result_fail("Failed to allocate huge page\n");
105+
return KSFT_FAIL;
104106
}
105107

106108
pthread_create(&thread1, NULL, madv, NULL);
@@ -117,7 +119,7 @@ int main(void)
117119
}
118120

119121
/* Unmap and restart */
120-
munmap(huge_ptr, MMAP_SIZE);
122+
munmap(huge_ptr, mmap_size);
121123
}
122124

123125
return KSFT_PASS;

0 commit comments

Comments
 (0)