Virtual memory: every program gets its own map
See how each process gets its own private address space, how page tables translate its addresses into real RAM, and what happens when RAM runs out.
THE IDEA
Each process gets its own private addresses
With virtual memory, each process sees its own address space, starting near 0, as if it had the whole memory to itself. The addresses it uses are virtual: they're not the real numbers of boxes in RAM. Behind the scenes, the kernel and the processor translate every virtual address into a real, physical one. Two programs can both use address 4096 and never meet, because each one's 4096 leads somewhere different.
A game and a browser can both believe their data starts at the same address. Neither knows, or needs to know, where in RAM it really is.
Check yourself
Why don't operating systems simply let every process use real RAM addresses directly?
- Because real addresses are too long to fit in a register
- Because one buggy program could overwrite another's data, and every program would need to know where the others are
- Because RAM can only be read by the kernel
- Because real addresses change every time the computer ticks
Show the answer
Because one buggy program could overwrite another's data, and every program would need to know where the others are
Right. Shared real addresses mean no walls between programs and constant bookkeeping about who's where. Private virtual addresses fix both.
Page table
Memory is handled in chunks called pages, commonly 4 KB (4,096 bytes) each. For every process the kernel keeps a page table: a list saying which virtual page sits in which physical page of RAM, called a frame. A part of the processor, the MMU (memory management unit), looks up every single address on the fly. It keeps a small cache of recent translations, so this lookup is almost always fast.
Virtual addresses 4096 to 8191 are page 1. If a process's table says "page 1 → frame 7", then its address 4096 really means the start of frame 7 in RAM.
Flat 1 in two different buildings
Two friends both live in "flat 1". That's no problem, because one lives in building A and the other in building B; the building turns "flat 1" into a real place on the map. A process's virtual address is the flat number, its page table is the building, and the physical frame is the real spot. Where the analogy breaks: the kernel can quietly move a process's page to a different frame, even out to the disk, and just update the table, which no real building can do with a flat.
Check yourself
What does a process's page table do?
- Lists which files the process has open
- Maps the process's virtual pages to physical frames in RAM
- Decides how long the process's time slice is
- Stores the process's machine code
Show the answer
Maps the process's virtual pages to physical frames in RAM
Right. It's the translation list: virtual page in, physical frame out. The MMU uses it for every address the process touches.
Step through it

Two processes, both using address 4096 On the left are two processes, A and B, each with three pages numbered 0, 1 and 2; page 1 in both starts at address 4096. On the right is RAM with eight frames, 0 to 7. Nothing is connected yet: both programs have their own addresses starting from zero, and both use 4096.

A's 4096 goes to frame 7, B's to frame 3 Arrows now run from each process's pages to frames in RAM, through the MMU. A's page 1 lands in frame 7 and B's page 1 in frame 3; the other pages go to other free frames. Same number, 4096, but different real memory, so neither can see the other's data.

RAM is full: A's page 2 goes out to swap Now frames 1 and 4 fill up too, so every frame in RAM is taken. The kernel picks a page that hasn't been used for a while, A's page 2, copies it down to a swap area on the SSD and frees its frame, 5. A's page table now points page 2 at the disk, shown by the dashed line.

Page fault: page 2 comes back to frame 5 Process A touches page 2 again. The MMU finds it isn't in RAM and raises a page fault; the kernel pauses A, reads the page back from the SSD into free frame 5, and turns the arrow solid again. A carries on without ever knowing, except that it had to wait for the disk.
Check yourself
In the frames, process A and process B both wrote to their address 4096, so one of them overwrote the other's data.
Show the answer
False
False. A's page table sends its 4096 to frame 7 and B's sends its 4096 to frame 3. Same virtual number, different physical memory, so they never touch.
PROTECTION
Why one crash doesn't take down the computer
If a program uses an address that isn't in its page table at all, the MMU stops it, and the kernel ends that one program. On Linux and macOS this is called a segmentation fault, on Windows an access violation. The crash stays inside that one process, instead of the bad write landing in someone else's memory and taking down the whole machine.
A buggy game follows a broken pointer to an address it was never given. The game closes with an error; your browser and music keep going.
When RAM runs out
- Page out
The kernel copies a page that hasn't been used for a while to a swap file (Windows calls it a paging file) on the disk, and frees its frame.
- The program touches it
Later the program uses an address on that page. The MMU sees it isn't in RAM: a page fault.
- Page in
The kernel pauses the program, reads the page back from disk into a free frame and updates the page table.
- Carry on
The program continues from the same instruction. It never notices, except that it waited.
Check yourself
A program touches a page that the kernel had moved out to swap. What happens?
- The program crashes with a segmentation fault
- A page fault: the kernel pauses it, brings the page back from disk into RAM, updates the table and lets it continue
- The processor reads the value straight from the swap file and keeps it there
- The program has to restart from the beginning
Show the answer
A page fault: the kernel pauses it, brings the page back from disk into RAM, updates the table and lets it continue
Right. The address is valid, just not in RAM right now. The page fault lets the kernel fetch it back and resume the program at the same instruction.
Check yourself
Match each term to what it means
Show the answer
- Virtual address → A number a process uses, private to that process
- Page → A 4 KB chunk of a process's address space
- MMU → The part of the processor that translates each address
- Swap → Space on the disk where pages go when RAM is full
- Thrashing → Constant paging in and out that makes a computer crawl
Lesson recap
- Virtual memory gives each process its own private address space, starting near 0.
- Memory is handled in 4 KB pages; each process's page table maps its virtual pages to physical frames, and the MMU translates every address.
- Two processes can use the same address, like 4096, and still reach different real memory.
- An address outside a process's table stops only that program: a segmentation fault or access violation.
- When RAM is full, idle pages go to swap on the disk and come back through a page fault; too much of that is thrashing.