Linux Namespaces and Control Groups
Linux namespaces give a process a restricted view of selected system resources. Control groups organize processes into a hierarchy that accounts for and controls their use of CPU, memory, I/O, and other resources.
itLinux | OpenSkills.info
Course pathWalk it in order
Look it upDip in anytime
Go furtherLeaves this page
Don't Panic
Don't Panic: Linux Namespaces and Control Groups
Linux namespaces and cgroups are two ways to stop an ordinary Linux process from behaving as though it owns the whole machine. They are not a tiny replacement computer. They are arrangements made by the same host kernel that was already there, which is less magical than it sounds and more useful than it first appears.
A namespace changes a process's view. Give it a mount namespace and it gets a different mount table. Give it a network namespace and it gets its own devices, routes, firewall rules, and port space. Give it a PID namespace and it gets its own process-ID view, including a PID 1 that must reap children. The kernel has not gone anywhere; the process has been issued a carefully edited map.
A cgroup answers the question the map cannot: how much CPU, memory, I/O, or process creation may this group of processes use? Cgroup v2 puts groups in one hierarchy. Controllers attach rules to that tree. A maximum is a boundary, while a weight is only a share when siblings compete. Confusing those two produces the traditional result: a configuration that looks disciplined until the workload becomes busy.
The surprising bit is that these controls are independent. Two processes can see the same network and live in different cgroups. They can share a cgroup while seeing different process lists. A cgroup namespace can hide a host-side path prefix without moving anything or granting authority over controllers. The label on a container is therefore not an explanation. Membership and placement are.
Container runtimes assemble the parts: namespaces, mounts, networking, user-ID mappings, capabilities, system-call filtering, then cgroup placement. User namespaces are especially good at puncturing the phrase root: user identifier zero inside a namespace can map to an unprivileged identifier outside it. That is reduced host privilege, not a private kernel in a convincing hat.
When something fails, begin with the symptom. A missing process suggests the PID namespace. A missing route suggests the network namespace. Periodic pauses suggest cpu.max; memory events and Pressure Stall Information expose pressure before or during a harder failure. The Cheatsheet maps those signals to the relevant files. The Slides compress the relationships. The Intro explains why delegation, capabilities, seccomp, and mandatory access control must accompany these mechanisms when the boundary matters.
Keep one sentence available for emergencies: namespaces partition views; cgroups organize and govern resource use. It is not the whole story, but it keeps you from asking a resource limit to hide a process, or a namespace to prevent a fork storm. The kernel appreciates precise questions, largely because it has no alternative.
Where this skill leads
Relevant careers
See how this topic contributes to broader role-level skill maps.
Sources
- https://man7.org/linux/man-pages/man7/namespaces.7.html
Supports
- Namespace types and the resources each isolates
- clone, unshare, setns, proc namespace handles, permissions, and lifetime
- User namespace creation exception and namespace-count limits
- https://man7.org/linux/man-pages/man2/clone.2.html
Supports
- Clone flags and kernel versions for namespace types
- Child namespace creation and capability requirements
- User namespace implementation milestones
- https://man7.org/linux/man-pages/man2/unshare.2.html
Supports
- Calling-process namespace creation
- Namespace-specific flag behavior and privilege checks
- https://man7.org/linux/man-pages/man2/setns.2.html
Supports
- Joining namespaces referenced by file descriptors
- User and cgroup namespace permission constraints
- https://man7.org/linux/man-pages/man7/user_namespaces.7.html
Supports
- UID and GID mappings and capability scope
- Namespace ownership and unprivileged creation since Linux 3.8
- Filesystem and parent-namespace constraints
- https://man7.org/linux/man-pages/man7/pid_namespaces.7.html
Supports
- Nested PID visibility and multiple process IDs
- PID 1 signal, child-reaping, and termination behavior
- https://man7.org/linux/man-pages/man7/network_namespaces.7.html
Supports
- Isolation of devices, stacks, routes, firewall rules, sockets, and ports
- Physical and virtual device behavior when a namespace is freed
- https://man7.org/linux/man-pages/man7/mount_namespaces.7.html
Supports
- Per-namespace mount lists and mount propagation
- https://man7.org/linux/man-pages/man2/mount.2.html
Supports
- Mount namespace availability from Linux 2.4.19
- https://man7.org/linux/man-pages/man7/cgroup_namespaces.7.html
Supports
- Virtualized cgroup path views and cgroup namespace roots
- Distinction between path view and actual cgroup membership
- https://man7.org/linux/man-pages/man7/time_namespaces.7.html
Supports
- Time namespace clock offsets and Linux 5.6 availability
- https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html
Supports
- Unified hierarchy, core files, topology rules, and delegation
- CPU, memory, I/O, and PIDs controller semantics
- Cgroup namespace interaction, migration, events, freezing, and killing
- https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v1/index.html
Supports
- Legacy cgroup documentation and the historical multiple-hierarchy model
- https://www.kernel.org/doc/html/latest/accounting/psi.html
Supports
- CPU, memory, and I/O stall metrics
- some, full, rolling averages, total time, and triggers
- https://man7.org/linux/man-pages/man7/capabilities.7.html
Supports
- Capability units and CAP_SYS_ADMIN operations
- Capability evaluation with user namespaces
- https://systemd.io/CGROUP_DELEGATION/
Supports
- systemd ownership of the cgroup hierarchy
- Service placement, scope and slice roles, and delegated subtrees
- https://github.com/opencontainers/runtime-spec/blob/main/config-linux.md
Supports
- OCI Linux namespace, UID mapping, capability, device, and cgroup resource fields
- https://www.kernel.org/pub/linux/kernel/v2.4/
Supports
- August 2002 release date for Linux 2.4.19
- https://kernelnewbies.org/Linux_2_6_24
Supports
- January 2008 release date
- Merge of task control groups, PID namespaces, and basic network namespaces
- https://lwn.net/Articles/680615/
Supports
- Namespace work beginning around 2002 and cgroup work beginning in 2006
- cgroup project origin and naming
- cgroup v2 becoming non-experimental in Linux 4.5
- https://github.com/sindresorhus/awesome
Supports
- Discovery route to the curated Containers awesome list
- https://github.com/Friz-zy/awesome-linux-containers
Supports
- Discovery of runc, LXC, Podman, NsJail, Kata Containers, and gVisor in the Linux container ecosystem
- https://github.com/opencontainers/runc
Supports
- runc as a Linux OCI runtime using bundles and the runtime specification
- Namespace and cgroup setup below higher-level container engines
- Apache-2.0 licensing
- https://linuxcontainers.org/lxc/introduction/
Supports
- LXC system containers and use of kernel namespaces and cgroups
- Low-level configuration and unprivileged-container model
- https://linuxcontainers.org/incus/docs/main/explanation/security/
Supports
- Default unprivileged containers and user namespace mapping
- Cgroup visibility and host-kernel security boundary
- https://docs.podman.io/en/latest/markdown/podman.1.html
Supports
- Rootless user namespace creation and subordinate ID requirements
- OCI runtime and cgroup manager integration
- https://nsjail.dev/
Supports
- Namespace, cgroup, rlimit, and seccomp composition for process isolation
- Apache-2.0 licensing
- https://gvisor.dev/docs/
Supports
- OCI runsc runtime and user-space application-kernel boundary
- https://kata-containers.github.io/kata-containers/quick-start-guide/
Supports
- Lightweight VM isolation compared with runc shared-kernel isolation
- OCI-compatible container and Kubernetes integration
- https://docs.docker.com/engine/containers/resource_constraints/
Supports
- Docker memory and CPU flags configuring host cgroup controls
- Default absence of container resource limits and OOM implications
- https://github.com/containers/crun
Supports
- crun as an OCI runtime with cgroup v2 and rootless support
- GPL-2.0 licensing
- https://systemd.io/CONTAINER_INTERFACE/
Supports
- systemd-nspawn container-manager integration with namespaces and cgroups
- Service-manager ownership of lifecycle and resource hierarchy
