mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kurt Lin <lylin1023@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: David Hildenbrand <david@kernel.org>,
	 "Liam R. Howlett" <liam@infradead.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	 Mike Rapoport <rppt@kernel.org>, Michal Hocko <mhocko@suse.com>,
	 Shuah Khan <shuah@kernel.org>,
	Mina Almasry <almasrymina@google.com>,
	 Sayali Patil <sayalip@linux.ibm.com>, Zi Yan <ziy@nvidia.com>,
	 Song Hu <husong@kylinos.cn>,
	linux-mm@kvack.org,  linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org,  Li Wang <li.wang@linux.dev>,
	Kurt Lin <lylin1023@gmail.com>
Subject: [PATCH 4/4] selftests/mm: fix and enable the multiple cgroups hugetlb tests
Date: Sat, 05 Dec 2026 01:32:00 +0800	[thread overview]
Message-ID: <20261205-hugetlb-charge-multi-cgroup-v1-4-e88105afc12a@gmail.com> (raw)
In-Reply-To: <20261205-hugetlb-charge-multi-cgroup-v1-0-e88105afc12a@gmail.com>

run_multiple_cgroup_test() has never worked:

 - Its sizes and limits are page counts, but unlike run_test() it never
   converts them to bytes, so all reservations fail.
 - Its checks compare page counts with differences in bytes.
 - Its local declarations, split over two lines, became
   "local x= /path", which aborts the script under set -e.
 - It calls cleanup_hugetlb_memory() without a cgroup, so the cleanup
   waits for nothing.

Fix all four and stop skipping the test. Each cgroup is now charged
exactly 3 and 5 huge pages, and the write in the second cgroup leaves
the usage of the first one unchanged.

Fixes: 29750f71a9b4 ("hugetlb_cgroup: add hugetlb_cgroup reservation tests")
Fixes: 404c04e010da ("selftests/mm: fix hugetlb pathname construction in charge_reserved_hugetlb.sh")
Signed-off-by: Kurt Lin <lylin1023@gmail.com>
---
 .../selftests/mm/charge_reserved_hugetlb.sh        | 59 +++++++++-------------
 1 file changed, 25 insertions(+), 34 deletions(-)

