Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Why We Need Paging

Note: This section draws from Samy Pesse’s How to make an Operating System.

The Problem Without Paging

Without paging, every process sees the same physical memory. Process A can read and write Process B’s memory. A bug in any program can corrupt the kernel. You’re limited to the actual amount of RAM in the machine.

What Paging Gives You

A paged system gives each process its own virtual 4GB address space — completely isolated from every other process:

Physical Memory          Process A              Process B
┌───────────┐            ┌───────────┐          ┌───────────┐
│ 00x: HELL │            │ 00x: HELL │          │ 00x: HAVE │
│ 01x: RLD! │  ←mapped   │ 01x: O WO │  ←mapped │ 01x: LOT  │
│ 02x: O WO │            │ 02x: RLD! │          │ 02x: S OF │
│ 03x: HAVE │            │ 03x: #### │          │ 03x: FUN  │
│ 04x:  FUN │            │ 04x: #### │          │ 04x: #### │
│ 05x:  LOT │            │ 05x: ;-)  │          │ 05x: ;-)  │
│ 06x: S OF │            └───────────┘          └───────────┘
│ 07x: ;-)  │
└───────────┘

Both processes can use address 0x00000000 without conflict. Their page tables map that virtual address to different physical pages. Neither process can see the other’s memory.

The Three Benefits

1. More memory than RAM

Virtual addresses can map to disk (swap space). Pages that aren’t accessed can be moved to disk and loaded back when needed. Processes can use more memory than physically exists.

2. Unique memory space per process

Every process thinks it owns 4GB of address space. The kernel manages the actual physical memory behind the scenes.

3. Dynamic permission control

Memory pages can be marked read-only, executable, or inaccessible. The CPU enforces these permissions in hardware. Writing to a read-only page generates a page fault, not silent corruption.

What This Means for KFS_3

At this stage, KFS_3 is a single-process kernel — there are no user processes yet. The paging system we build here is the foundation that will eventually support:

  • Process isolation (when we add user-mode processes)
  • Memory protection (kernel vs user space)
  • Dynamic allocation (kmalloc/vmalloc sitting on top of page frames)

For now, the most important thing paging gives us is a controlled memory allocation system — instead of raw physical addresses, we work with frames and virtual mappings.