[LTP] [PATCH] cgroup: make regression test compatible with cgroup v2

Li Wang liwang@redhat.com
Fri Apr 3 04:30:31 CEST 2026


Hi Soma,

First, thank you for cleanup this test. Yes, it is only compatible
on Cgroup v1, and it's definately could compatible v2 just with
some adjutment.

But I'd like suggest to make use of the LTP standard Cgroup API, for
version-check, mount/unmount, ctrl-file set, etc.

You can take a look at the cgroup_lib.sh, I think it will be more
convenient to reuse the mature APIs.

>  test2()
>  {
> +	if mount | grep -q "type cgroup2"; then
> +		tst_res TCONF "cgroup v2 already active - cannot mount v1 on this kernel"
> +		return
> +	fi
> +
>  	local val1
>  	local val2
> -	local cgroup_version
> +	local cgroup_mount="$PWD/cgroup"
>  

> -	cgroup_require "memory"
> -	cgroup_version=$(cgroup_get_version "memory")
> -	if [ "$cgroup_version" = "2" ]; then
> -		tst_res TCONF "This test requires cgroup v1, but system is using cgroup v2"
> -		cgroup_cleanup

The code you removed here is actually what we recommended as a way to
check the system's cgroup version :).

We can not simply rely on kernel versions to think the cgroup versions,
because for different Linux distributions, it may backport the new
feature to old kernels, and kind of Linux supports v1 and v2 flexibly.

-- 
Regards,
Li Wang



More information about the ltp mailing list