nirbhay.sh
../writing

How a 100 GB Game Fits in 16 GB of RAM

date
2026-06-07
tags
paging, os-internals, x86-64, memory
length
2,324 words · ~12 min
On this page

Install a big open-world game with the texture pack — Cyberpunk, or Flight Simulator with scenery mods — and the process will happily map on the order of 100 GB of virtual memory. Your machine has 16 GB of RAM.

Nothing about that is a trick of accounting. The game really does address all of it, and the hardware really does translate every one of those addresses. Here is the machinery that makes it work.

The two numbers to hold onto:

SizeIn 4 KB pages
Game virtual address space100 GB26,214,400 virtual pages
Physical RAM16 GB4,194,304 physical frames

Plus an NVMe SSD with a swap file (swapfile.sys, or /swapfile) to hold whatever doesn't fit.

Does any of this fit anywhere?

Two separate questions get confused here, and separating them is most of the insight.

Can 100 GB of translations live in the TLB? No, and not remotely. A 1,536-entry L2 TLB covers 1,536 × 4 KB = 6 MB of address space. Switch to 2 MB huge pages and it covers 3 GB — better, still nowhere near 100 GB. The TLB is missing and evicting constantly while the game renders.

Can the page table itself live in RAM? Yes, easily, and this is the part that surprises people. Every virtual page needs one 8-byte leaf entry:

26,214,400 PTEs x 8 bytes = 209,715,200 bytes = 200 MB

