CSE Roadmap

Common tier · about 3 hours · 7 parts

Part 4 of 7 · 2 min read

Shared kernel and limits

Think of two tenants who both turn on the same boiler. Each sees only their own tap, but if one drains the tank, both have no hot water. The analogy stops in one place: a boiler has a gauge for everyone, while the kernel's counters are per group only when a control group exists.

In plain words: Two checks show what is shared and what is limited. First, the kernel: a process in the container reads /proc/version and gets the host's kernel text, since there is only one kernel. Second, the limit: the launcher is started from a shell that has been put into the memory cgroup of page 5 (20 MiB), so the container's processes belong to it.

A worked example.

$ ./container 'cat /proc/version'  (first words)
Linux version 6.18.44-fc-v653 (builder@sandboxing) ...
$ uname -r                          (on the host)
6.18.44-fc-v653

$ sh -c 'echo $$ > /sys/fs/cgroup/memory/demo/cgroup.procs; exec ./container mem'
host sees the container as pid 543
touched 10 MiB
Killed
$ free -m       (host memory afterwards: used 395, free 7587 of 8024)

The container reports the same kernel version as the host. The memory test of page 5 ran inside it and was killed near 20 MiB. The host's memory stayed unaffected: 395 MiB used and 7,587 MiB free out of 8,024. Without the group, the same program in the container used 100 MiB and finished.

The key lines. The namespaces made the container look separate, and the cgroup made it small. Neither gave it a kernel of its own.

Shared kernel

A shared kernel is the property that all containers on a host, and the host itself, run on one kernel. A call that works in one container is a call into the same kernel code as every other, so a kernel flaw is a flaw for all of them.

Example: cat /proc/version in the container prints the host's kernel version.

Check yourself: 1. How does the container prove that it shares the host's kernel? 2. What happened to the host when the container's program was killed? 3. Which parts did the cgroup add?