Skip to content

Commit 09b18c2

Browse files
Feng Tanggregkh
Feng Tang
authored andcommitted
selftests/mm: compaction_test: support platform with huge mount of memory
commit ab00ddd 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/20250423103645.2758-1-feng.tang@linux.alibaba.com Fixes: bd67d5c ("Test compaction of mlocked memory") Signed-off-by: Feng Tang <feng.tang@linux.alibaba.com> Acked-by: Dev Jain <dev.jain@arm.com> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com> Tested-by: Baolin Wang <baolin.wang@inux.alibaba.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Sri Jayaramappa <sjayaram@akamai.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0529646 commit 09b18c2

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 */
@@ -119,11 +121,18 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size)
119121

120122
lseek(fd, 0, SEEK_SET);
121123

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

0 commit comments

Comments
 (0)