Skip to content

Commit c614d85

Browse files
Feng Tangvijay-suman
authored andcommitted
selftests/mm: compaction_test: support platform with huge mount of memory
commit ab00ddd802f80e31fc9639c652d736fe3913feae upstream. When running mm selftest to verify mm patches, 'compaction_test' case failed on an x86 server with 1TB memory. And the root cause is that it has too much free memory than what the test supports. The test case tries to allocate 100000 huge pages, which is about 200 GB for that x86 server, and when it succeeds, it expects it's large than 1/3 of 80% of the free memory in system. This logic only works for platform with 750 GB ( 200 / (1/3) / 80% ) or less free memory, and may raise false alarm for others. Fix it by changing the fixed page number to self-adjustable number according to the real number of free memory. Link: https://lkml.kernel.org/r/[email protected] Fixes: bd67d5c ("Test compaction of mlocked memory") Signed-off-by: Feng Tang <[email protected]> Acked-by: Dev Jain <[email protected]> Reviewed-by: Baolin Wang <[email protected]> Tested-by: Baolin Wang <[email protected]> Cc: Shuah Khan <[email protected]> Cc: Sri Jayaramappa <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit ef3a6d37950680654be8be4406189f74ec94c8d6) Signed-off-by: Vijayendra Suman <[email protected]>
1 parent 183e4d4 commit c614d85

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

tools/testing/selftests/vm/compaction_test.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size)
8989
int compaction_index = 0;
9090
char initial_nr_hugepages[20] = {0};
9191
char nr_hugepages[20] = {0};
92+
char target_nr_hugepages[24] = {0};
93+
int slen;
9294

9395
/* We want to test with 80% of available memory. Else, OOM killer comes
9496
in to play */
@@ -118,11 +120,18 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size)
118120

119121
lseek(fd, 0, SEEK_SET);
120122

121-
/* Request a large number of huge pages. The Kernel will allocate
122-
as much as it can */
123-
if (write(fd, "100000", (6*sizeof(char))) != (6*sizeof(char))) {
124-
ksft_test_result_fail("Failed to write 100000 to /proc/sys/vm/nr_hugepages: %s\n",
125-
strerror(errno));
123+
/*
124+
* Request huge pages for about half of the free memory. The Kernel
125+
* will allocate as much as it can, and we expect it will get at least 1/3
126+
*/
127+
nr_hugepages_ul = mem_free / hugepage_size / 2;
128+
snprintf(target_nr_hugepages, sizeof(target_nr_hugepages),
129+
"%lu", nr_hugepages_ul);
130+
131+
slen = strlen(target_nr_hugepages);
132+
if (write(fd, target_nr_hugepages, slen) != slen) {
133+
ksft_test_result_fail("Failed to write %lu to /proc/sys/vm/nr_hugepages: %s\n",
134+
nr_hugepages_ul, strerror(errno));
126135
goto close_fd;
127136
}
128137

0 commit comments

Comments
 (0)