Describe paging: how RAM is divided into fixed-size frames and pages
Describe segmentation: logical variable-size division of memory
Explain virtual memory and the page table; define page fault
Explain the TLB and thrashing
Paging
Paging
Paging divides physical memory (RAM) into fixed-size frames and a process’s logical memory into same-size pages. Pages are mapped to frames via a page table (one per process).
Pages can be placed in any free frame — no need for contiguous memory allocation. Eliminates external fragmentation.
Page size is typically 4 KB (OS configurable). A process’s pages may be scattered across non-contiguous frames.
Page table entry: frame number + valid/invalid bit + dirty bit (data modified) + reference bit (recently accessed).
Virtual Memory
Virtual Memory and Page Faults
Virtual memory allows a process to use more memory than physically available by storing some pages on secondary storage (disk/SSD). Processes see a large virtual address space regardless of physical RAM.
Page fault: CPU accesses a page not currently in RAM (valid bit = 0). OS is interrupted and loads the required page from disk to a free frame. This is slow (disk access vs RAM access).
Thrashing: if too many pages are swapped in/out rapidly, the system spends more time managing paging than executing processes. Performance collapses. Caused by insufficient physical RAM.
TLB
Translation Lookaside Buffer (TLB)
The TLB is a fast, small hardware cache inside the CPU that stores recently used page table entries (virtual page → physical frame mappings).
TLB hit: page mapping found in TLB. Address translated in 1–2 cycles — fast.
TLB miss: mapping not in TLB. OS must access the page table in RAM to find the frame number — slower. Result is cached in TLB for future use.
High TLB hit rate is essential for performance. Modern CPUs have 64–1024 TLB entries; working set of a program should fit to maximise hit rate.
Segmentation
Segmentation
Segmentation divides memory into variable-size logical segments corresponding to program structure: code segment, data segment, stack segment, heap.
vs Paging
Paging: fixed size, transparent to programmer, eliminates external fragmentation. Segmentation: variable size, matches logical program structure, programmer/compiler aware.
Combined
Modern systems often use segmented paging: logical address space divided into segments, each segment then paged. Combines benefits of both.
Segmentation can cause external fragmentation (gaps between variable-size segments). Paging eliminates this but causes internal fragmentation (wasted space within a page).
Exam Practice
OCR H446 Style · 5 marks
Explain what is meant by a page fault and describe the steps the OS takes to handle one. State one consequence of excessive page faults occurring.
[5 marks]
1
A page fault occurs when a process accesses a virtual page that is not currently loaded in physical RAM (the valid bit in the page table entry is 0).
1
The CPU generates an interrupt; the OS is invoked (page fault handler).
1
OS locates the required page in secondary storage (swap space/disk).
1
OS loads the page into a free frame in RAM and updates the page table entry (sets valid bit, stores frame number).
1
Consequence: thrashing — if page faults are excessive, the CPU spends all its time swapping pages rather than executing instructions, causing severe performance degradation.
Common Mistakes
Don’t Lose Marks
!
Saying a page fault means the program crashed — a page fault is handled by the OS and the program continues. It’s a normal (though slow) event, not an error per se.
!
Confusing paging and segmentation: paging uses fixed sizes (frames = pages), segmentation uses variable sizes (logical code/data/stack). Pages are invisible to the programmer; segments are not.
!
Saying thrashing occurs because “the disk is full” — thrashing is caused by insufficient RAM, causing constant page swapping. The disk being full is a separate issue.