Huge pages
Every memory access uses a virtual address that must be translated to a physical one. The CPU keeps recent translations in a small cache, the TLB. A typical TLB holds 32, 64 or 128 entries, and each entry covers one page.
Leave line 1 out for now. Line 2 fills a 2 MiB buffer. On ordinary 4 KiB pages that is 512 pages: 512 page faults and 512 translations. A 64-entry TLB reaches only 256 KiB, so it keeps missing.
On a TLB miss the hardware walks the page table. On x86-64 that is four levels, each indexed by 9 bits of the address, so up to four memory reads before the data itself. 512 misses mean up to 2,048 extra reads.
Line 1 asks the kernel for huge pages here. Now one entry at the third level, the PMD, points straight at a 2 MiB block of physical memory. The walk stops a level early, and one TLB entry covers the whole buffer.
A huge page needs 2 MiB of free physical memory in one aligned piece, which gets hard once memory is fragmented. Touch one byte and you still get 2 MiB, and the kernel must zero all of it. So Linux makes them optional.
NUMA placement
Big servers are often NUMA machines: each processor socket has its own memory, and Linux calls each socket with its memory a node. A CPU reaches its own node's memory fastest. The other node's memory is reached over a link between sockets, more slowly.
Memory is placed when a page is first touched, not when it is allocated. Line 2 runs on a CPU in node 0, so Linux's default local policy takes the huge page from node 0's memory.
Line 3 runs in a worker thread the scheduler put on node 1. Each cache line it reads (the small block a CPU fetches at once) comes over the link from node 0: all 2 MiB is remote and slower.
Linux can fix this. Automatic NUMA balancing notices node 1 using the page and migrates it there, or a program asks with move_pages() or mbind(). The huge page is one block, so it moves all at once. Later reads are local.
Huge pages cut TLB misses and page-table walks for big, busy memory. NUMA placement keeps that memory on the node whose CPUs use it. Both serve one goal: fewer slow trips for each useful memory access.
What happens
;; step 1/10 · tlb virtual address -> TLB -> physical address page size 4 KiB (ordinary x86-64 page) TLB 64 entries (OSTEP: typically 32, 64 or 128) reach 64 x 4 KiB = 256 KiB reach (or coverage): how much memory the TLB can translate without a miss
Sizes are for x86-64 Linux: 4 KiB pages, 2 MiB huge pages at the PMD level and 1 GiB pages at the PUD level. RISC-V has the same 4 KiB and 2 MiB sizes. Linux can also use five-level page tables; the lesson shows the usual four. The figure draws fewer small tiles than the 512 real pages, so they stay readable.