← Operating System Concepts

BOOK NOTES · OPERATING SYSTEMS · CHAPTER 20

Operating System Concepts Chapter 20 — The Linux System.

operating-systemschapter-20linuxkernelcfscase-study

// the one-minute version

Linux is the book's great open-source case study — every concept in a real, shipping system. It's a modular monolithic kernel: one fast kernel with loadable modules for drivers and file systems. It creates processes with fork/clone, shares the CPU with the fair CFS scheduler, manages memory with demand paging and a large page cache, and abstracts all storage through the VFS. Everything from the earlier chapters, made concrete.

After nineteen chapters of concepts, Linux is where they all show up at once — running most of the world's servers, all Android phones, and the cloud. It's the proof that these ideas aren't theory: here's a real kernel built from them, whose source you can read.

01 Design and history

Linux started in 1991 as Linus Torvalds's hobby kernel and grew, through open-source collaboration, into one of the most widely deployed systems ever. Design goals: UNIX-compatible, efficient, portable across hardware, and open. Strictly, "Linux" is the kernel; a full distribution adds the GNU tools, libraries, and applications around it (hence "GNU/Linux").

02 Modular monolithic kernel

Linux made a deliberate architectural choice (Chapter 2): a monolithic kernel for speed — scheduling, memory, file systems, and networking all run in kernel space — but modular, via loadable kernel modules that add drivers and file systems at runtime without rebooting or rebuilding the kernel.

key ideaThis is the famous Torvalds–Tanenbaum trade-off resolved in practice. Linux kept the speed of a monolith (no message-passing overhead) but bought back flexibility with modules. The result outcompeted both pure microkernels and rigid monoliths — engineering pragmatism over purity.

03 Process and thread management

Linux creates processes with fork() (copy the caller, using copy-on-write from Chapter 10 so it's cheap) then exec() (load a new program), exactly as Chapter 3 described. Internally it uses clone(), which can selectively share resources (memory, file descriptors, signal handlers). That's how Linux implements threads: a thread is just a task that shares its parent's address space. To the kernel, threads and processes are variations of one structure (task_struct).

04 The CFS scheduler

Linux's Completely Fair Scheduler (CFS) aims to give every runnable task a fair share of CPU. Rather than fixed time slices, it tracks each task's accumulated virtual runtime and always runs whichever has gotten the least, weighted by priority (the nice value). The effect is Chapter 5's fairness goal realized cleanly — interactive tasks stay responsive and nothing starves. (Recent kernels move toward the EEVDF scheduler, refining the same fairness idea.)

05 Memory management

Linux uses everything from Chapters 9–10: paging, demand paging, copy-on-write, and page replacement (an LRU approximation via the clock/second-chance idea). It maintains per-process page tables, uses the TLB, and swaps to disk under memory pressure. It also keeps a large page cache in otherwise-free RAM to hold recently used file data.

note"Linux ate all my RAM!" is a classic misunderstanding. Free RAM is wasted RAM, so Linux fills it with the page cache (cached file data) and instantly releases it when programs need memory. High memory "usage" from caching is the system working well, not a leak. The free command's "available" column shows the truth.

06 The VFS and file systems

Linux's virtual file system (Chapter 15) supports dozens of file systems — ext4, Btrfs, XFS, FAT, NFS — through one interface. Its common native choice, ext4, is a journaling file system (Chapters 14–15) giving fast crash recovery. Following the UNIX "everything is a file" philosophy, even devices and kernel data appear as files (under /dev, /proc, /sys) — a single uniform interface to wildly different things.

common catches & gotchas

  • Linux is the kernel, not the whole OS — A distribution = the Linux kernel + GNU tools + apps. The pedantic "GNU/Linux" point shows up in exams.
  • Threads are processes that share memory — Linux has no separate thread type — clone() makes a task sharing the parent's address space. The unified model surprises people.
  • High RAM use is healthy — The page cache fills free RAM by design and frees it on demand. Don't read cache usage as a memory leak.
  • fork is cheap because of COWfork() doesn't copy memory upfront; copy-on-write shares pages until one side writes. Assuming a full copy misjudges its cost.
  • Monolithic but modular — Linux runs services in kernel space (monolithic) yet loads modules at runtime. It's neither a pure microkernel nor a rigid monolith.

07 Questions students actually ask

Is Linux a microkernel or monolithic?

Monolithic — core services run together in kernel space for speed — but modular, using loadable kernel modules to add drivers and file systems at runtime. It deliberately combines the monolith's speed with module flexibility.

How does Linux implement threads?

Through clone(), which creates a task that can share memory and other resources with its parent. A thread is just a task sharing its parent's address space, so the kernel treats threads and processes with the same underlying structure.

What does the CFS scheduler optimize for?

Fairness. It tracks how much virtual runtime each task has used and runs the one that's gotten the least (weighted by nice priority), so every task gets a fair share and interactive tasks stay responsive without fixed time slices.

Why does Linux seem to use all my RAM?

It fills otherwise-idle RAM with a page cache of recently used file data to speed things up, and releases it instantly when applications need memory. High usage from caching is good behavior, not a problem.

Why is fork() cheap in Linux?

Because of copy-on-write: parent and child share the same physical pages (marked read-only) until one writes, at which point only that page is copied. Forking doesn't duplicate the whole address space upfront.

08 Key takeaways

  • Linux is the book's real, open-source case study — every concept, in production.
  • It's a modular monolithic kernel: fast core plus loadable modules.
  • Processes use fork/exec (with copy-on-write); threads are built on clone().
  • The CFS scheduler delivers fair CPU sharing via virtual runtime.
  • Memory uses paging, demand paging, COW, and a big page cache (high RAM use is healthy).
  • The VFS supports many file systems; ext4 journals; "everything is a file."

09 Wrapping up

Linux shows the concepts in an open system. The final chapter shows them again in a very different but equally real design — Microsoft's Windows. Next up: Windows 10.

← prev: Chapter 19next: Chapter 21 →
© cvam — written in plaintext, served warm