SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
CAIE 9618 · Paper 1 · Topic 1.3.6

Virtual Memory

Paging · Page Faults · Swapping · Thrashing · Benefits & Limitations

CSZone Cambridge International AS & A Level Computer Science 9618
What is Virtual Memory?

Using Secondary Storage as RAM

Virtual memory is a memory management technique that uses a portion of secondary storage (HDD or SSD) to simulate additional RAM. It allows the OS to run programs that require more memory than is physically available in RAM.
HOW IT WORKS
Memory is divided into fixed-size chunks called pages. Active pages are in RAM. Inactive pages are stored in the page file (swap file) on disk. OS moves pages between RAM and disk as needed.
BENEFITS
Allows large programs to run when RAM is limited. Enables more programs to run simultaneously. Provides memory isolation between processes. Allows for larger address spaces.
Paging

Fixed-Size Memory Blocks

Paging divides both virtual memory and physical RAM into equal-sized blocks. Virtual memory blocks are called pages; RAM blocks are called frames. A page table maps virtual page addresses to physical frame addresses.
1
Program references a virtual memory address
2
OS checks page table — is this page in RAM? If yes → access it (page hit)
3
If not in RAM → page fault — OS must load page from disk
4
If RAM full, OS evicts least recently used (LRU) page back to disk, loads needed page into freed frame
5
Page table updated; program continues — program is unaware this happened
Thrashing

When Virtual Memory Goes Wrong

Thrashing occurs when the OS spends more time swapping pages between RAM and disk than executing actual program instructions. The system becomes extremely slow and appears to "freeze."
CAUSES
Too many programs running simultaneously. Not enough physical RAM for working sets. Programs need pages that keep being swapped out.
SOLUTIONS
Install more physical RAM. Close unnecessary programs. Use working set model (keep all pages a process currently needs in RAM).
Exam Practice

Cambridge-style questions

Question 1
Explain what is meant by a page fault and describe what happens when one occurs.
4 marks
1 mark
A page fault occurs when the CPU requests a memory page that is not currently loaded in physical RAM
1 mark
The OS pauses the process and identifies which page is needed using the page table
1 mark
If RAM is full, the OS evicts a page (e.g. using LRU algorithm) and swaps it out to the page file on disk
1 mark
The required page is loaded from disk into RAM, the page table is updated, and the process resumes
Common Mistakes

Don't lose easy marks

1
Saying virtual memory is the page file — virtual memory is the concept (using disk as extra RAM). The page file/swap file is the specific file on disk used to store inactive pages. They are not the same thing.
2
Saying thrashing means the computer has crashed — thrashing means the system is extremely slow due to excessive page swapping, but the computer is still running (just barely). It's a performance problem, not a crash.
3
Confusing pages and frames — pages are the fixed-size blocks in virtual memory; frames are the fixed-size blocks in physical RAM. They are the same size, but the terms are different.
Topic Summary — 1.3.6

What You Need to Know

VIRTUAL MEMORY
Uses secondary storage as extra RAM
Allows programs larger than physical RAM to run
OS manages pages between RAM and disk
Page table maps virtual → physical addresses
PAGING
Pages (virtual) + Frames (physical RAM)
Page fault: page not in RAM → load from disk
LRU: evict least recently used page
Page table tracks which pages are in RAM
THRASHING
Too many page faults → constant swapping
CPU spends more time swapping than processing
System slows to a near-halt
Fix: add more RAM, close programs
LIMITATIONS
Much slower than real RAM (disk I/O)
Page faults cause significant delay
SSD page file is faster than HDD
Virtual memory is not a replacement for RAM
CSZone

Next Video

1.4.1
Assembly Language Programming
Loops · Branching · Subroutines · Stack
Head to CSZone.co.uk for the complete worksheet, quiz, and interactive tools