💻 Paper 1 · 1.3 Processor Fundamentals
1.3.6 Virtual Memory and Memory Management
Cambridge 9618 · International A Level Computer Science · ~13 min read
Notes
Video
Slides
Quiz
Worksheet

What is Virtual Memory?

Virtual memory is a memory management technique that allows the operating system to use part of secondary storage (HDD or SSD) as an extension of main RAM. This creates the illusion that the computer has more RAM than it physically does.

Programs are given virtual addresses — an address space that is independent of the physical RAM installed. The OS maps virtual addresses to actual physical memory locations.

How Virtual Memory Works — Paging

The most common implementation of virtual memory uses paging:

  • Both virtual memory and physical RAM are divided into fixed-size blocks called pages (virtual) and frames (physical RAM)
  • A page table maintained by the OS maps each virtual page number to its physical frame number in RAM
  • Pages that are not currently needed can be swapped out to a reserved area of secondary storage called the swap file (Windows) or swap space (Linux)
  • Only the pages currently in use need to be in RAM at any time
Main RAM
Page 0 ✓ loaded
Page 2 ✓ loaded
Page 5 ✓ loaded
Pages in RAM
Swap File (Disk)
Page 1 — swapped
Page 3 — swapped
Page 4 — swapped
Pages on disk

Page Fault

A page fault occurs when the CPU tries to access a page that is not currently loaded into RAM:

  • The OS pauses the program and locates the required page in the swap file on disk
  • If RAM is full, the OS must choose a page to swap out (evict) using a page replacement algorithm (e.g. LRU — Least Recently Used)
  • The required page is loaded into the freed frame
  • The page table is updated
  • The program resumes

Page faults are expensive — accessing secondary storage is much slower than accessing RAM. Frequent page faults slow down a system significantly.

Thrashing

Thrashing occurs when the system spends more time swapping pages in and out of memory than actually executing programs. It happens when:

  • RAM is severely insufficient for the number of processes running
  • Too many page faults occur simultaneously
  • The system constantly swaps pages in and out without making useful progress

Symptoms: computer becomes very slow, disk activity LED is constantly active. Solutions: add more RAM, reduce the number of running processes, use faster secondary storage (SSD).

The Page Table

The page table is a data structure stored in RAM (and managed by the OS) that maps virtual page numbers to physical frame numbers. Each entry also stores:

  • Present/absent bit — whether the page is currently in RAM (1) or on disk (0)
  • Modified/dirty bit — whether the page has been changed since it was loaded (determines if it must be written back to disk when evicted)
  • Referenced bit — whether the page has been recently accessed (used by replacement algorithms)

Translation Lookaside Buffer (TLB)

Every memory access requires a page table lookup (virtual address → physical address), which would be slow if it required a RAM access itself. The TLB is a small, fast cache that stores recent virtual-to-physical address translations:

  • TLB hit — translation found in TLB → fast address translation
  • TLB miss — translation not found → must access page table in RAM (slower)

Segmentation (Contrast with Paging)

Segmentation is an alternative approach where memory is divided into variable-size segments based on logical units of the program (code segment, data segment, stack segment). Unlike paging (fixed-size), segments have different sizes. Most modern systems use a combination of paging and segmentation.

OS Role in Memory Management

The operating system is responsible for:

  • Allocating RAM to processes when they start
  • Maintaining the page table for each process
  • Handling page faults (loading pages from disk)
  • Choosing which pages to evict using replacement algorithms
  • Protecting each process's memory space from other processes
  • Releasing memory when processes terminate
Exam tip: Cambridge 9618 questions on virtual memory often ask you to explain paging, page faults, and thrashing. For a page fault, always describe the sequence: CPU finds page not in RAM → OS locates page on disk → (if RAM full) OS evicts a page → required page loaded → page table updated → program resumes. For thrashing, explain why it degrades performance (more time swapping than executing).
⚠️ Common Mistakes
  • Saying virtual memory IS secondary storage — virtual memory is a technique that USES secondary storage as an extension of RAM; they're not the same thing
  • Saying a page fault means the program has crashed — a page fault is a normal OS event; the OS handles it by loading the missing page
  • Confusing pages and frames — a page is a block of virtual address space; a frame is a physical block of RAM of the same size
  • Saying thrashing is caused by a large RAM — thrashing occurs when RAM is too SMALL for the active processes; more RAM reduces thrashing
