Home / Alt manpages / proc_pid_autogroup(5)

  • proc_pid_autogroup(5)
  • File format
  • linux

Tune Scheduler Priority with /proc/pid/autogroup

A background build hogs the CPU under the terminal you are typing in. /proc/<pid>/autogroup is the scheduler's own knob for fixing that, not a cgroup you have to build. This guide inspects the scheduler autogroup for a process, shows when a new session gets a separate group, and adjusts an autogroup's CPU priority correctly. Allow about ten minutes.

The examples use the proc_pid_autogroup interface documented by Linux man-pages 6.7, installed here from package version 6.7-2. You need a shell and a Linux kernel with autogroup support. Most checks are ordinary, unprivileged reads.

1. Check whether the kernel feature is enabled

Autogrouping needs a kernel configured with CONFIG_SCHED_AUTOGROUP. The running system exposes its switch through /proc/sys/kernel/sched_autogroup_enabled:

$ cat /proc/sys/kernel/sched_autogroup_enabled
1

A value of 1 means the feature is enabled and 0 means it is disabled. The documented default is enabled unless the kernel was booted with noautogroup. Reading the switch does not change anything. If the file is absent, the running kernel may lack the feature, or the proc filesystem may not be mounted as expected.

Checkpoint

Record the value before investigating a process. If it is 0, the per-process file may still be visible, but autogroup scheduling is not doing the work you expect.

2. Read a process's autogroup

Replace PID with a process you are allowed to inspect:

$ cat /proc/PID/autogroup
/autogroup-123456 nice 0
  • The group identifier is kernel-generated and will differ on every system.
  • The nice value is the priority of the autogroup as a whole.
  • A process normally inherits its parent's group on fork, while a new session created with setsid starts a new autogroup. A terminal window commonly creates such a session.

For a self-contained read-only comparison, use two shells:

$ printf 'current shell: '; cat /proc/self/autogroup
current shell: /autogroup-123456 nice 0
$ setsid sh -c 'printf "new session: "; cat /proc/self/autogroup'
new session: /autogroup-123457 nice 0

The numbers are examples. The useful observation is that the group ID can change after setsid: a changed ID does not mean a cgroup was created.

3. Understand what the grouping changes

When enabled, autogrouping places members of one session in the same scheduler task group. Under CPU contention, the CFS scheduler distributes CPU time between task groups, so ten CPU-bound processes in one group do not automatically outweigh one CPU-bound process in another group by a factor of ten. The exact result depends on CPU topology, runnable work and other scheduler settings.

The interface applies to processes using the ordinary non-real-time policies SCHED_OTHER, SCHED_BATCH and SCHED_IDLE. Real-time and deadline policies are scheduled by their own rules. A CPU cgroup outside the root CPU cgroup overrides autogrouping, so use cgroup controls when you need an explicit service or container CPU boundary.

Do not use /proc/PID/autogroup as a general CPU quota. It changes relative scheduling weight between autogroups, not a fixed percentage of a machine's CPU capacity.

4. Change an autogroup's nice value deliberately

Writing an integer from -20 through 19 changes the autogroup priority. A lower value gives the group higher relative priority; a higher value lowers it. This is a live scheduling change, so treat it as service-impacting. Test it on a disposable session first:

$ setsid sh -c 'printf 5 > /proc/self/autogroup; cat /proc/self/autogroup'
/autogroup-123458 nice 5

The command changes only the short-lived shell's session, which exits immediately afterwards. It does not write a persistent configuration file.

Warning

Writing a value affects every eligible process in that autogroup, not just the process whose path you opened.

Raising priority requires the privileges allowed by the kernel's scheduler policy. An unprivileged write to -1, or an attempt to move a group back towards higher priority after lowering it, can fail with a non-zero status and an I/O error. Capture the result instead of assuming the write worked:

$ printf 5 > /proc/self/autogroup
$ status=$?
$ printf 'write status: %s\n' "$status"
write status: 0
$ cat /proc/self/autogroup
/autogroup-123456 nice 5

Before changing a long-running workload, save its original value. To restore a value that needs more privilege, use your normal reviewed administrative procedure, for example sudo sh -c 'printf 0 > /proc/PID/autogroup'. Check the target PID and group again before running that command. Do not paste a PID from an old process listing: PIDs can be reused.

5. Diagnose a result that does not fit

If a read fails, check that the process still exists and that proc is mounted:

$ test -r /proc/PID/autogroup && echo readable
$ ps -p PID -o pid,comm,stat
$ mountpoint /proc

An exited process has no file to read. A missing autogroup file or a disabled feature is different from a permission failure. If a write is rejected, verify the integer is within -20 to 19, capture the exit status, and check whether the requested priority increase needs elevated privilege. Do not repeatedly retry a write against a production workload.

Also check whether the process is in a non-root CPU cgroup before drawing conclusions from the autogroup value. If a service is managed by a container runtime or system manager, its cgroup policy may be the effective control.

Done means

  • Checked sched_autogroup_enabled and know whether the feature is active.
  • Read the target process's autogroup and told its ID apart from a cgroup.
  • Know that sessions, not individual commands, define the usual grouping boundary.
  • Tested a nice change on a short-lived session and checked its exit status.
  • Have a reviewed restore path before changing a long-running workload.
  • Will use CPU cgroups when explicit resource control or quotas are needed.