Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.A desk that is too small
Imagine working at a small desk with a huge archive in the basement. Only a few folders fit on the desk; when you need another, something must go back downstairs. A computer’s fast memory is that desk, and the disk is the basement. The operating system decides what stays on the desk, shares the computer among many running programs (processes), and moves data to and from disk. Good decisions keep everything fast; bad ones make the machine crawl.
| ref | 1 | 2 | 3 | 4 | 1 | 2 | 5 | 1 | 2 | 3 | 4 | 5 |
| frame 0 | 1 | 1 | 1 | 4 | 4 | 4 | 5 | 5 | 5 | 5 | 5 | 5 |
| frame 1 | · | 2 | 2 | 2 | 1 | 1 | 1 | 1 | 1 | 3 | 3 | 3 |
| frame 2 | · | · | 3 | 3 | 3 | 2 | 2 | 2 | 2 | 2 | 4 | 4 |
| faults | 1 fr | 2 fr | 3 fr | 4 fr | 5 fr |
| FIFO | 12 | 12 | 9 | 10 | 5 |
| LRU | 12 | 12 | 10 | 8 | 5 |
| CLOCK | 12 | 12 | 9 | 10 | 5 |
| OPT | 12 | 9 | 7 | 6 | 5 |
Flight computers and robot controllers run many processes with hard memory budgets; a training job on a cluster is killed the moment it exceeds its memory limit. Reading top, interpreting an exit code of 137 and knowing why a “free memory: 2%” report is usually harmless save hours of debugging.
- 1. A process is…
- 2. When fast memory is full, the OS must…
- 3. In the demo with Belady's string, giving FIFO one more frame…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.Watching processes
ps aux --sort=-%mem | head # biggest memory users
top / htop # live view: %CPU, RES (resident memory), state
pgrep -af python # find processes by name
kill 4242 # polite stop (SIGTERM); kill -9 4242 = SIGKILL, cannot be caught
nice -n 10 python train.py & # lower priority, run in the background
free -h; df -h; iostat -x 1 # memory, disk space, disk activityProcess states: R running or runnable, S sleeping (waiting for something), D uninterruptible I/O wait (often a slow file system), Z zombie (finished, parent hasn’t collected it), T stopped. A %CPU of 400 means four cores busy.
Exit codes
0 is success; 1 to 125 are the program’s own errors; 128 + n means “killed by signal n”: 130 = Ctrl-C (SIGINT), 137 = SIGKILL (very often the out-of-memory killer or a scheduler’s limit), 139 = SIGSEGV (invalid memory access), 143 = SIGTERM.
- 1. A job exits with status 137. The first suspect is…
- 2. %CPU = 400 in top means…
- 3. Which signal can a program not catch?
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.Processes and threads
fork() duplicates a process (cheaply, with copy-on-write pages), exec() replaces its program; the shell runs every command this way. Threads share one address space; processes do not, so multiprocessing in Python copies or shares data explicitly (C5). Everything the kernel knows about a process is visible under /proc/<pid>/: stat (state, CPU ticks, memory), status (human-readable), fd/ (open files), maps (memory regions).
Virtual memory
Each process sees its own virtual address space. Memory is managed in pages (4 KiB; also 2 MiB huge pages). On x86-64 a 48-bit address is split 9 + 9 + 9 + 9 + 12 bits: four page-table levels and an offset; the TLB caches recent translations. Touching an unmapped page causes a page fault: minor if the data is already in RAM (first touch, shared library), major if it must be read from disk. RSS is what is resident in RAM; virtual size (VSZ) includes reserved-but-untouched memory, so a 30 GB VSZ is normal for a GPU process.
Linux uses otherwise idle RAM as page cache for files, so “free” memory is small on a healthy machine; MemAvailable estimates what programs can still get. When memory truly runs out, the system swaps (slow) and finally the OOM killer kills a process; under cgroups (Docker, Slurm) the limit is per job.
- 1. The page offset of a 4 KiB page has how many bits?
- 2. A 'major' page fault means…
- 3. free shows 2% free but MemAvailable is 70%. The machine…
Level 3: Advanced
★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.Page replacement
When RAM is full, the kernel evicts pages. The ideal (OPT, Belady) evicts the page used farthest in the future; real systems approximate LRU with reference bits (CLOCK, Linux’s active and inactive lists). Two classic facts: FIFO can suffer Belady’s anomaly (more memory, more faults), and LRU collapses on loops slightly larger than memory (every access misses). Large sequential scans can flush a hot working set; posix_fadvise(DONTNEED), direct I/O or Linux’s two-list design limit the damage.
I/O performance
Three numbers describe storage: latency (time per operation: about 0.1 ms for NVMe, 5–10 ms for a hard disk seek), IOPS (operations per second) and bandwidth (bytes per second). Small random reads are latency-bound; large sequential reads are bandwidth-bound. Writes go to the page cache first and reach the disk later; fsync forces durability (essential for checkpoints you rely on, and slow if called too often). Measure with iostat, fio, or simply time a read loop; tune with larger requests, fewer files (C4.1), and asynchronous prefetching (C3.6’s tf.data, PyTorch’s DataLoader workers).
- 1. A loop over 100 pages with 99 frames under LRU gives a hit rate of…
- 2. Which policy can show Belady's anomaly?
- 3. Random 4 KiB reads on an HDD are slow because of…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.The kernel’s view, measured
Exercise 1. A stat line for a process named python train (v2).py parses correctly only when split at the last ). 780 user and 60 system clock ticks in 2 s of wall time (100 ticks per second) are 420% CPU. A machine with 64 GB, 2.5% “free” and 70% available is only 30% used. The virtual address 0x7f3a1c2b3d4e splits into indices 254, 232, 225, 179 and offset 0xd4e; mapping its page to frame 0x1234 translates it to 0x1234d4e, and the next page faults. Exit 137 decodes to SIGKILL.
Exercise 2: page-replacement policies.
| Workload | FIFO | LRU | CLOCK | OPT |
|---|---|---|---|---|
| Belady’s string, faults with 3 / 4 frames | 9 / 10 | 10 / 8 | 9 / 10 | 7 / 6 |
| loop of 100 pages, 99 frames: hit rate | 0% | 0% | 0% | 98% |
| Zipf (1000 pages, s = 1), 10 frames: hit rate | 0.182 | 0.210 | 0.196 | 0.432 |
| Zipf, 50 frames | 0.406 | 0.462 | 0.447 | 0.659 |
| Zipf, 200 frames | 0.644 | 0.694 | 0.683 | 0.836 |
| hot set of 50 + 400-page scans, 100 frames | 0.679 | 0.679 | 0.679 | 0.711 |
On skewed (Zipf) workloads CLOCK recovers most of LRU’s advantage over FIFO at a fraction of the bookkeeping, and OPT shows the remaining headroom. On the scan workload every realistic policy loses the hot set after each scan (50 extra misses per cycle); OPT keeps it.
Processes, memory and I/O in AI, robotics and aerospace
- Training jobs: exit 137 and
dmesgOOM messages; memory limits in Slurm and Docker are cgroup limits. - Data loading: page cache warm-up between epochs, DataLoader worker processes (fork and copy-on-write), memory-mapped datasets (
np.memmap, HDF5). - Flight and robot software: real-time Linux (PREEMPT_RT), locked memory (
mlockall) to avoid page faults in control loops, process isolation between subsystems. - Telemetry archives: checkpoint durability with fsync; sequential append-only logs for throughput.
References
- R. H. Arpaci-Dusseau, A. C. Arpaci-Dusseau (2023). Operating Systems: Three Easy Pieces, v1.10 (ostep.org).
- L. A. Belady, R. A. Nelson, G. S. Shedler (1969). “An anomaly in space-time characteristics of certain programs running in a paging machine.” Communications of the ACM, 12(6).
- R. L. Mattson, J. Gecsei, D. R. Slutz, I. L. Traiger (1970). “Evaluation techniques for storage hierarchies.” IBM Systems Journal, 9(2).
- Linux kernel documentation: The /proc filesystem (proc(5)), Memory management (docs.kernel.org).
- B. Gregg (2020). Systems Performance, 2nd ed. Addison-Wesley.