✅ Notes completed!
Video coming soon
Click slide or press arrow keys to navigate

Worksheet — 1.3.6 Virtual Memory

8 questions · instantly marked · Cambridge 9618 standard

Q1Explain what virtual memory is and why it is useful.[3]
✅ Mark scheme
Mark scheme
Virtual memory is a memory management technique that uses part of secondary storage (disk) as an extension of main RAM [1]; it creates the illusion that more RAM is available than is physically installed [1]; useful because it allows large programs to run even when there is insufficient physical RAM [1].
Q2Describe the role of the page table in virtual memory management.[4]
✅ Mark scheme
Mark scheme
The page table maps virtual page numbers to physical frame numbers in RAM [1]; it is maintained by the OS and stored in RAM [1]; each entry includes a present/absent bit indicating whether the page is currently in RAM or on disk [1]; it also records modified (dirty) and referenced bits used for page replacement decisions [1].
Q3Describe what happens when a page fault occurs.[5]
✅ Mark scheme
Mark scheme
The CPU tries to access a page not currently in RAM [1]; the OS is notified and the program is paused [1]; the OS locates the required page in the swap file on secondary storage [1]; if RAM is full, a page is chosen to be evicted (swapped out) using a replacement algorithm [1]; the required page is loaded from disk into RAM and the page table updated [1]; the program resumes from where it was interrupted [1]. Award max 5.
Q4Explain what thrashing is and describe two ways to reduce thrashing.[4]
✅ Mark scheme
Mark scheme
Thrashing: the OS spends more time swapping pages in and out of memory than executing programs — caused by insufficient RAM for active processes [1]; reduces effective CPU use and severely degrades performance [1]; solutions: install more RAM so fewer pages need to be swapped [1]; reduce the number of simultaneously running processes so each has more RAM available [1]. Also accept: use faster secondary storage (SSD reduces swap time).
Q5Explain the difference between paging and segmentation as approaches to memory management.[4]
✅ Mark scheme
Mark scheme
Paging: divides memory into fixed-size blocks (pages/frames) [1]; simplifies memory management; avoids external fragmentation [1]; Segmentation: divides memory into variable-size segments based on logical units of the program (code, data, stack) [1]; more natural division of programs but can lead to external fragmentation (holes of unusable space) [1].
Q6What is the Translation Lookaside Buffer (TLB) and how does it improve performance?[3]
✅ Mark scheme
Mark scheme
The TLB is a small fast cache that stores recent virtual-to-physical address translations from the page table [1]; on a TLB hit, address translation is done without accessing the page table in RAM [1]; this avoids a slow RAM access for every memory reference, significantly improving performance [1].
Q7Explain why using a hard disk drive (HDD) for the swap file instead of an SSD makes thrashing worse.[2]
✅ Mark scheme
Mark scheme
An HDD has much slower access times than an SSD due to mechanical moving parts [1]; when thrashing occurs and many page swaps are needed, HDD's slow speed means each page load takes much longer, worsening the performance degradation [1].
Q8State three responsibilities of the operating system in memory management.[3]
✅ Mark scheme
Mark scheme
Any three from: allocating RAM to processes [1]; maintaining the page table [1]; handling page faults [1]; selecting pages to evict (page replacement) [1]; protecting one process's memory from another [1]; releasing memory when processes terminate [1].
Topic Quiz
Question 1 of 15
You scored
out of 15
Card 1 of 10
Click to reveal definition
🎉
All cards reviewed!
TermDefinition
🎯

Mini Test — 1.3.6 Virtual Memory

10 questions · 10 marks · 10 minutes

← 1.3.5 Memory Types
23 of 82 · Cambridge 9618
1.4.1 Assembly Programming →
🔒
Pro lesson
Upgrade to CSZone Pro to access all Cambridge 9618 A Level lessons.
Upgrade to Pro →