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 · about 14 min to read

Play it as a journeyTutor comes with a plan

A computer inside a computer: virtualization

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

: the kernel in the middle, sharing one machine between many programs. This lesson puts a second referee under the kernel, so that whole computers can share one machine.

Before you start. In Four ways to get stuck: deadlock, two cooks shared one knife and one board, and a rule about who may hold what kept the kitchen from freezing. Sharing needs a referee. On your laptop the referee is the kernel, the one program with full control of the hardware, and the chip enforces that with a privileged mode that ordinary programs cannot enter (Processes, Threads & the Kernel). The kernel also gives each program its own private-looking addresses and translates them to real memory (The address book every process carries). This lesson asks what happens when the program you want to share the machine with is itself a kernel.

Lesson 24 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

  • The problem: a rack of servers doing almost nothing
  • The hypervisor: a kernel for kernels
  • Trap and emulate: a privileged instruction becomes a call to the hypervisor
  • VT-x: the chip learns about guests
  • Paravirtualization: a guest that knows and helps
  • A container is not a computer: only a fenced-off program
  • Type 1 and type 2 hypervisors
  • Memory: two page tables, one walk
  • A trap and emulate monitor in 12 lines
  • Sharing memory between VMs, and the packing sum
  • Edge cases and trade-offs

Terms it explains: hypervisor, virtual machine, trap, trap and emulate, VT-x, VM exit, VM entry, paravirtualized, hypercall, container, type 1, type 2, context switch, fork/exec, init/systemd, kernel, MMU + page table, namespaces + cgroups, page (~4KB) / frame, page fault, 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