Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 04 · How Computers Work · Inside the operating system · with code: Python · about 21 min to read

Play it as a journeyTutor comes with a plan

The address book every process carries

Processes Threads and the Kernel
Processes Threads and the Kernel · Open board

The kernel in the middle, handing every program a private-looking stretch of memory. This lesson opens the book the kernel keeps for each program, and asks what happens when the real memory behind it runs short.

Before you start. RAM is fast and small, the disk is huge and far slower, and a program runs well only when what it needs sits in the fast part (The Memory Hierarchy (cache, locality, the memory wall)). The address a program uses is not where its data really is: the kernel, the one program with full control of the hardware, translates every address on the way (Processes, Threads & the Kernel). And the kernel moves memory around in fixed-size pieces called pages, the same pieces it uses to cache files (The drawer that says it saved).

Lesson 16 of 41 in How Computers Work

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • 1966: the computers that slowed down when you gave them more work
  • Every address goes through a book: the page table
  • Asking for a gigabyte and getting nothing: the page fault
  • When the slots run out: who gets thrown out
  • Christmas 1966: the working set, and thrashing
  • A copy that costs nothing until someone writes: copy-on-write

Terms it explains: page table, page fault, working set, thrashing, copy-on-write, TLB, context switch, fork/exec, init/systemd, kernel, MMU + page table, namespaces + cgroups, page (~4KB) / frame, PID, preemption, process, scheduler, segfault, swap, syscall, thread, user vs kernel mode (ring 3/0), virtual memory.

Lab

The program needs twelve pages at once. What happens when it gets eleven frames?

Drag Frames of real memory from 24 down to 11, then back to 12, and watch Time spent working.

Open The working set

Three long jobs are running when you press a key. How long until the keypress gets the CPU?

Click Take turns, drag How long one turn lasts from 100 ms down to 1 ms, and watch The keypress waits.

Open The time slice

How many workers should a pool have, and why does the answer flip when the tasks mostly wait?

Drag Workers on shift down to the core count, then push Share of each task spent waiting to 90% and watch Finished each second.

Open The thread pool

Related papers

Review How Computers Work