LinuxCommandLibrary

cgclassify

Move processes into cgroups

TLDR

Move the process with a specific PID to the control [g]roup student in the CPU hierarchy

$ cgclassify -g [cpu:student] [1234]
copy

Move the process with a specific PID to control groups based on the /etc/cgrules.conf configuration file
$ cgclassify [1234]
copy

Move the process with a specific PID to the control [g]roup student in the CPU hierarchy. Note: The daemon of the service cgred does not change cgroups of the specific PID and its children (based on /etc/cgrules.conf)
$ cgclassify --sticky -g [cpu:/student] [1234]
copy

SYNOPSIS

cgclassify -g controller_list:path [-g controller_list:path ...] pid...
cgclassify [-h|--help] [-v|--version]

PARAMETERS

-g :
    Specifies the target control group(s) for the tasks. controller_list is a comma-separated list of cgroup subsystems (e.g., cpu,memory). path is the absolute path to the cgroup directory within the cgroup filesystem hierarchy.

...
    One or more process IDs (PIDs) or thread IDs (TIDs) to move into the specified cgroup(s). These are the tasks whose resource assignments will be changed.

-h, --help
    Displays a help message and exits.

-v, --version
    Displays version information and exits.

DESCRIPTION

cgclassify is a utility from the libcgroup tools that allows an administrator or authorized user to dynamically move running processes or threads into specified control groups (cgroups). This command is crucial for real-time resource management, as cgroups are a Linux kernel feature for organizing processes hierarchically and allocating system resources (like CPU, memory, I/O, network) among them.

By moving a task into a different cgroup, its resource constraints and accounting immediately change according to the rules defined for that target cgroup. It operates by writing the process ID (PID) or thread ID (TID) to the tasks or cgroup.procs file within the target cgroup's subsystem directory in the cgroup virtual filesystem. This enables administrators to rebalance workloads or adjust resource allocations on the fly without restarting applications.

CAVEATS

Permissions: Requires root privileges or the CAP_SYS_ADMIN capability to move processes between cgroups.
Cgroup Hierarchy: Primarily designed for Cgroup v1, which uses distinct hierarchies for different controllers. While the underlying cgroup.procs mechanism is shared with Cgroup v2, cgclassify's direct usage patterns align with v1.
Cgroup Existence: The target cgroup(s) specified by the -g option must already exist before cgclassify is run (e.g., created by cgcreate or manually).
Inheritance: Moving a process does not automatically move its future child processes. For persistent assignments, Cgroup rules managed by cgrulesengd are often used.

COMMON USE CASES

Dynamically re-prioritizing a running batch job by moving it to a cgroup with lower CPU or I/O priority.
Adjusting resource limits for a critical service on the fly without requiring a service restart.
Correcting processes that accidentally started in the wrong cgroup.
Debugging and testing cgroup configurations by manually assigning processes and observing their behavior under new resource constraints.

PREREQUISITES

The cgroup filesystem must be mounted (typically at /sys/fs/cgroup).
The necessary cgroup subsystems (e.g., cpu, memory) must be enabled and mounted within the cgroup hierarchy.
User must have sufficient permissions (root or CAP_SYS_ADMIN) to modify cgroup assignments.

HISTORY

cgclassify is an integral part of the libcgroup tools suite, which was developed alongside the introduction of the cgroups (control groups) feature in the Linux kernel (version 2.6.24). It has served as a fundamental utility for administrators to dynamically manage and reassign tasks to specific resource groups, adapting with the evolving capabilities of the cgroups subsystem over time.

SEE ALSO

cgcreate(1), cgexec(1), cgget(1), cgset(1), cgrulesengd(8)

Copied to clipboard