Computer ScienceFoundation18 min read

Data Storage and Virtual Memory

Three technologies, and the trick that lets a machine run more than it can hold

This topic appears in:

01

Primary and secondary storage

Primary storage is directly accessible by the processor. RAM is volatile — its contents vanish when the power goes — and holds whatever is currently running. ROM is non-volatile and holds the start-up instructions the machine needs before it can load anything else.

Secondary storage is not directly accessible by the processor; data must be copied into RAM first. It is non-volatile, far larger and far slower, and it is where everything lives when the machine is off.

RAMROMSecondary
Volatile?yesnono
Can be written to?yesnot normallyyes
Sizegigabytessmallhundreds of gigabytes upward
Speedfastfastslow
Holdsprograms currently runningboot instructionsall files permanently

ROM does not hold the operating system

It holds the small program that starts the machine and knows how to find the operating system on the disk. The operating system itself is far too large for ROM and is loaded into RAM during booting. Answers claiming the OS lives in ROM are a standing error.

02

The three secondary storage technologies

Each stores data by a completely different physical mechanism, and the mechanism explains every one of its characteristics.

Magnetic storage — a hard disk — magnetises tiny regions on spinning platters, read by a head that moves across them. The moving parts make it slower and vulnerable to being dropped, but it is cheap per gigabyte and available in very large capacities.

Optical storage — CD, DVD, Blu-ray — burns pits into a reflective surface, read by the way a laser reflects off pits and flat areas. It is cheap, portable and long-lasting, but slow and small by modern standards.

Solid state storage — SSDs and flash drives — traps charge in transistors with no moving parts at all. Fast, silent and shock-resistant, but dearer per gigabyte, and each cell tolerates only a limited number of writes before it wears out.

Worked example

A film crew needs storage for footage shot on location, and separately for a video archive kept at the office. Recommend a technology for each.

  1. On location: solid state.It has no moving parts, so it survives being carried, dropped and vibrated in a vehicle.
  2. It is also fast, which matters when writing high-bitrate video in real time.A magnetic disk might not keep up and would risk dropped frames.
  3. For the archive: magnetic hard disks.Capacity per rupee is what matters for an archive, and the drives sit still in a rack.
  4. The speed disadvantage is irrelevant for material accessed occasionally, and the cost saving over SSDs at that capacity is large.Matching the technology to the actual demand is the whole question.

Solid state on location for durability and speed; magnetic at the office for capacity and cost.

03

Virtual memory

A machine may be asked to run more programs than its RAM can hold. Rather than refusing, the operating system uses virtual memory: a region of secondary storage treated as though it were extra RAM.

Pages of memory not currently being used are written out to disk, freeing real RAM for what is active. When a page is needed again it is read back, and something else is written out to make room. That exchange is called paging or swapping.

It works, and it is slow. Disk access is thousands of times slower than RAM, so a machine paging heavily becomes dramatically sluggish — the familiar symptom of a slow computer with a constantly busy disk light. The cure is more RAM, which removes the need to page at all, rather than a faster disk, which only shortens each delay.

Why virtual memory is worth having anyway

Without it, opening one program too many would simply fail. With it, the machine slows down but keeps working, and the user can close something. Graceful degradation under pressure is nearly always preferable to an outright refusal, which is why every modern operating system does this.

Before you leave this chapter

  1. RAM is volatile and holds what is running; ROM is non-volatile and holds boot instructions.
  2. ROM does not hold the operating system — that is loaded into RAM at boot.
  3. Magnetic: cheap and large, but moving parts. Optical: portable but slow and small. Solid state: fast and durable but dearer with limited writes.
  4. Virtual memory uses secondary storage as extra RAM, moving pages in and out.
  5. Heavy paging means a slow machine with a busy disk. More RAM removes the cause.
04

Choosing storage for a purpose

Questions in this topic describe a use and ask which storage suits it. Four considerations settle almost every case, and naming which one dominates is what turns a recommendation into a justified one.

  • Capacity — how much must be stored? Archives favour magnetic disks, which are far cheaper per gigabyte at large sizes.
  • Speed — how quickly must it be read or written? Solid state is dramatically faster, which matters for an operating system or live video.
  • Portability and durability — will it be carried? Solid state and optical survive handling; a hard disk does not enjoy being dropped.
  • Cost — per gigabyte, magnetic is cheapest, then optical, then solid state.
PurposeBest choiceDeciding factor
Operating system drivesolid statespeed
Large video archivemagneticcapacity per rupee
Carrying files between sitessolid state or opticalportability and durability
Distributing software to customersopticalcheap to duplicate in quantity
Recording video on locationsolid stateno moving parts to fail

