0

I really need to learn how to turn on cgroups v2 cpu controller for modern Linux most of which now support by default only cgroups v2 (not cgroups v1).

A quote from https://man7.org/linux/man-pages/man7/cgroups.7.html:

   The cgroups v2 "cpu" controller and realtime threads
       As at Linux 4.19, the cgroups v2 cpu controller does not support
       control of realtime threads (specifically threads scheduled under
       any of the policies SCHED_FIFO, SCHED_RR, described
       SCHED_DEADLINE; see sched(7)).  Therefore, the cpu controller can
       be enabled in the root cgroup only if all realtime threads are in
       the root cgroup.  (If there are realtime threads in nonroot
       cgroups, then a write(2) of the string "+cpu" to the
       cgroup.subtree_control file fails with the error EINVAL.)

       On some systems, systemd(1) places certain realtime threads in
       nonroot cgroups in the v2 hierarchy.  On such systems, these
       threads must first be moved to the root cgroup before the cpu
       controller can be enabled.

How can I effectively deal with this "realtime threads" problem and move them all to the root, as suggested?

I use command ps -T axo pid,ppid,user,group,lwp,nlwp,start_time,comm,cgroup,cls|grep RR from here: https://access.redhat.com/solutions/6582021 to find realtime threads. Is it a reliable way to find all the realtime threads? Or may filtering by RR scheduling be not enough? Anyway, I try to kill them off but they reappear again with new PIDs.

I add C/C++ tags as I need to use cpu limit controller in the code for certain threads. And I need it to work on most of Linux distributions. Ubuntu 22.04 and Centos 9 Stream do not have cpu controllers available in their root cgroup.controllers. However, RHEL9 does have cpu controller available, even though the command above shows its list of realtime threads non-empty.

UPDATE

On Ubuntu 22.04 I finally managed to kill off all the RR threads. But cpu controller still does not appear. Maybe the problem is not about realtime threads?

Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128
JenyaKh
  • 2,040
  • 17
  • 25

1 Answers1

1

As explained here https://serverfault.com/a/931180/518713 an https://unix.stackexchange.com/a/635645/346609 I needed just to add cgroup_no_v1=all as a kernel boot option in my grub config and update grub, and reboot. And here it is. None legacy cpu is mounted as cgroup v1. So it becomes available for cgroup v2.

JenyaKh
  • 2,040
  • 17
  • 25