How the Linux kernel works
medium 40 minThe kernel is the one program that runs with full privilege.
Check yourself
One question at a time. Each answer explains why.
Question 1 of 12
Which one is started by a device rather than by the running program?
Why can kill -9 seem to do nothing to a process in state D?
vmstat shows r = 1 and b = 30 on 8 CPUs, with a high load. What do you check next?
What does fork() share between parent and child right after the call?
free -m shows 300 MB free and 6 GB buff/cache. Is the machine short of memory?
Which VFS object holds the current position of one open file?
One CPU is at 100% in %soft and the others are idle during a packet flood. Best next step?
Two containers on one host share what?
A container restarts every few hours with no log line. Where do you look first?
Who expands the glob in ls *.txt?
cpu.max is 25000 100000. How much CPU may the group use?
What is a kernel thread?
Pick an answer to see why.
Not quite. Interrupts come from devices such as disks and network cards. The other three are caused by the running program.
Not quite. SIGKILL cannot be caught, blocked or ignored, but it is acted on only when the task leaves the kernel.
Not quite. b counts tasks blocked on I/O. The load is waiting, not computing.
Not quite. Pages are shared until one side writes; then that page is copied.
Not quite. Page cache is reused file data and can be reclaimed. available and PSI memory show real pressure.
Not quite. The file object is the kernel side of a descriptor. The inode is the file itself and has no position.
Not quite. One hot interrupt column means one CPU handles all receive work. Spreading queues shares it.
Not quite. Namespaces and cgroups separate views and budgets. The kernel is one.
Not quite. SIGKILL from the OOM killer cannot be caught, so the program writes nothing.
Not quite. bash reads the directory and passes the matching names to ls as arguments.
Not quite. 25 ms per 100 ms period in total across all CPUs: 0.25 of one CPU.
Not quite. Examples are kswapd and ksoftirqd. ps shows them in brackets.
Flashcards
Say your answer, then reveal it.
Card 1 of 12
What is the kernel?
The one program that runs with full privilege, owns the hardware and shares it among all other programs.
Say your answer, then reveal it.
Three ways into the kernel?
System call (the program asks), interrupt (a device), exception (the current instruction faulted, such as a page fault).
Say your answer, then reveal it.
When are signals acted on?
On the way from kernel mode back to user mode, for example after a system call. A task stuck in D never gets there until its I/O ends.
Say your answer, then reveal it.
fork, execve, wait?
fork copies the process with copy-on-write pages. execve replaces the program. wait reaps the child, which is a zombie until then.
Say your answer, then reveal it.
State D?
Uninterruptible sleep, usually I/O. It counts in the load average and ignores signals until the wait ends.
Say your answer, then reveal it.
How does the scheduler choose?
Each CPU has a run queue. CFS, and since 6.6 EEVDF, picks by virtual runtime weighted by nice. EEVDF adds a virtual deadline.
Say your answer, then reveal it.
Minor or major page fault?
Minor: no disk needed, a zeroed page or file data already cached. Major: the data must be read from disk.
Say your answer, then reveal it.
What is the page cache?
File data kept in RAM after reads and writes. It shows as buff/cache in free and is reclaimable.
Say your answer, then reveal it.
The four VFS objects?
Superblock (a mounted file system), inode (the file), dentry (a name to inode link), file (one open, with a position).
Say your answer, then reveal it.
Top half and bottom half?
The hard IRQ handler does the minimum. A softirq does the rest. Neither may sleep. ksoftirqd runs softirqs when they pile up.
Say your answer, then reveal it.
Container in two words?
Namespaces (what it sees) plus cgroups (what it uses), on the one shared kernel.
Say your answer, then reveal it.
cpu.max = 50000 100000?
50 ms of CPU per 100 ms period across all CPUs: half a CPU. The default is max 100000, no limit.
Say your answer, then reveal it.
These cards come back in Today, just before you would forget them.