Say which factor decided it

A recommendation without a reason earns half the marks. "Solid state, because there are no moving parts to fail when the equipment is being carried" is a complete answer; "solid state, because it is better" is not. Identify the factor that actually dominates in the situation described, and say so.

Practice questions

6 questions · 20 marks · full working on every one

Try each one on paper first, then open the working. The marks are shown where they are actually awarded, because that is where they are actually lost.

Short questions

3 · 6 marks

Two marks each, in the style of the short-question section of the paper. Answer in two or three lines.

SQ1[2 marks]
State two differences between RAM and ROM.
Model answer

RAM is volatile and loses its contents when the power is removed; ROM is non-volatile and retains them. RAM can be written to freely and holds the programs currently running; ROM is not normally written to and holds the start-up instructions.

Examiner tip. Volatility is the difference the mark scheme always wants. What each holds is the natural second point.

SQ2[2 marks]
Why is secondary storage needed as well as RAM?
Model answer

RAM is volatile, so everything in it is lost when the machine is switched off, and it is comparatively small and expensive. Secondary storage retains data permanently without power and provides far greater capacity at a much lower cost.

Examiner tip. Give both reasons — permanence and capacity. Either alone is usually one mark.

SQ3[2 marks]
Explain one advantage of solid-state storage over magnetic storage.
Model answer

It has no moving parts, so it accesses data much faster, uses less power, makes no noise and is far more resistant to damage from being dropped or vibrated.

Examiner tip. The absence of moving parts is the single fact that explains every one of those advantages, so lead with it.

Solved numericals

2 · 8 marks

Full working, one step per line, with the marks shown where they are awarded.

N1[4 marks]
Explain what virtual memory is and how it works.
Full working
  1. Virtual memory is an area of secondary storage used as though it were additional RAM[1]
  2. It is used when the programs being run need more memory than the physical RAM provides[1]
  3. Pages of memory not currently in use are written out to disk, freeing real RAM for active data[1]
  4. When a page is needed again it is read back and another is written out — a process called paging or swapping[1]

Disk space used as extra RAM, with unused pages swapped out and read back when needed.

Examiner tip. Say explicitly that it is on secondary storage. Describing it as "extra memory" without saying where it comes from misses the point.

N2[4 marks]
A computer becomes very slow when many applications are open, and its disk light stays on. Explain the cause and evaluate two possible remedies.
Full working
  1. RAM has filled, so the operating system is using virtual memory and paging to diskthe constant disk activity is the clue[1]
  2. Disk access is thousands of times slower than RAM, so every switch between programs now waits on the disk[1]
  3. Installing more RAM is the better remedy: it removes the need to page at all[1]
  4. Fitting a faster SSD helps but only shortens each swap — it reduces the symptom while leaving the cause in placethe distinction is the mark[1]

RAM is full and the OS is paging. More RAM removes the cause; a faster disk only shortens each delay.

Examiner tip. Distinguishing removing the cause from reducing the symptom is what turns a correct answer into a full-mark one.

Long questions

1 · 6 marks

Theory and numerical together, as they appear in the long-question section.

LQ1[6 marks]
A hospital is specifying storage for three purposes: the machine that runs monitoring software, an archive of patient scans, and copies of records to be carried between sites.
  1. Recommend a storage type for each, with a reason.
  2. Explain why the monitoring machine should have enough RAM to avoid virtual memory.
  3. Explain why ROM is still needed in each machine.
Mark scheme
  1. Monitoring machine: solid state, for speed and because it has no moving parts to fail[1]
  2. Archive: magnetic hard disks, for the very large capacity at low cost per gigabyte[1]
  3. Between sites: optical or solid state portable media, as it must be carried and survive handlingeither accepted with justification[1]
  4. If it began paging, the machine would slow unpredictably as it waited on disk access[1]
  5. In a monitoring system a delayed response could be dangerous, so the timing must stay predictable — which means never depending on virtual memorythe safety point is the mark[1]
  6. ROM holds the start-up instructions that run before any disk is read, so the machine can find and load the operating system — without it nothing could boot at all[1]

(a) SSD, magnetic archive, portable media (b) paging would make response times unpredictable, which is unsafe here (c) ROM boots the machine before any disk is available

Examiner tip. Part (b) links storage back to real-time systems: it is not that paging is slow, but that it makes the delay unpredictable, and a monitoring system cannot tolerate that.