Skip to content

Instantly share code, notes, and snippets.

@coin8086
Last active January 17, 2024 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coin8086/d514fee9f96032ab4a5c33d903069d9c to your computer and use it in GitHub Desktop.
Save coin8086/d514fee9f96032ab4a5c33d903069d9c to your computer and use it in GitHub Desktop.
cgroup and systemd

cgroup and systemd

cgroup

"The control groups, abbreviated as cgroups in this guide, are a Linux kernel feature that allows you to allocate resources — such as CPU time, system memory, network bandwidth, or combinations of these resources — among hierarchically ordered groups of processes running on a system."

Check the cgroups by systemd-cgls.

Resource controller

"A resource controller, also called a cgroup subsystem, represents a single resource, such as CPU time or memory."

Check the controllers under /proc/cgroups, and the cgroup a process belonging to at /proc/<pid>/cgroup.

systemd

"The systemd system and service manager is responsible for controlling how services are started, stopped and otherwise managed".

Relation between cgroup and systemd

"...by binding the system of cgroup hierarchies with the systemd unit tree", "Therefore, you can manage system resources with systemctl commands, or by modifying systemd unit files."

systemd unit types

The key systemd unit types related to cgroups are:

  • Service - "A process or a group of processes, which systemd started based on a unit configuration file."
  • Scope - "Scopes encapsulate processes that are started and stopped by arbitrary processes through the fork() function and then registered by systemd at runtime."
  • Slice - "A group of hierarchically organized units. Slices do not contain processes, they organize a hierarchy in which scopes and services are placed. The actual processes are contained in scopes or in services."

systemd tools

  • systemctl - Show, start, stop, enable, disable, ..., services
  • journalctl - Show service log
  • systemd-cgls - Recursively view cgroup contents
  • systemd-run - Create transient cgroups
  • systemd-top - View service processes

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment