ELI5 · How computers work

Virtual memory.

Giving every program its own private, tidy address space, while the OS quietly maps it onto the real, messy RAM.

If every program shared one big pool of physical memory directly, they would constantly trip over each other's data, and each would have to know exactly which free regions it was allowed to use. That is a recipe for chaos and crashes.

Virtual memory hands each program its own private, clean address space that starts at zero and looks like it has the whole machine to itself. Behind the scenes the operating system, with help from the CPU, maps those make-believe addresses onto wherever the data really sits in physical RAM — like everyone using simple apartment numbers while the post office knows the real GPS coordinates.

  1. Apartment 1, all mine.
    program A program B 012012 each starts at zero
    1

    Every program gets its own tidy address space, starting at zero, as if it owned the machine.

  2. Send it to flat 42.
    read flat 42 a virtual address
    2

    When it reads an address, that’s a make-believe one — a flat number, not a real location.

  3. flat 42 PAGE TABLE → RAM 0x9C real RAM
    3

    The page table is the post office: it looks up where that page really sits in RAM.

  4. No address for next door.
    program A program B no name for next door
    4

    Each program has its own mapping, so one literally can’t name another’s memory.

  5. One moment, retrieving…
    RAM missing disk page fault
    5

    If the page was parked on disk, a page fault fetches it back before work continues.

  6. Why is everything frozen?
    RAM disk thrashing — it crawls
    6

    Too much of that and pages ping-pong to slow disk — thrashing grinds it to a crawl.

Each program uses simple apartment numbers; the OS post office knows the real address behind every one.

Isolation and the illusion of space

Because each process has its own mapping, one program literally cannot name another's memory — its virtual addresses translate only to its own pages. That isolation is a cornerstone of stability and security: a misbehaving app cannot scribble over the kernel or its neighbours. The mapping also lets the OS present more address space than physically exists and place a program's pages wherever there is free RAM, so memory need not be one contiguous block.

Paging and swapping

Memory is handled in fixed-size chunks called pages. When RAM fills up, the OS can move rarely-used pages out to disk and bring them back on demand. Touching a page that is currently on disk triggers a page fault, and the program pauses while the OS fetches it. A little of this is fine; too much — when active pages keep ping-ponging to disk — is "thrashing", and it makes a machine grind to a near halt because disk is thousands of times slower than RAM.

The real version Virtual memory simulator →
Found this useful?