]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/mm: run_vmtests.sh: free memory if available memory is low
authorMike Rapoport (Microsoft) <rppt@kernel.org>
Mon, 11 May 2026 16:28:38 +0000 (19:28 +0300)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 21 Jun 2026 18:37:31 +0000 (11:37 -0700)
Currently when running THP and HugeTLB tests, if HAVE_HUGEPAGES is set
run_test() drops caches, compacts memory and runs the test.  But if
HAVE_HUGEPAGES is not set it skips the tests entirely, even if THP tests
have nothing to do with HAVE_HUGEPAGES.

Replace the check if HAVE_HUGEPAGES is set with a check of how much memory
is available.  If there is less than 256 MB of available memory, drop
caches and run compaction and then continue to run a test regardless of
HAVE_HUGEPAGES value.

Link: https://lore.kernel.org/20260511162840.375890-55-rppt@kernel.org
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Tested-by: Luiz Capitulino <luizcap@redhat.com>
Tested-by: Sarthak Sharma <sarthak.sharma@arm.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Donet Tom <donettom@linux.ibm.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Liam Howlett <liam@infradead.org>
Cc: Li Wang <li.wang@linux.dev>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Mark Brown <broonie@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Nico Pache <npache@redhat.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/testing/selftests/mm/run_vmtests.sh

index 8453be45ab18335da390c54c116eee05dd45ad56..524c79b423443100c207ccb2b2bf1b8d7ffdab5c 100755 (executable)
@@ -234,19 +234,17 @@ pretty_name() {
 # Usage: run_test [test binary] [arbitrary test arguments...]
 run_test() {
        if test_selected ${CATEGORY}; then
-               local skip=0
-
                # On memory constrainted systems some tests can fail to allocate hugepages.
                # perform some cleanup before the test for a higher success rate.
                if [ ${CATEGORY} == "thp" -o ${CATEGORY} == "hugetlb" ]; then
-                       if [ "${HAVE_HUGEPAGES}" = "1" ]; then
+                       mem_kb=$(awk '/MemAvailable/ {print $2}' /proc/meminfo)
+                       mem_Mb=$((mem_kb / 1024))
+
+                       if (( $mem_Mb < 256 )); then
                                echo 3 > /proc/sys/vm/drop_caches
                                sleep 2
                                echo 1 > /proc/sys/vm/compact_memory
                                sleep 2
-                       else
-                               echo "hugepages not supported" | tap_prefix
-                               skip=1
                        fi
                fi
 
@@ -255,12 +253,8 @@ run_test() {
                local sep=$(echo -n "$title" | tr "[:graph:][:space:]" -)
                printf "%s\n%s\n%s\n" "$sep" "$title" "$sep" | tap_prefix
 
-               if [ "${skip}" != "1" ]; then
-                       ("$@" 2>&1) | tap_prefix
-                       local ret=${PIPESTATUS[0]}
-               else
-                       local ret=$ksft_skip
-               fi
+                ("$@" 2>&1) | tap_prefix
+                local ret=${PIPESTATUS[0]}
                count_total=$(( count_total + 1 ))
                if [ $ret -eq 0 ]; then
                        count_pass=$(( count_pass + 1 ))