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

Configure Feed

Select the types of activity you want to include in your feed.

lib/test_vmalloc.c: minor fixes to test_vmalloc.c

If PAGE_SIZE is larger than 4k and if you have a system with a large
number of CPUs, this test can require a very large amount of memory
leading to oom-killer firing. Given the type of allocation, the kernel
won't have anything to kill, causing the system to stall.

Add a parameter to the test_vmalloc driver to represent the number of
times a percpu object will be allocated. Calculate this in
test_vmalloc.sh to be 90% of available memory or the current default of
35000, whichever is smaller.

Link: https://lkml.kernel.org/r/20251201181848.1216197-1-audra@redhat.com
Signed-off-by: Audra Mitchell <audra@redhat.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Rafael Aquini <raquini@redhat.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: "Uladzislau Rezki (Sony)" <urezki@gmail.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Audra Mitchell and committed by
Andrew Morton
a98ec863 bd4526e6

+35 -7
+7 -4
lib/test_vmalloc.c
··· 58 58 /* Add a new test case description here. */ 59 59 ); 60 60 61 + __param(int, nr_pcpu_objects, 35000, 62 + "Number of pcpu objects to allocate for pcpu_alloc_test"); 63 + 61 64 /* 62 65 * This is for synchronization of setup phase. 63 66 */ ··· 320 317 size_t size, align; 321 318 int i; 322 319 323 - pcpu = vmalloc(sizeof(void __percpu *) * 35000); 320 + pcpu = vmalloc(sizeof(void __percpu *) * nr_pcpu_objects); 324 321 if (!pcpu) 325 322 return -1; 326 323 327 - for (i = 0; i < 35000; i++) { 324 + for (i = 0; i < nr_pcpu_objects; i++) { 328 325 size = get_random_u32_inclusive(1, PAGE_SIZE / 4); 329 326 330 327 /* 331 328 * Maximum PAGE_SIZE 332 329 */ 333 - align = 1 << get_random_u32_inclusive(1, 11); 330 + align = 1 << get_random_u32_inclusive(1, PAGE_SHIFT - 1); 334 331 335 332 pcpu[i] = __alloc_percpu(size, align); 336 333 if (!pcpu[i]) 337 334 rv = -1; 338 335 } 339 336 340 - for (i = 0; i < 35000; i++) 337 + for (i = 0; i < nr_pcpu_objects; i++) 341 338 free_percpu(pcpu[i]); 342 339 343 340 vfree(pcpu);
+28 -3
tools/testing/selftests/mm/test_vmalloc.sh
··· 13 13 DRIVER="test_${TEST_NAME}" 14 14 NUM_CPUS=`grep -c ^processor /proc/cpuinfo` 15 15 16 + # Default number of times we allocate percpu objects: 17 + NR_PCPU_OBJECTS=35000 18 + 16 19 # 1 if fails 17 20 exitcode=1 18 21 ··· 29 26 PERF_PARAM="sequential_test_order=1 test_repeat_count=3" 30 27 SMOKE_PARAM="test_loop_count=10000 test_repeat_count=10" 31 28 STRESS_PARAM="nr_threads=$NUM_CPUS test_repeat_count=20" 29 + 30 + PCPU_OBJ_PARAM="nr_pcpu_objects=$NR_PCPU_OBJECTS" 32 31 33 32 check_test_requirements() 34 33 { ··· 52 47 fi 53 48 } 54 49 50 + check_memory_requirement() 51 + { 52 + # The pcpu_alloc_test allocates nr_pcpu_objects per cpu. If the 53 + # PAGE_SIZE is on the larger side it is easier to set a value 54 + # that can cause oom events during testing. Since we are 55 + # testing the functionality of vmalloc and not the oom-killer, 56 + # calculate what is 90% of available memory and divide it by 57 + # the number of online CPUs. 58 + pages=$(($(getconf _AVPHYS_PAGES) * 90 / 100 / $NUM_CPUS)) 59 + 60 + if (($pages < $NR_PCPU_OBJECTS)); then 61 + echo "Updated nr_pcpu_objects to 90% of available memory." 62 + echo "nr_pcpu_objects is now set to: $pages." 63 + PCPU_OBJ_PARAM="nr_pcpu_objects=$pages" 64 + fi 65 + } 66 + 55 67 run_performance_check() 56 68 { 57 69 echo "Run performance tests to evaluate how fast vmalloc allocation is." 58 70 echo "It runs all test cases on one single CPU with sequential order." 59 71 60 - modprobe $DRIVER $PERF_PARAM > /dev/null 2>&1 72 + check_memory_requirement 73 + modprobe $DRIVER $PERF_PARAM $PCPU_OBJ_PARAM > /dev/null 2>&1 61 74 echo "Done." 62 75 echo "Check the kernel message buffer to see the summary." 63 76 } ··· 86 63 echo "available test cases are run by NUM_CPUS workers simultaneously." 87 64 echo "It will take time, so be patient." 88 65 89 - modprobe $DRIVER $STRESS_PARAM > /dev/null 2>&1 66 + check_memory_requirement 67 + modprobe $DRIVER $STRESS_PARAM $PCPU_OBJ_PARAM > /dev/null 2>&1 90 68 echo "Done." 91 69 echo "Check the kernel ring buffer to see the summary." 92 70 } ··· 98 74 echo "Please check $0 output how it can be used" 99 75 echo "for deep performance analysis as well as stress testing." 100 76 101 - modprobe $DRIVER $SMOKE_PARAM > /dev/null 2>&1 77 + check_memory_requirement 78 + modprobe $DRIVER $SMOKE_PARAM $PCPU_OBJ_PARAM > /dev/null 2>&1 102 79 echo "Done." 103 80 echo "Check the kernel ring buffer to see the summary." 104 81 }