mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] selftests/mm: skip hugetlb cgroup v2 tests without the needed controllers
@ 2026-10-16 12:54 Qiliang Yuan
  2026-10-16 17:48 ` Joshua Hahn
  0 siblings, 1 reply; 2+ messages in thread
From: Qiliang Yuan @ 2026-10-16 12:54 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Shuah Khan, Mina Almasry,
	Muchun Song, Oscar Salvador
  Cc: linux-mm, linux-kselftest, linux-kernel, Qiliang Yuan

With -cgroup-v2, charge_reserved_hugetlb.sh and
hugetlb_reparenting_test.sh mount a cgroup2 hierarchy on a temporary
directory when none is mounted and enable the hugetlb controller
(hugetlb_reparenting_test.sh also enables memory) in its
cgroup.subtree_control.

On a system that still binds these controllers to cgroup v1, they are
not available in the new hierarchy. Writing to cgroup.subtree_control
fails with ENOENT, "set -e" aborts the script, the test is reported as
failed, and the temporary cgroup2 mount is left behind.

Check cgroup.controllers first, and skip the test when a controller is
missing, after unmounting the hierarchy and removing the directory the
script created.

With hugetlb and memory bound to cgroup v1, per script:

                                before      after
  result                        fail        skip
  cgroup2 mounts left behind       1           0

Fixes: 29750f71a9b4 ("hugetlb_cgroup: add hugetlb_cgroup reservation tests")
Signed-off-by: Qiliang Yuan <odys.yuan@gmail.com>
---
 tools/testing/selftests/mm/charge_reserved_hugetlb.sh  |  8 ++++++++
 tools/testing/selftests/mm/hugetlb_reparenting_test.sh | 10 ++++++++++
 2 files changed, 18 insertions(+)

diff --git a/tools/testing/selftests/mm/charge_reserved_hugetlb.sh b/tools/testing/selftests/mm/charge_reserved_hugetlb.sh
index a1cfd3a349db6..65065b1377b24 100755
--- a/tools/testing/selftests/mm/charge_reserved_hugetlb.sh
+++ b/tools/testing/selftests/mm/charge_reserved_hugetlb.sh
@@ -39,6 +39,14 @@ if [[ $cgroup2 ]]; then
     mount -t cgroup2 none $cgroup_path
     do_umount=1
   fi
+  if ! grep -qw hugetlb $cgroup_path/cgroup.controllers; then
+    echo "hugetlb controller not available in cgroup v2. Skipping..."
+    if [[ $do_umount ]]; then
+      umount $cgroup_path
+      rmdir $cgroup_path
+    fi
+    exit $ksft_skip
+  fi
   echo "+hugetlb" >$cgroup_path/cgroup.subtree_control
 else
   cgroup_path=$(mount -t cgroup | grep ",hugetlb" | awk '{print $3}')
diff --git a/tools/testing/selftests/mm/hugetlb_reparenting_test.sh b/tools/testing/selftests/mm/hugetlb_reparenting_test.sh
index 95f517c3bd167..811912ae7d975 100755
--- a/tools/testing/selftests/mm/hugetlb_reparenting_test.sh
+++ b/tools/testing/selftests/mm/hugetlb_reparenting_test.sh
@@ -29,6 +29,16 @@ if [[ $cgroup2 ]]; then
     mount -t cgroup2 none $CGROUP_ROOT
     do_umount=1
   fi
+  for ctrl in hugetlb memory; do
+    if ! grep -qw $ctrl $CGROUP_ROOT/cgroup.controllers; then
+      echo "$ctrl controller not available in cgroup v2. Skipping..."
+      if [[ $do_umount ]]; then
+        umount $CGROUP_ROOT
+        rmdir $CGROUP_ROOT
+      fi
+      exit $ksft_skip
+    fi
+  done
   echo "+hugetlb +memory" >$CGROUP_ROOT/cgroup.subtree_control
 else
   CGROUP_ROOT=$(mount -t cgroup | grep ",hugetlb" | awk '{print $3}')

---
base-commit: 437a7e839def0f505277022622fc59a8b071d6cf
change-id: 20261016-bug-selftests-mm-hugetlb-cgroup2-skip-7fc0316486f2

Best regards,
-- 
Qiliang Yuan <odys.yuan@gmail.com>


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] selftests/mm: skip hugetlb cgroup v2 tests without the needed controllers
  2026-10-16 12:54 [PATCH] selftests/mm: skip hugetlb cgroup v2 tests without the needed controllers Qiliang Yuan
@ 2026-10-16 17:48 ` Joshua Hahn
  0 siblings, 0 replies; 2+ messages in thread
From: Joshua Hahn @ 2026-10-16 17:48 UTC (permalink / raw)
  To: Qiliang Yuan
  Cc: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Shuah Khan, Mina Almasry,
	Muchun Song, Oscar Salvador, linux-mm, linux-kselftest,
	linux-kernel

