]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/cgroup: enable memory controller in hugetlb memcg test
authorGuopeng Zhang <zhangguopeng@kylinos.cn>
Wed, 20 May 2026 09:31:30 +0000 (17:31 +0800)
committerTejun Heo <tj@kernel.org>
Fri, 22 May 2026 16:20:43 +0000 (06:20 -1000)
test_hugetlb_memcg creates a child cgroup and then writes memory.max and
memory.swap.max. When the test is run standalone, the memory controller
may not be enabled in the test root cgroup's subtree_control.

In that case, the child cgroup is created without the memory control
files, and the test fails during setup before reaching the hugetlb memcg
accounting checks.

Skip the test when the memory controller is unavailable. Otherwise, enable
it in subtree_control before creating the test cgroup.

Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
Acked-by: Michal Koutný <mkoutny@suse.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
tools/testing/selftests/cgroup/test_hugetlb_memcg.c

index f451aa449be6fd175dea35930555202e06cbb096..b627d84358b1b46f06d218f5aad3614e6f14ba5e 100644 (file)
@@ -217,6 +217,14 @@ int main(int argc, char **argv)
        if (cg_find_unified_root(root, sizeof(root), NULL))
                ksft_exit_skip("cgroup v2 isn't mounted\n");
 
+       if (cg_read_strstr(root, "cgroup.controllers", "memory"))
+               ksft_exit_skip("memory controller isn't available\n");
+
+       if (cg_read_strstr(root, "cgroup.subtree_control", "memory")) {
+               if (cg_write(root, "cgroup.subtree_control", "+memory"))
+                       ksft_exit_skip("Failed to set memory controller\n");
+       }
+
        switch (test_hugetlb_memcg(root)) {
        case KSFT_PASS:
                ksft_test_result_pass("test_hugetlb_memcg\n");