Filesystem · Scheduling · Advanced — IPC · Signals · cgroups · Observability
Filesystem · Scheduling · Advanced — IPC · Signals · cgroups · Observability
🎯 What you'll be able to do after this lesson
After completing this lesson, you will be confident in the following 3 areas:
- ▸✅ Context switching overhead (thread < process)
- ▸✅ epoll · kqueue · IOCP event-driven I/O
- ▸✅ Copy-on-Write + fork() behavior
Keep the learning goals as a checklist and close the lesson once you can answer all of them.
Filesystem — inodes and directories
One-liner: A file = inode + data blocks, and a directory = name → inode mapping.
6 steps from open() to read():
1. open("/etc/hosts") — path parsing
2. dentry cache lookup — directory entry cache (RAM)
3. inode load — permission · size · block location · timestamp metadata
4. permission check — user/group · rwx
5. fd allocation — returns file descriptor number (0,1,2 = stdin/stdout/stderr, 3+ = user)
6. read(fd, buf, n) — block to page cache → user buffer
Filesystem types:
Common pitfalls:
- ▸❌ "too many open files" — insufficient fds (
ulimit -nincrease) - ▸❌ Concurrent file writes → corruption (fcntl lock · O_APPEND)
- ▸❌ Following symbolic links into an infinite loop (beware
-Loption) - ▸✅ Call
fsync()to guarantee disk sync (DB · write-ahead log)
CPU Scheduling — who runs first
Linux CFS (Completely Fair Scheduler) — the default scheduler (2.6.23+).
Principle: Tracks the virtual runtime of each process. The process that has run the least goes first → fairness.
Scheduling policies:
Round Robin (RR) behavior:
1. Each process is given a time slice (e.g., 10 ms)
2. When the slice expires, the process moves to the back of the queue
3. The next process runs
→ Fair, but incurs context switching overhead
Scheduling pitfalls:
- ▸❌ Misusing nice values (lower = higher priority) — counter-intuitive
- ▸❌ Real-time SCHED_FIFO infinite loop → entire system freezes
- ▸❌ No CPU affinity set → frequent cache invalidation
Modern trends:
- ▸EEVDF (Earliest Eligible Virtual Deadline First) — CFS successor in Linux 6.6+
- ▸Pluggable — custom BPF schedulers via sched_ext (2024+)
IPC · Signals · Zombies — inter-process communication
IPC (Inter-Process Communication) types:
Signal usage:
Graceful Shutdown pattern:
Zombie process:
- ▸Child has exited but parent has not called
wait()→ only the PCB remains - ▸Shown as
Zstate inps - ▸Prevention: parent registers a SIGCHLD handler and calls
waitpid() - ▸Orphan process: if the parent dies first, init (PID 1) adopts it → init calls wait → cleaned up
cgroups + Observability — the foundation of containers
cgroup (Control Group) — Linux mechanism to limit resources for process groups. The core of Docker and Kubernetes.
Examples:
Docker example: docker run --memory=1g --cpus=0.5 nginx internally configures cgroups.
cgroup v2 (modern Linux): unified hierarchy (consolidates v1's separate controllers).
Observability — 3 pillars:
eBPF (Extended Berkeley Packet Filter):
- ▸Runs code safely inside the kernel (no kernel patch needed)
- ▸Observes all system call · network · disk events
- ▸Tools:
bcc·bpftrace·pixie·falco(security) - ▸Cilium (K8s networking) and Datadog APM are both eBPF-based
Observability pitfalls:
- ▸❌ Metrics only (no idea why) → add traces too
- ▸❌ Log explosion (10 TB/day) → sampling · filtering
- ▸❌ /var/log fills up → log rotation is mandatory (logrotate)
🤖 Try asking AI like this
Knowing the concepts in this lesson lets you give AI specific instructions. Instead of a vague "fix this," you can make requests with vocabulary — that is where token savings begin.
- ▸"Diagnose whether this task incurs high context switching overhead"
- ▸"Tell me what benefits there would be in converting this task to epoll (Linux)-based async"
Why this reduces tokens
Without the concepts, even after receiving an AI answer you have to follow up with "What is that?" That follow-up is what burns tokens. Learn the concept once and the conversation ends in a single round.