On Fri, 16 Oct 2026 20:54:48 +0800 Qiliang Yuan <odys.yuan@gmail.com> wrote:

> With -cgroup-v2, charge_reserved_hugetlb.sh and
> hugetlb_reparenting_test.sh mount a cgroup2 hierarchy on a temporary
> directory when none is mounted and enable the hugetlb controller
> (hugetlb_reparenting_test.sh also enables memory) in its
> cgroup.subtree_control.
> 
> On a system that still binds these controllers to cgroup v1, they are
> not available in the new hierarchy. Writing to cgroup.subtree_control
> fails with ENOENT, "set -e" aborts the script, the test is reported as
> failed, and the temporary cgroup2 mount is left behind.
> 
> Check cgroup.controllers first, and skip the test when a controller is
> missing, after unmounting the hierarchy and removing the directory the
> script created.
> 
> With hugetlb and memory bound to cgroup v1, per script:
> 
>                                 before      after
>   result                        fail        skip
>   cgroup2 mounts left behind       1           0
> 
> Fixes: 29750f71a9b4 ("hugetlb_cgroup: add hugetlb_cgroup reservation tests")
> Signed-off-by: Qiliang Yuan <odys.yuan@gmail.com>

Hi Qiliang,

Thanks for the fixes. I think the problem you're describing is real and
the fix does address it. Sashiko raised a concern about failing tests
after this and leading to leaks [1].

At first I thought what Sashiko said made sense, but taking a step back
this SKIP path can be taken when we're mounted with v1, and the new
skip would prevent us from failing anyways so... I think it might
actually be OK, we probably can't reach the failure case once we skip.

( of course unless, I'm missing something ; -) )

LGTM!

Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>

[1] https://fb.workplace.com/photo/?fbid=2894459417496799&set=g.190352285091763

> ---
>  tools/testing/selftests/mm/charge_reserved_hugetlb.sh  |  8 ++++++++
>  tools/testing/selftests/mm/hugetlb_reparenting_test.sh | 10 ++++++++++
>  2 files changed, 18 insertions(+)
> 
> diff --git a/tools/testing/selftests/mm/charge_reserved_hugetlb.sh b/tools/testing/selftests/mm/charge_reserved_hugetlb.sh
> index a1cfd3a349db6..65065b1377b24 100755
> --- a/tools/testing/selftests/mm/charge_reserved_hugetlb.sh
> +++ b/tools/testing/selftests/mm/charge_reserved_hugetlb.sh
> @@ -39,6 +39,14 @@ if [[ $cgroup2 ]]; then
>      mount -t cgroup2 none $cgroup_path
>      do_umount=1
>    fi
> +  if ! grep -qw hugetlb $cgroup_path/cgroup.controllers; then
> +    echo "hugetlb controller not available in cgroup v2. Skipping..."
> +    if [[ $do_umount ]]; then
> +      umount $cgroup_path
> +      rmdir $cgroup_path
> +    fi
> +    exit $ksft_skip
> +  fi
>    echo "+hugetlb" >$cgroup_path/cgroup.subtree_control
>  else
>    cgroup_path=$(mount -t cgroup | grep ",hugetlb" | awk '{print $3}')
> diff --git a/tools/testing/selftests/mm/hugetlb_reparenting_test.sh b/tools/testing/selftests/mm/hugetlb_reparenting_test.sh
> index 95f517c3bd167..811912ae7d975 100755
> --- a/tools/testing/selftests/mm/hugetlb_reparenting_test.sh
> +++ b/tools/testing/selftests/mm/hugetlb_reparenting_test.sh
> @@ -29,6 +29,16 @@ if [[ $cgroup2 ]]; then
>      mount -t cgroup2 none $CGROUP_ROOT
>      do_umount=1
>    fi
> +  for ctrl in hugetlb memory; do
> +    if ! grep -qw $ctrl $CGROUP_ROOT/cgroup.controllers; then
> +      echo "$ctrl controller not available in cgroup v2. Skipping..."
> +      if [[ $do_umount ]]; then
> +        umount $CGROUP_ROOT
> +        rmdir $CGROUP_ROOT
> +      fi
> +      exit $ksft_skip
> +    fi
> +  done
>    echo "+hugetlb +memory" >$CGROUP_ROOT/cgroup.subtree_control
>  else
>    CGROUP_ROOT=$(mount -t cgroup | grep ",hugetlb" | awk '{print $3}')
> 
> ---
> base-commit: 437a7e839def0f505277022622fc59a8b071d6cf
> change-id: 20261016-bug-selftests-mm-hugetlb-cgroup2-skip-7fc0316486f2
> 
> Best regards,
> -- 
> Qiliang Yuan <odys.yuan@gmail.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-16 17:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-16 12:54 [PATCH] selftests/mm: skip hugetlb cgroup v2 tests without the needed controllers Qiliang Yuan
2026-10-16 17:48 ` Joshua Hahn

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®