Memory management lets many processes share physical RAM safely. Modern systems use paging: memory is split into fixed-size pages (logical) and frames (physical), and a page table maps one to the other. Virtual memory extends this so a process can use more memory than physically exists, by keeping some pages on disk.
Paging & virtual memory
Paging divides logical memory into fixed-size pages and physical memory into frames; a page table translates page numbers to frame numbers. Virtual memory keeps only the needed pages in RAM and the rest on disk, so programs can be larger than physical memory and stay isolated.
Paging vs segmentation
| Aspect | Paging | Segmentation |
|---|---|---|
| Block size | fixed (pages) | variable (segments) |
| Fragmentation | internal | external |
| View | physical, uniform | logical (code, stack, data) |
⚡ The edge
- A page fault is when a referenced page is not in RAM; the OS fetches it from disk — expensive, so minimising faults is the goal of page-replacement algorithms.
- Know the replacement algorithms: FIFO (oldest out, can suffer Belady's anomaly), LRU (least recently used, a good practical choice), Optimal (evict the page used farthest in the future — a benchmark).
Worked example
'What is virtual memory and why is it useful?'
- Define it: virtual memory gives each process a large, contiguous address space while keeping only some pages in RAM and the rest on disk.
- State the benefits: programs can exceed physical memory, processes are isolated, and memory is used efficiently.
- Mention the cost: accessing a page on disk causes a page fault, which is slow.
Answer: An abstraction giving each process a large private address space, paging unused parts to disk.
Worked example
'What is thrashing?'
- Define it: thrashing is when the system spends more time swapping pages in and out of disk than doing useful work.
- Explain the cause: too many processes competing for too little RAM, so the page-fault rate skyrockets.
- Give the fix: reduce the degree of multiprogramming, or add RAM; the working-set model helps.
Answer: Excessive paging where the CPU mostly swaps pages instead of executing — caused by over-committed RAM.
⚠ Watch out
- Internal fragmentation (wasted space inside a page) belongs to paging; external fragmentation belongs to segmentation.
- FIFO can show Belady's anomaly — more frames sometimes cause more faults; LRU and Optimal never do.
- A page fault is normal and handled by the OS — it is not a crash.