Computer ScienceExam code: 0984

Memory and Storage

Hardware

Virtual memory is an area on secondary storage that the operating system uses as an extension of when RAM is full.

Imagine a computer running so many programs that physical RAM fills up. Without some way to free RAM, the system would have to refuse to launch any new program. Virtual memory solves this by temporarily moving inactive data and instructions out of RAM and onto , freeing space in RAM for whatever is currently active.

How it works

The operating system breaks RAM and virtual memory into fixed-size chunks called pages.

  1. RAM becomes full while several programs are running.
  2. The OS picks pages that have not been used recently (e.g. a video editor that the user has minimised).
  3. Those pages are copied out of RAM onto secondary storage, into the virtual-memory area.
  4. The space they used to occupy in RAM is now free for new active data.
  5. If the user goes back to the minimised program, its pages are copied back from into RAM (and, if necessary, some other inactive pages are sent out to make room).
Diagram showing pages of data being transferred between RAM and the virtual-memory area on secondary storage
Source: What is Virtual Memory by Save My Exams

Effects on performance

Virtual memory lets the computer keep working when RAM is full, but it has a cost:

  • Secondary storage is much slower than RAM. Whenever the CPU needs a page that is currently in virtual memory rather than RAM, the system has to fetch it from disk first. This causes a noticeable pause.
  • Moving pages back and forth uses CPU time and adds disk wear.
  • If the OS spends more time shuffling pages than running programs, the system is said to be thrashing, and performance collapses.

The fix is straightforward: add more physical RAM so the system rarely needs to fall back on virtual memory.

Common misconception: virtual memory does NOT add to the physical capacity of RAM. It simply borrows space on secondary storage as a slow stand-in, used only when the real RAM is exhausted.

Common exam question

Explaining how virtual memory is used

Question: State the purpose of virtual memory, explain how it is used when RAM is full and another page is needed, or complete a description of it from a list of terms (1–5 marks).

Asked in 3 of the 17 papers. The one-mark purpose takes either credited idea: programs can run when there is not enough RAM, or RAM can hold more data when required. For the four-mark explanation, give the scheme's sequence: secondary storage is partitioned to create the virtual memory; the page not needed now is sent to it; that frees space in RAM for the new page; once a page in RAM has been processed, the stored page is sent back to RAM when needed. Write in pages throughout. The fill-in-the-gaps version is one mark per term, and every gap is one of RAM, hard disk drive, pages and virtual memory; the other terms offered (binary, hexadecimal, ROM, tracks, sectors, software, operating system) are distractors.

Quick check

4 short questions on this note. See what has stuck, and where to look if something hasn't.

About 2 minutes

Build on this topic