Check cgroup mounts in /sys/fs/cgroup
In the previous step, you saw the available cgroup subsystems. Now, let's explore where these cgroups are mounted in the filesystem. In Linux, cgroups are typically exposed through a virtual filesystem, usually mounted under /sys/fs/cgroup
.
The /sys
filesystem is another virtual filesystem that provides an interface to kernel data structures. It's often used to configure and monitor hardware and kernel features. The /sys/fs/cgroup
directory is the standard mount point for the cgroup filesystem.
To see the contents of this directory and understand how the cgroup hierarchies are organized, you will use the ls
command. The ls
command lists the contents of a directory.
Open your terminal if it's not already open.
Type the following command into the terminal and press Enter:
ls /sys/fs/cgroup
You should see output similar to this:
cgroup.controllers cgroup.max.depth cgroup.max.descendants cgroup.stat cgroup.subtree_control cgroup.threads cpu cpu.stat cpu.pressure cpuset cpuset.cpus cpuset.mems cpuset.stat io io.stat io.pressure memory memory.stat memory.pressure memory.swap.max memory.high memory.low memory.min memory.swap.current memory.current memory.events memory.events.local pids pids.current pids.max systemd user.slice
This output shows the directories and files within the /sys/fs/cgroup
directory. In systems using the unified cgroup hierarchy (cgroup v2), you'll see files like cgroup.controllers
, cgroup.stat
, and directories corresponding to the mounted controllers (like cpu
, memory
, io
, pids
).
Each of these directories (like cpu
, memory
, etc.) represents a cgroup controller. Inside these directories, you'll find files that allow you to configure and monitor the resource limits for processes within that cgroup.
For example, if you were to navigate into the cpu
directory, you would find files related to CPU resource control.
Let's quickly look inside the cpu
directory using ls
:
ls /sys/fs/cgroup/cpu
You might see output like:
cgroup.controllers cgroup.events cgroup.freeze cgroup.max.depth cgroup.max.descendants cgroup.stat cgroup.subtree_control cgroup.threads cpu.max cpu.stat cpu.weight cpu.pressure
These files (like cpu.max
, cpu.weight
) are used to set CPU limits and priorities for cgroups.
Understanding the structure of /sys/fs/cgroup
is key to working with cgroups, as this is where you interact with them directly.
Click Continue to move on to the next step.