AlgoViz

How the Linux kernel works

medium 40 min

The kernel is the one program that runs with full privilege.

Remember it

The few things worth knowing cold, and how to make them stick.

Memory hook

The kernel holds the keys. Programs knock, devices ring, instructions trip the alarm.

A tool library: members work in the hall and pass slips through a hatch. Noor, the keeper, has the keys, a front shelf, a basement, a delivery bell, and a board of turns at the workbench.

Cheat sheet

Ways in
syscall, interrupt, exception
Signals act
on return to user mode
States
R S D T Z I
Load counts
R + D tasks
Scheduler
CFS 2.6.23, EEVDF from 6.6
Nice
-20 high to 19 low
Huge pages x86
2M and 1G
VFS objects
superblock, inode, dentry, file
Containers
namespaces + cgroups
cpu.max default
max 100000
Soft lockup
kernel loop over 20 s

Spot it when you see

  • "What happens when you run a command?"
  • "kill -9 does not work."
  • "Load is high but CPU is idle."
  • "The container died silently."

Tricks that stick

  • Knock, ring, trip: syscall, interrupt, exception.
  • D is for disk, and for don't disturb.
  • Front shelf first, basement on a miss.
  • See with namespaces, spend with cgroups.

Do not forget

  • Saying the kernel is a process.
  • Saying kill -9 always works.
  • Saying ls expands the glob.
  • Calling buff/cache wasted memory.
  • Treating a container like a virtual machine with its own kernel.
  • Running strace on a busy production process without warning: it slows it down.