Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support cgroup v1 mounted with noprefix #4513

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tomaszduda23
Copy link

@tomaszduda23 tomaszduda23 commented Nov 5, 2024

Android mounts cgroup v1 with noprefix. Related to #4443

# mount | grep cgroup
none on /dev/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
none on /dev/cpuctl type cgroup (rw,nosuid,nodev,noexec,relatime,cpu)
none on /dev/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset,noprefix,release_agent=/sbin/cpuset_release_agent)
none on /dev/memcg type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
none on /dev/stune type cgroup (rw,nosuid,nodev,noexec,relatime,schedtune)
none on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime)
ls -l /dev/cpuset
total 0
drwxr-xr-x. 2 system system 0 May 29  1970 background
drwxr-xr-x. 2 system system 0 May 29  1970 camera-daemon
-rw-r--r--. 1 root   root   0 Nov  5 19:48 cgroup.clone_children
-rw-rw-r--. 1 system system 0 May 29  1970 cgroup.procs
-r--r--r--. 1 root   root   0 Nov  5 19:48 cgroup.sane_behavior
-rw-r--r--. 1 root   root   0 Nov  5 19:48 cpu_exclusive
-rw-r--r--. 1 root   root   0 May 29  1970 cpus
-r--r--r--. 1 root   root   0 Nov  5 19:48 effective_cpus
-r--r--r--. 1 root   root   0 Nov  5 19:48 effective_mems
drwxr-xr-x. 2 system system 0 May 29  1970 foreground
-rw-r--r--. 1 root   root   0 Nov  5 19:48 mem_exclusive
-rw-r--r--. 1 root   root   0 Nov  5 19:48 mem_hardwall
-rw-r--r--. 1 root   root   0 Nov  5 19:48 memory_migrate
-r--r--r--. 1 root   root   0 Nov  5 19:48 memory_pressure
-rw-r--r--. 1 root   root   0 Nov  5 19:48 memory_pressure_enabled
-rw-r--r--. 1 root   root   0 Nov  5 19:48 memory_spread_page
-rw-r--r--. 1 root   root   0 Nov  5 19:48 memory_spread_slab
-rw-r--r--. 1 root   root   0 May 29  1970 mems
-rw-r--r--. 1 root   root   0 Nov  5 19:48 notify_on_release
-rw-r--r--. 1 root   root   0 Nov  5 19:48 release_agent
drwxr-xr-x. 2 system system 0 May 29  1970 restricted
-rw-r--r--. 1 root   root   0 Nov  5 19:48 sched_load_balance
-rw-r--r--. 1 root   root   0 Nov  5 19:48 sched_relax_domain_level
drwxrwxr-x. 2 system system 0 May 29  1970 system-background
-rw-rw-r--. 1 system system 0 May 29  1970 tasks
drwxr-xr-x. 2 system system 0 May 29  1970 top-app

Copy link
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, cgroup v1 is being phased out slowly, and we'd rather not add more functionality in this area.

I'm pretty sure Android is going to switch to cgroup v2 soon, if not yet.

@kolyshkin
Copy link
Contributor

I'm pretty sure Android is going to switch to cgroup v2 soon, if not yet.

I see that even the latest and greatest Android 15 still uses cgroup v1 for a few specific controllers (although there are only 3 that I see on my phone, and only cpuset is mounted with noprefix flag).

Yet, I see there's cgroup2 mounted at /sys/fs/cgroup. Why not use it, it should be pretty standard.

@tomaszduda23
Copy link
Author

In general, cgroup v1 is being phased out slowly, and we'd rather not add more functionality in this area.

Usually Android use older kernels. The support for cgroup v2 is limited there. I've two phones with Android 13 and 14 and both are on kernel 4.19. Android was updated a few times but kernel version stay the same.

Yet, I see there's cgroup2 mounted at /sys/fs/cgroup. Why not use it, it should be pretty standard.

I tried that approach too. It doesn't work since it would require newer kernel which is not available for many devices.

@tomaszduda23 tomaszduda23 force-pushed the groupv1 branch 2 times, most recently from 7983199 to 9e8dc7b Compare November 6, 2024 18:18
Copy link
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit message needs to be updated to explain what is going on and why.

libcontainer/cgroups/fs/cpuset.go Outdated Show resolved Hide resolved
libcontainer/cgroups/fs/cpuset.go Show resolved Hide resolved
libcontainer/cgroups/fs/cpuset.go Outdated Show resolved Hide resolved
@tomaszduda23 tomaszduda23 force-pushed the groupv1 branch 4 times, most recently from 2e7eb64 to bbb3244 Compare December 8, 2024 20:57
Android mounts the v1 cpuset cgroup with the noprefix option.
As a result, runc first attempts to access cpuset files using the prefix format (e.g., cpuset.cpus).
If this fails, it falls back to accessing them without the prefix (e.g., cpus).
Once a successful access method is determined, it is cached and used for all subsequent operations.
Only the v1 cpuset cgroup is allowed to mount with noprefix. See kernel source:
https://github.com/torvalds/linux/blob/2e1b3cc9d7f790145a80cb705b168f05dab65df2/kernel/cgroup/cgroup-v1.c#L1070.
Cpuset cannot be mounted with and without prefix simultaneously.

Signed-off-by: Tomasz Duda <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants