Study Guide

Virtual Memory

CIE A-Level Computer ScienceΒ· Unit 5: System SoftwareΒ· 45 min read

1. Purpose and Overview of Virtual Memoryβ˜…β˜…β˜†β˜†β˜†β± 10 min

When multiple programs run simultaneously, the total size of all program data often exceeds the available capacity of physical RAM. Virtual memory solves this problem by moving inactive program data from RAM to a dedicated area of secondary storage called swap space (or paging file), freeing up RAM for active processes.

πŸ“˜ Definition

Virtual Memory

A memory management technique that creates an illusion of a larger contiguous address space than is physically available in RAM, using secondary storage to extend main memory capacity.

Example:

A 4GB RAM system can run a 6GB game by storing 2GB of inactive game data in virtual memory on a solid state drive.

πŸ“ Worked Example

A computer has 2GB of physical RAM. Five open programs require a total of 3.5GB of combined memory. Explain how virtual memory allows all five programs to stay open.

  1. 1
    1. The operating system identifies which portions of the programs are currently inactive (e.g., a minimized word processor not used for 10 minutes).
  2. 2
    1. The inactive portions are copied from RAM to the swap space on secondary storage, freeing ~1.5GB of physical RAM for active use.
  3. 3
    1. When the user switches back to the inactive program, its data is swapped back into RAM, and any new inactive data is swapped out to virtual memory.

Exam tip:

Always note that virtual memory is slower than physical RAM, because secondary storage has much higher access latency than RAM.

2. Paging and Address Translationβ˜…β˜…β˜…β˜†β˜†β± 15 min

Virtual memory is most commonly implemented using paging, where the virtual address space is split into fixed-size blocks called pages, and physical RAM is split into equally sized blocks called page frames. The Memory Management Unit (MMU) handles automatic translation between virtual addresses and physical addresses.

πŸ“˜ Definition

Page Table

A data structure stored in main memory that maps each virtual page number to the corresponding physical page frame address, or marks the page as stored in virtual memory on disk.

πŸ“ Worked Example

A system uses 1KB pages. A process has a virtual address of 0x0254, which maps to virtual page 2. The page table lists the physical page frame for page 2 as 0x0A. Calculate the corresponding physical address.

  1. 1
    1. Find the offset within the page: page size is 1KB = 1024 = 0x400 bytes, so the offset is the virtual address modulo page size:
  2. 2
    Offset=0x0254mod  0x400=0x254\text{Offset} = 0x0254 \mod 0x400 = 0x254
  3. 3
    1. Calculate the starting address of the physical page frame:
  4. 4
    Physical Start=0x0AΓ—0x400=0x2800\text{Physical Start} = 0x0A \times 0x400 = 0x2800
  5. 5
    1. Add the offset to get the full physical address:
  6. 6
    Physical Address=0x2800+0x254=0x2A54\text{Physical Address} = 0x2800 + 0x254 = 0x2A54

3. Page Faults and Thrashingβ˜…β˜…β˜…β˜†β˜†β± 12 min

A page fault occurs when a process tries to access a page that is not currently loaded into physical RAM. When this happens, the operating system pauses the process, loads the required page from swap space into a free page frame in RAM, updates the page table, and resumes the process. If no free page frames exist, the OS evicts the least recently used (LRU) page to swap space.

πŸ“˜ Definition

Thrashing

A severe performance degradation state where the system spends most of its time swapping pages between RAM and virtual memory, instead of executing application instructions.

Example:

Thrashing occurs when there are too many active processes competing for too little physical RAM.

πŸ“ Worked Example

A user opens 15 large browser tabs on a laptop with only 4GB of RAM. The system becomes extremely slow even when only one tab is active. Explain why this happens using the term thrashing.

  1. 1
    1. The total size of all 15 tabs exceeds the 4GB available physical RAM, so most tab data is stored in virtual memory on disk.
  2. 2
    1. When the user switches between tabs, each switch requires the new tab's page to be swapped into RAM, and an old page to be swapped out to disk.
  3. 3
    1. The system spends most of its processing time handling page faults and swapping, rather than running the active tab. This state of excessive swapping is called thrashing, which causes the severe slowdown.