diff --git a/tools/testing/selftests/mm/charge_reserved_hugetlb.sh b/tools/testing/selftests/mm/charge_reserved_hugetlb.sh
index e43b7bc1ad1b..ca84c353e28f 100755
--- a/tools/testing/selftests/mm/charge_reserved_hugetlb.sh
+++ b/tools/testing/selftests/mm/charge_reserved_hugetlb.sh
@@ -283,14 +283,16 @@ function write_hugetlbfs_and_get_usage() {
 
 function cleanup_hugetlb_memory() {
   set +e
-  local cgroup="$1"
+  local cgroup
   if [[ "$(pgrep -f write_to_hugetlbfs)" != "" ]]; then
     echo killing write_to_hugetlbfs
     killall -2 write_to_hugetlbfs
     while pgrep -f write_to_hugetlbfs > /dev/null; do
       sleep 0.1
     done
-    wait_for_hugetlb_memory_to_get_depleted $cgroup
+    for cgroup in "$@"; do
+      wait_for_hugetlb_memory_to_get_depleted $cgroup
+    done
   fi
   set -e
 
@@ -345,17 +347,17 @@ function run_test() {
 }
 
 function run_multiple_cgroup_test() {
-  local size1="$1"
+  local size1=$(($1 * ${MB} * 1024 * 1024))
   local populate1="$2"
   local write1="$3"
-  local cgroup_limit1="$4"
-  local reservation_limit1="$5"
+  local cgroup_limit1=$(($4 * ${MB} * 1024 * 1024))
+  local reservation_limit1=$(($5 * ${MB} * 1024 * 1024))
 
-  local size2="$6"
+  local size2=$(($6 * ${MB} * 1024 * 1024))
   local populate2="$7"
   local write2="$8"
-  local cgroup_limit2="$9"
-  local reservation_limit2="${10}"
+  local cgroup_limit2=$(($9 * ${MB} * 1024 * 1024))
+  local reservation_limit2=$((${10} * ${MB} * 1024 * 1024))
 
   local nr_hugepages="${11}"
   local method="${12}"
@@ -392,14 +394,12 @@ function run_multiple_cgroup_test() {
   reservation_failed1=$reservation_failed
   oom_killed1=$oom_killed
 
-  local cgroup1_hugetlb_usage=\
-	  $cgroup_path/hugetlb_cgroup_test1/hugetlb.${MB_DISPLAY}${UNIT}.$fault_usage_file
-  local cgroup1_reservation_usage=\
-	  $cgroup_path/hugetlb_cgroup_test1/hugetlb.${MB_DISPLAY}${UNIT}.$reservation_usage_file
-  local cgroup2_hugetlb_usage=\
-	  $cgroup_path/hugetlb_cgroup_test2/hugetlb.${MB_DISPLAY}${UNIT}.$fault_usage_file
-  local cgroup2_reservation_usage=\
-	  $cgroup_path/hugetlb_cgroup_test2/hugetlb.${MB_DISPLAY}${UNIT}.$reservation_usage_file
+  local prefix1=$cgroup_path/hugetlb_cgroup_test1/hugetlb.${MB_DISPLAY}${UNIT}
+  local prefix2=$cgroup_path/hugetlb_cgroup_test2/hugetlb.${MB_DISPLAY}${UNIT}
+  local cgroup1_hugetlb_usage=$prefix1.$fault_usage_file
+  local cgroup1_reservation_usage=$prefix1.$reservation_usage_file
+  local cgroup2_hugetlb_usage=$prefix2.$fault_usage_file
+  local cgroup2_reservation_usage=$prefix2.$reservation_usage_file
 
   local usage_before_second_write=$(cat $cgroup1_hugetlb_usage)
   local reservation_usage_before_second_write=$(cat $cgroup1_reservation_usage)
@@ -418,7 +418,7 @@ function run_multiple_cgroup_test() {
   expect_equal "$reservation_usage_before_second_write" \
     "$(cat $cgroup1_reservation_usage)" "Reservation usage changed."
 
-  cleanup_hugetlb_memory
+  cleanup_hugetlb_memory "hugetlb_cgroup_test1" "hugetlb_cgroup_test2"
 
   local final_hugetlb=$(cat $cgroup1_hugetlb_usage)
   local final_reservation=$(cat $cgroup1_reservation_usage)
@@ -524,15 +524,6 @@ for populate in "" "-o"; do
 
         cleanup
 
-        # The "multiple cgroups" scenario (run_multiple_cgroup_test) is
-        # multiply broken and has never run in CI: a backslash
-        # line-continuation breaks its local declarations, it passes
-        # reservation sizes in bytes rather than pages (unlike
-        # run_test), and its assertions compare page counts to byte
-        # values. Skip it until properly rewritten; the two scenarios
-        # above are restored by this change.
-        continue
-
         echo
         echo
         echo
@@ -564,10 +555,10 @@ for populate in "" "-o"; do
         echo Memory charged to reservation2=$reserved_difference2
 
         if [[ "$reserve" != "-n" ]] || [[ "$populate" == "-o" ]]; then
-          expect_equal "3" "$reserved_difference1" \
+          expect_equal "$((3 * $MB * 1024 * 1024))" "$reserved_difference1" \
             "Incorrect reservations charged to cgroup 1."
 
-          expect_equal "5" "$reserved_difference2" \
+          expect_equal "$((5 * $MB * 1024 * 1024))" "$reserved_difference2" \
             "Incorrect reservation charged to cgroup 2."
 
         else
@@ -579,10 +570,10 @@ for populate in "" "-o"; do
         fi
 
         if [[ "$populate" == "-o" ]]; then
-          expect_equal "3" "$hugetlb_difference1" \
+          expect_equal "$((3 * $MB * 1024 * 1024))" "$hugetlb_difference1" \
             "Incorrect hugetlb charged to cgroup 1."
 
-          expect_equal "5" "$hugetlb_difference2" \
+          expect_equal "$((5 * $MB * 1024 * 1024))" "$hugetlb_difference2" \
             "Incorrect hugetlb charged to cgroup 2."
 
         else
@@ -609,16 +600,16 @@ for populate in "" "-o"; do
         echo Memory charged to hugtlb2=$hugetlb_difference2
         echo Memory charged to reservation2=$reserved_difference2
 
-        expect_equal "3" "$hugetlb_difference1" \
+        expect_equal "$((3 * $MB * 1024 * 1024))" "$hugetlb_difference1" \
           "Incorrect hugetlb charged to cgroup 1."
 
-        expect_equal "3" "$reserved_difference1" \
+        expect_equal "$((3 * $MB * 1024 * 1024))" "$reserved_difference1" \
           "Incorrect reservation charged to cgroup 1."
 
-        expect_equal "5" "$hugetlb_difference2" \
+        expect_equal "$((5 * $MB * 1024 * 1024))" "$hugetlb_difference2" \
           "Incorrect hugetlb charged to cgroup 2."
 
-        expect_equal "5" "$reserved_difference2" \
+        expect_equal "$((5 * $MB * 1024 * 1024))" "$reserved_difference2" \
           "Incorrected reservation charged to cgroup 2."
         echo 'PASS'
 

-- 
2.56.1


  parent reply	other threads:[~2026-12-04 17:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 17:31 [PATCH 0/4] selftests/mm: run all hugetlb cgroup reservation tests Kurt Lin
2026-12-04 17:31 ` [PATCH 1/4] selftests/mm: don't wait for a hugetlb reservation that is expected to fail Kurt Lin
2026-12-04 17:31 ` [PATCH 2/4] selftests/mm: don't use killall --wait in charge_reserved_hugetlb.sh Kurt Lin
2026-12-04 17:31 ` [PATCH 3/4] selftests/mm: restore hidden hugetlb reservation scenarios Kurt Lin
2026-12-04 17:32 ` Kurt Lin [this message]
2026-12-05  8:33 ` [PATCH 0/4] selftests/mm: run all hugetlb cgroup reservation tests Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261205-hugetlb-charge-multi-cgroup-v1-4-e88105afc12a@gmail.com \
    --to=lylin1023@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=almasrymina@google.com \
    --cc=david@kernel.org \
    --cc=husong@kylinos.cn \
    --cc=li.wang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=rppt@kernel.org \
    --cc=sayalip@linux.ibm.com \
    --cc=shuah@kernel.org \
    --cc=vbabka@kernel.org \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®