The upper levels add roughly 400 KB on top (each level is 512x smaller than the one below it — there's a full derivation in the appendix). So the entire four-level page table tree for a 100 GB game costs about 200.4 MB of RAM.

That fits inside 16 GB without trouble. The page table was never the problem. The 100 GB of actual game data is the problem.

Which leaves the real question: how does a 200 MB page table in RAM track 100 GB of virtual pages when only 16 GB of physical frames exist to point at?

The two personalities of a page table entry

Every leaf entry in the level-1 page table is a 64-bit integer. What those 64 bits mean depends entirely on bit 0 — the present bit.

CASE A: page is in physical RAM (bit 0: Present = 1)
┌──────┬──────────────────────────────┬─────────────────┬───┬───┬───┬───┐
│  NX  │   Physical Frame Number      │  OS / Ignored   │ D │ A │R/W│ P │
│Bit 63│   (PFN, bits 12..51)         │   (bits 9..11)  │ 6 │ 5 │ 1 │ 0 │
└──────┴──────────────────────────────┴─────────────────┴───┴───┴───┴───┘
  ▲                  ▲                                    ▲   ▲       ▲
No-Exec      read by the hardware MMU                   Dirty Acc  Present=1
             (goes straight into the TLB)


CASE B: page was evicted to disk (bit 0: Present = 0)
┌───────────────────────────────────────────────────────┬───────────┬───┐
│              Disk swap offset (50+ bits)              │ Swap type │ P │
│        (which 4 KB slot inside /swapfile on SSD)      │ (bits 1-5)│ 0 │
└───────────────────────────────────────────────────────┴───────────┴───┘
                             ▲                                        ▲
         the MMU ignores bits 1..63 when P=0                      Present=0
         so the kernel hides the disk address there

Case B is the load-bearing trick, and it is real hardware behaviour on both x86-64 and ARM64:

  • When P = 1, the hardware page table walker reads bits 12..51 as the physical frame number.
  • When P = 0, the walker stops immediately and raises a page fault (#PF, interrupt 14 on x86). It never looks at the other 63 bits.

Because the hardware ignores those 63 bits, the kernel is free to store whatever it likes in them — and what it stores is the exact offset in the swap file where it hid that page.

For our game on a full 16 GB machine, the split looks roughly like:

Present bitCountCoversPoints at
P = 1~3.5M PTEs~14 GBphysical frames in RAM
P = 0~22.7M PTEs~86 GBswap offsets, or file-backed assets on SSD

Three accesses, three very different costs

Walk your character through the world and the CPU will hit all three of these, often within the same frame.

1. TLB hit — the hot path (~0.5 ns)

The renderer touches a texture it used a microsecond ago, at virtual address 0x00007FF123456000.

  1. The CPU looks up the VPN (0x7FF123456) in the 64-entry L1 dTLB.
  2. Hit. The TLB returns PFN #10420.
  3. The page table in RAM is never touched.

One clock cycle. This is the overwhelming majority of memory accesses, and it is why paging is affordable at all.

2. TLB miss, page in RAM (~10–30 ns)

You spin the camera 180°, and the CPU reaches a tree mesh at 0x00007FF555555000. The mesh is resident in RAM at PFN #88888, but with only 1,536 TLB entries its translation fell out milliseconds ago.

  1. L1 and L2 TLB both miss.

  2. The kernel is not involved. On x86-64 and ARM64 the OS never learns that a TLB miss happened.

  3. The hardware page table walker starts from CR3 and walks the four levels.

    This is where the paging-structure caches earn their silicon. Intel calls them the PML4, PDPTE and PDE caches. Because millions of pages share the same top three levels, the walker almost always hits in the PDE cache, skips the first three lookups, and performs a single RAM read to fetch the leaf PTE.

  4. The MMU checks bit 0 — Present = 1 — pulls PFN #88888 out of bits 12..51, installs VPN 0x7FF555555 → PFN #88888 into the TLB (evicting something older), and the instruction resumes.

Total stall: roughly 15–40 cycles. You don't drop a frame.

3. TLB miss and a major page fault (~100,000 ns)

Now fast-travel. The game touches a building at 0x00007FF999999000, part of the ~86 GB that was pushed out to the SSD.

1. Translation fails. L1 TLB miss, L2 TLB miss, hardware walk reads the leaf PTE, and bit 0 is 0.

2. The hardware traps. The MMU can't translate a non-present entry, so the CPU saves the thread's registers, writes the faulting address into CR2 (FAR_EL1 on ARM64), switches to ring 0, and jumps to the kernel's fault handler — do_page_fault on Linux.

3. The kernel reads the hidden offset. It reads CR2 to find out which address failed, walks the same page table in software, sees Present == 0 with bits 1..63 non-zero, and decodes them: swap offset #4,500,123.

4. It needs a free frame, and there are none. RAM is full, so the kernel has to evict. Using the active/inactive LRU lists it picks a page the game hasn't touched in twenty minutes — say VPN 0x7FF111111, currently holding PFN #55555. Evicting it means:

  1. If that PTE's hardware dirty bit is set, write the 4 KB at PFN #55555 out to swap (say offset #8,000,000).
  2. Rewrite the victim's PTE to Present = 0 | swap offset #8,000,000.
  3. TLB shootdown. Other cores may still have VPN 0x7FF111111 → PFN #55555 cached in their own TLBs, and the hardware will not notice that the PTE changed underneath them. The kernel issues INVLPG locally and sends an inter-processor interrupt to every other core running the process, forcing them to flush that entry. This is genuinely expensive, and it is pure coordination overhead.

5. Read the page in. PFN #55555 is free now, so the kernel issues an NVMe read from swap offset #4,500,123 into it. That takes 50–100 µs. The scheduler sleeps the thread and runs something else — and if this was the main render thread, that is your frame hitch.

6. Fix up and retry. DMA completes, the kernel sets the faulting PTE to Present = 1 | PFN #55555 | RW = 1, and returns via IRET to re-execute the exact same instruction. This time the walk finds a present entry, fills the TLB, and the game continues.

Three accesses to three addresses, spanning five orders of magnitude: ~0.5 ns, ~20 ns, ~100,000 ns.

How does the kernel know which PTE to invalidate?

Step 4 above hides a real problem. When the kernel decided to evict PFN #55555, how did it know that frame belonged to VPN 0x7FF111111 of this particular process, so it could go and clear the present bit in that entry?

The x86-64 page table is a forward table: it maps VPN → PFN. You cannot ask it the reverse question without scanning millions of entries.

So Linux keeps its own inverted table in software. For every physical frame in RAM — all 4,194,304 of them — it maintains a struct page (a struct folio in modern kernels), indexed by PFN, in the mem_map array. Inside each one is a reverse mapping (rmap) back to the processes and virtual addresses using that frame.

The result is a clean division of labour:

DirectionUsed byStructure
VPN → PFNCPU hardware MMU, on every TLB miss4-level forward page table
PFN → VPNkernel reclaim (kswapd), when evictingmem_map[PFN] reverse map

The hardware gets the fast path in silicon. The kernel gets the bookkeeping it needs to take a frame away.

The whole picture

CPU core accesses a virtual address in the 100 GB game space
  │
  ├─► 1. Check L1/L2 TLB (~1,536 entries in silicon)
  │      ├── HIT (~1-7 cycles) ──────────────────────────► read RAM at PFN
  │      └── MISS
  │           │
  │           ▼
  ├─► 2. Hardware MMU walks the 4-level page table in RAM
  │      (200 MB total; accelerated by paging-structure caches for L4/L3/L2)
  │      Inspects the 8-byte leaf PTE:
  │      ├── Present == 1  (~14 GB of game) ─────────────► fill TLB, read RAM
  │      └── Present == 0  (~86 GB of game)
  │           │
  │           ▼
  └─► 3. Hardware traps to the kernel (#PF, faulting address in CR2)
         ├── pick a victim PFN via clock/LRU (kswapd)
         ├── use mem_map[victim_PFN] to find the old VPN, write the dirty
         │   page to swap, set the old PTE Present = 0, then TLB shootdown
         │   (INVLPG + IPI to every other core)
         ├── read the swap offset hidden in bits 1..63 of the faulting PTE
         │   from SSD into victim_PFN
         └── set the faulting PTE Present = 1, retry the instruction

TLB reach, four-level radix trees, the present bit, reverse mappings, LRU eviction and SSD latency are usually taught as separate topics. They are one mechanism, and this is the shape of it.

Appendix: where every byte of the page table goes

The 200.4 MB figure above deserves showing rather than asserting.

The golden rule

Every table, at every level, has identical structure:

  • One table is 4 KB
  • One entry is 8 bytes
  • So one table holds 4096 / 8 = 512 entries

It is a 512-way radix tree. Every parent has 512 slots pointing at children.

Level 4 (PGD)          1 table (4 KB)
                         │ uses 1 slot of 512
                         ▼
Level 3 (PUD)          1 table (4 KB)
                         │ uses 100 slots of 512
                         ▼
Level 2 (PMD)        100 tables (400 KB)
                         │ 100 x 512 = 51,200 slots
                         ▼
Level 1 (PTE)     51,200 tables (200 MB)
                         │ each points at 512 data pages
                         ▼
Game data     26,214,400 virtual pages (100 GB)

Working bottom-up

Our game maps 100 GB = 102,400 MB.

Level 1 (PTE). Each 4 KB data page needs one 8-byte entry, and a table holds 512 of them, so one L1 table covers 512 x 4 KB = 2 MB of game data.

102,400 MB / 2 MB per table = 51,200 L1 tables
51,200 tables x 4 KB        = 204,800 KB = 200 MB

Level 2 (PMD). Each L2 table holds 512 pointers to L1 tables, so one L2 table covers 512 x 2 MB = 1 GB.

51,200 L1 tables / 512 pointers = 100 L2 tables
100 tables x 4 KB               = 400 KB

Level 3 (PUD). Each L3 table holds 512 pointers to L2 tables, covering 512 x 1 GB = 512 GB. We need 100 of those slots, so a single table does it, with 412 slots empty. 4 KB.

Level 4 (PGD). Every process has exactly one, pointed at by CR3. Its 512 slots cover 512 GB each — 256 TB of 48-bit address space in total. Our game uses one slot. 4 KB.

Summary

LevelLinuxIntelOne table coversTables for 100 GBRAM
L4 (root)PGDPML4256 TB1 (1/512 full)4 KB
L3PUDPDPT512 GB1 (100/512 full)4 KB
L2PMDPD1 GB100400 KB
L1 (leaf)PTEPT2 MB51,200200 MB
Total51,302 pages200.4 MB

Two things worth taking away

Each level up is 512x smaller, because each table holds 512 pointers: 200 MB → 400 KB → 4 KB → 4 KB. The tree is almost entirely leaves.

That is exactly why the paging-structure caches work. There are 51,200 level-1 tables, but only 102 tables total across levels 2, 3 and 4 — about 408 KB. A cache small enough to fit on the die can hold nearly all of the upper tree, which turns a four-read page table walk into a single read for the leaf. The 100 GB game is tractable because its page table is shaped like a pyramid with almost nothing above the base.