Exam tip:

CIE examiners always expect you to link thrashing to insufficient physical RAM and a high page fault rate. Mention both to get full marks.

4. Advantages and Disadvantagesβ˜…β˜…β˜†β˜†β˜†β± 8 min

  • Advantages:

  • Allows larger programs to run on systems with limited physical RAM

  • Allows more processes to be loaded and open at the same time

  • Frees up physical RAM for active processes by moving inactive data to disk

  • Provides memory protection between processes, as each has its own virtual address space

  • Disadvantages:

  • Virtual memory access is much slower than physical RAM access

  • Requires extra processing overhead for address translation and page fault handling

  • Uses secondary storage space for swap, reducing available user storage

  • Can lead to thrashing if RAM is insufficient for the current workload

βœ“ Quick check

Test your understanding:

  1. Which of the following correctly describes virtual memory?

    • A: It adds extra physical RAM to the system via the hard disk

    • B: It uses secondary storage to extend the available logical memory space

    • C: It is cache memory between the CPU and main RAM

    • D: It permanently stores the operating system kernel

    Reveal answer
    B β€”

    A is incorrect: virtual memory does not add physical RAM. C is incorrect: cache is separate from virtual memory. D is incorrect: the kernel is stored in persistent storage, not virtual memory.

5. Common Pitfalls

Wrong move:

Claiming virtual memory increases the amount of physical RAM available

Why:

Virtual memory does not change the physical RAM capacity of the system, it only uses secondary storage as an extension

Correct move:

State that virtual memory increases the logical address space available to processes, allowing larger or more programs to run than physical RAM alone can support

Wrong move:

Confusing a page fault with a system error or crash

Why:

Page faults are a normal, expected part of virtual memory operation, not errors

Correct move:

Recognize that page faults trigger the OS to load the requested page from swap into RAM, and the process resumes normally after resolution

Wrong move:

Claiming thrashing is caused by too much swap space allocated on disk

Why:

Thrashing is caused by insufficient physical RAM to hold all active pages of running processes

Correct move:

Link thrashing to high page fault rates caused by insufficient physical RAM for the current workload

Wrong move:

Changing the offset when calculating physical addresses from virtual addresses

Why:

Only the page number is mapped to a new physical frame; the offset identifies the exact byte within the page and does not change

Correct move:

Always retain the original offset from the virtual address and add it to the starting address of the physical page frame

Wrong move:

Claiming virtual memory is only used when RAM is completely full

Why:

Operating systems use virtual memory even when RAM is not full, to provide memory protection and larger address spaces

Correct move:

State that the primary use is extending memory when RAM is insufficient, but it also provides process protection and larger address space benefits

6. Quick Reference Cheatsheet

Term

Key Definition

Virtual Memory

Secondary storage extension of main memory

Page

Fixed-size block of virtual address space

Page Frame

Fixed-size block of physical RAM

Page Table

Maps virtual page to physical frame

Page Fault

Requested page not in RAM, triggers swap

Thrashing

Excessive swapping reduces system performance

Swap Space

Secondary storage area for virtual memory

When this came up on past exams

AI-estimated based on syllabus patterns β€” cross-check with official past papers for accuracy. Use only as revision-focus signals.

  • 2022 Β· 12

    Explain purpose of virtual memory

  • 2023 Β· 11

    Describe causes of thrashing

  • 2024 Β· 12

    Compare RAM and virtual memory

Going deeper

What's Next

Virtual memory is a core memory management concept heavily tested in CIE A-Level Computer Science Paper 1, so mastering its key terms, processes, and common pitfalls is critical for exam success. It builds on your understanding of main memory organization and operating system functions, and connects to broader topics like process scheduling, memory protection, and secondary storage design. Beyond this sub-topic, you will encounter virtual memory concepts again when learning about operating system security, multi-tasking, and system performance optimization. Building a solid understanding of this topic will help you answer both short and extended response questions in your exam.