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 18 min to read

Play it as a journeyTutor comes with a plan

When memory runs out: OOM, swap and NUMA

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

: the kernel in the middle, handing every program its memory. This lesson follows what the kernel does when the memory it promised is not there.

On 28 November 2026 I ran a small Python program on a Linux machine with 16 GB of RAM. It asked the kernel for 4 GB, then 8 GB, then 16 GB. The kernel said yes to all three. That is 28 GB promised on a machine that holds 16 GB. Then I ran another program inside a box limited to 100 MB, and it tried to use 300 MB. It did not get an error message. It was killed, and the only trace was the number 137.

Both are normal. By the end of this lesson you will be able to say what Linux does when a program asks for more memory than exists, when memory truly runs out, and why the same memory read can be slower on a big server.

The history (optional)

On 24 September 2004, Andries Brouwer replied on the Linux kernel mailing list to Thomas Habets. Habets had proposed a setting so that chosen programs would never be killed when memory ran out. Brouwer answered with a story about an aircraft company that flew with less fuel to save money, and threw a passenger out when fuel ran short. His point: killing a process is a poor emergency tool, and arguing about whom to kill never ends. LWN printed the thread on 28 September 2004.

Before you start. In The address book every process carries you saw that asking for memory only writes a promise into a program’s page table, and that a real page of RAM is handed over at the first touch, through a page fault. A program with less RAM than its working set (the pages it uses right now) thrashes, waiting for the disk. The Memory Hierarchy (cache, locality, the memory wall) gave the reason: the disk is far slower than RAM. Running a Container for Real showed the exit code 137 from the outside.

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

  • Overcommit: promising more memory than exists
  • The memory limit and the OOM killer: when the promise comes due
  • Swap: space on the disk that postpones the kill
  • NUMA node: when the distance to memory is not the same

Terms it explains: Overcommit, out-of-memory killer, memory limit, swap, NUMA node, context switch, fork/exec, init/systemd, kernel, MMU + page table, namespaces + cgroups, page (~4KB) / frame, page fault, PID, preemption, process, scheduler, segfault, 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