KS4J277 1.2.1 28 min read 10 question quiz 18 exam marks

Primary Storage: RAM, ROM and Virtual Memory

Why the computer needs memory at all, the real difference between RAM and ROM, and what virtual memory is actually doing when your machine slows to a crawl.

Why primary memory exists

The CPU can only fetch instructions and data from primary memory. It cannot read directly from a hard disk or an SSD.

So when you open a program, the operating system copies it from secondary storage into RAM, and the CPU works from there.

Why not just run it from the hard drive? Because secondary storage is thousands of times slower. If the CPU had to wait for a disk on every instruction, a 3 GHz processor would perform like a machine from the 1970s.

The definition to memorise

Primary storage is memory that the CPU can access directly. It holds the data and instructions that are currently in use.

The memory hierarchy

Speed and cost pull in opposite directions, which produces a hierarchy:

LevelSpeedCapacityCost per byteVolatile
RegistersFastestA few bytesHighestYes
CacheVery fastKB to MBVery highYes
RAMFastGBModerateYes
Secondary storageSlowGB to TBLowNo

The pattern is consistent: the closer to the CPU, the faster, the smaller and the more expensive.

The memory hierarchyA four level pyramid. Registers sit at the top holding a few bytes and are the fastest and most expensive storage. Below them cache holds kilobytes to megabytes and is very fast. Below that RAM holds gigabytes, is fast and is volatile. At the base secondary storage holds gigabytes to terabytes, is slow and is non volatile. Moving up the pyramid storage gets faster, smaller and more expensive per byte. Moving down it gets larger and cheaper.Registersa few bytesfastest, most expensiveCacheKB to MBvery fastRAMGBfast, volatileSecondary storageGB to TBslow, non volatilefasterbigger and cheaper
The pattern is consistent: the closer to the processor, the faster, the smaller and the more expensive per byte.
The memory hierarchy: small and fast at the top, huge and slow at the bottomThe memory hierarchy drawn as a pyramid of four tiers, narrow at the top and wide at the bottom. Registers sit inside the processor itself, hold a few hundred bytes and are the fastest storage in the machine. Cache sits on the processor chip, holds a few megabytes and answers in nanoseconds, which is why a cache hit saves so much time. Main memory, the RAM, holds eight to thirty two gigabytes, is fast but volatile, so everything in it is lost when the power goes off. Secondary storage, an SSD or a hard disk, holds terabytes and keeps your files permanently, but is far slower. Every step down is bigger, slower and cheaper per byte. If one kind of memory were fast, huge and cheap there would only be one kind.Registersinside the CPU · a few hundred bytesfastest of allL1Cacheon the CPU chip · a few megabytesnanosecondsMain memoryRAM · 8 to 32 gigabytesfast, but volatileCTRLSecondary storageSSD or hard disk · terabytesslow, but permanentsmaller, faster, dearerbigger, slower, cheaper per byte12345
  1. Registers: inside the CPU, a few hundred bytes, fastest of all.
  2. Cache: still on the chip, a few megabytes, and very fast.
  3. Main memory: gigabytes, fast, and it empties when the power goes.
  4. Secondary storage: terabytes, slow, and it keeps your files forever.
  5. The whole point: small and fast at the top, huge and slow at the bottom.
Every level down is bigger, slower and cheaper per byte. If one kind of memory were fast, huge and cheap, there would only be one kind.

RAM

RAM, random access memory, is the computer's main memory.

  • It holds the operating system, the applications currently running and the data those applications are using.
  • It is volatile: its contents are lost the moment power is removed.
  • It can be read from and written to.
  • It is much faster than secondary storage but slower than cache.
Volatile means power, not speed

Volatile does not mean unstable or unreliable. It means the contents disappear when the power goes. This is why unsaved work is lost in a power cut.

What happens when RAM fills up

RAM is finite. Open enough programs and it runs out. The computer does not simply stop, it starts using virtual memory, and that is when things get slow.

Two memory sticks with the notch in a different placeA stick of DDR memory: a long green circuit board with eight black memory chips in a row and a gold edge connector with a notch off centre.DDR4DDR5notchnotch, somewhere elseso it will not fit the wrong slotmemory chipsgold contacts
The notch is in a different place on each generation of memory, so a DDR4 stick physically will not fit a DDR5 slot.Drawn illustration

ROM

ROM, read only memory, holds instructions that must be available the instant the machine is switched on.

  • It is non volatile: contents are kept when the power is off.
  • It is read only in normal use, so the contents cannot be accidentally overwritten.
  • It is small, typically a few megabytes at most.
  • It contains the bootstrap or BIOS: the start up instructions.

The boot process

  1. The computer is switched on.
  2. The CPU fetches the boot program from ROM, because RAM is empty at this point.
  3. The boot program checks the hardware is working, a power on self test.
  4. It then locates the operating system on secondary storage and copies it into RAM.
  5. Control is handed to the operating system, which is now running from RAM.
The classic question

"Explain why a computer needs both RAM and ROM." The answer hinges on volatility. RAM is volatile, so at switch on it is empty and cannot hold the start up instructions. ROM is non volatile, so it still holds the boot program. ROM alone is not enough because it cannot be written to, and running programs constantly need to write data.

RAMROM
Full nameRandom access memoryRead only memory
VolatileYesNo
Read and writeBothRead only in normal use
Typical size8 GB to 32 GBA few MB
ContentsOperating system, open programs, data in useBoot program, BIOS
SpeedFastFast
A flash memory chip soldered to a boardA small rectangular flash memory chip soldered to a motherboard, holding the firmware the computer runs before the operating system loads.FLASH64Mfirmwarepin 1 dotmarks the first leglegssoldered to the boardflash memory chipkeeps its contents
This chip holds the firmware. It keeps its contents with the power off, which is what makes it read only memory rather than RAM.Drawn illustration

Virtual memory

Virtual memory is a section of secondary storage used as if it were RAM, when RAM is full.

How it works

  1. RAM becomes full but another program needs to be loaded.
  2. The operating system identifies data in RAM that has not been used recently.
  3. That data is moved out to a dedicated area of secondary storage, called the swap file or page file.
  4. The freed RAM is used for the new program.
  5. If the moved out data is needed again, it is swapped back into RAM, which may require moving something else out.

Why it makes the computer slow

Secondary storage is far slower than RAM. Every swap means writing data out and reading data in. If the machine is very short on RAM this can happen constantly, a condition called disk thrashing, where the computer spends more time moving data than doing useful work.

The trade off in one sentence

Virtual memory lets a computer run more programs than its RAM can physically hold, at the cost of a large drop in speed, because secondary storage is much slower than RAM.

The fix

Adding more RAM. With enough RAM, virtual memory is rarely needed, so the swapping stops.

Virtual memory: pages moved between RAM and diskVirtual memory, drawn as pages moving between two levels. RAM holds the parts of the running programs that are needed now: it is fast, volatile and small. The disk below is slow, permanent and enormous. When another program is started and there is no space left in RAM, the operating system picks a page that has not been used recently and writes it out to a reserved area of the disk, which is the swap space or page file. That frees real memory so the new program can start. If the page that was swapped out is needed again, it has to be fetched back from the disk, which is thousands of times slower than RAM, and that is why a computer that is short of memory and swapping constantly feels so slow.RAM: fast, and smallDisk: slow, and hugeA1A2B1B2C1C2A3C3not used latelyswap space (the page file)B4A7C3Program Dopening nowno room left!needed againdisk is slowso the computerfeels sluggish12345
  1. RAM holds the programs that are running. It is fast, and it is small.
  2. Open one program too many and there is no room left.
  3. A page that has not been used lately is written out to the disk.
  4. That frees real memory, so the new program can start.
  5. Needed again, the page is fetched back, which is why it goes slow.
Virtual memory does not make a machine faster. It lets it run more than will fit, and pays for that in disk time.

Key terms you must be able to define

Primary storage
Memory the CPU can access directly, holding data and instructions currently in use.
RAM
Random access memory. Volatile main memory holding the operating system, running programs and data in use.
ROM
Read only memory. Non volatile memory holding the boot program the computer needs at switch on.
Volatile
Loses its contents when power is removed.
Non volatile
Keeps its contents when power is removed.
Virtual memory
An area of secondary storage used as extra RAM when RAM is full.
Swap file
The area of secondary storage where data moved out of RAM is held.
Bootstrap
The small start up program held in ROM that loads the operating system into RAM.
Disk thrashing
Excessive swapping between RAM and virtual memory, which makes a computer extremely slow.

Flashcards

Say the definition out loud before you flip the card. Retrieving it from memory is what builds recall, reading it again is not.

DefinePrimary storage
AnswerMemory the CPU can access directly, holding data and instructions currently in use.
DefineRAM
AnswerRandom access memory. Volatile main memory holding the operating system, running programs and data in use.
DefineROM
AnswerRead only memory. Non volatile memory holding the boot program the computer needs at switch on.
DefineVolatile
AnswerLoses its contents when power is removed.
DefineNon volatile
AnswerKeeps its contents when power is removed.
DefineVirtual memory
AnswerAn area of secondary storage used as extra RAM when RAM is full.
DefineSwap file
AnswerThe area of secondary storage where data moved out of RAM is held.
DefineBootstrap
AnswerThe small start up program held in ROM that loads the operating system into RAM.

Reach the top grade on this topic

The high marks on this topic come from causal chains. A grade 9 answer explains virtual memory as a sequence of events with a consequence, not as a definition.

Weak: "Virtual memory is part of the hard drive used as RAM. It makes the computer slow."

Strong: "When RAM becomes full, the operating system moves data that has not been used recently out to the swap file on secondary storage, freeing RAM for the new program. Because secondary storage is far slower than RAM, every subsequent access to that data requires it to be swapped back in, and if this happens continuously the computer spends most of its time transferring data rather than executing instructions."

Notice the second version names the trigger, the mechanism, the location and the consequence.

  • Be able to explain why ROM is needed given that RAM exists, using volatility
  • Be able to describe the boot sequence in four steps
  • Be able to explain the cause of slowdown when virtual memory is heavily used
  • Be able to recommend adding RAM and justify why it solves the problem

Mistakes that cost marks here

Avoid these
  • Saying ROM is 'where the operating system is stored'. The OS lives in secondary storage and is copied into RAM at boot. ROM holds only the small boot program.
  • Describing volatile as 'temporary' without mentioning power. The examiner wants the link to power being removed.
  • Saying virtual memory 'adds more RAM'. It does not. It uses slower secondary storage as a substitute for RAM.
  • Claiming ROM can never be changed. It can be reflashed during a firmware update, it just is not written to during normal operation.
  • Confusing cache with RAM. Cache is inside or beside the CPU and is much smaller and faster than RAM.
Fun fact

The word RAM stands for random access memory, and the random part means any location can be read in the same amount of time. Old magnetic tape was the opposite: to reach the end you had to wind through everything before it.

Knowledge check

0 of 10 answered
1Which statement about RAM is correct?
2Why does a computer need ROM as well as RAM?
3What happens immediately after the boot program in ROM completes its hardware checks?
4Virtual memory is best described as:
5Why does heavy use of virtual memory slow a computer down?
6A user complains that their computer becomes very slow when many applications are open. What is the most effective upgrade?
7Which of these is non volatile?
8Where must a program be before the CPU can execute it?
9Which is the correct ordering from fastest to slowest?
10Disk thrashing occurs when:
Score 0 / 10

Exam-style questions

Five written questions in the style of the real paper. Write a full answer, then let the marker check it against the mark scheme.

18 marks
1State two differences between RAM and ROM.2 marks
State

Mark scheme0 / 2
  • LRAM is volatile while ROM is non volatile
  • LRAM can be read from and written to, ROM is read only in normal use
Model answer

RAM is volatile, meaning its contents are lost when the power is switched off, whereas ROM is non volatile and keeps its contents. RAM can also be both read from and written to during normal operation, while ROM is read only in normal use.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
2Explain the purpose of ROM in a computer system.3 marks
Explain

Mark scheme0 / 3
  • LHolds the boot program or BIOS
  • LIt is non volatile so the instructions are still present when the computer is switched on
  • LThe boot program checks hardware and loads the operating system from secondary storage into RAM
Model answer

ROM holds the bootstrap program, sometimes called the BIOS, which is the set of instructions the computer runs the moment it is switched on. ROM is used because it is non volatile, so unlike RAM its contents survive the computer being powered down and the instructions are guaranteed to be present at start up. The boot program checks that the hardware is working, then locates the operating system in secondary storage and copies it into RAM so that the CPU can run it.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
3Explain what virtual memory is and describe how it is used when a computer runs out of RAM.4 marks
Explain

Mark scheme0 / 4
  • LVirtual memory is an area of secondary storage used as if it were RAM
  • LUsed when RAM is full and more space is needed
  • LData not being used recently is moved from RAM out to the swap file
  • LIt is swapped back into RAM when needed again
Model answer

Virtual memory is an area of secondary storage, such as a region of the hard disk or SSD known as the swap file, that the operating system uses as though it were additional RAM. It is used when RAM becomes full but another program or piece of data needs to be loaded. The operating system identifies data in RAM that has not been accessed recently and moves it out to the swap file, freeing physical RAM for the new data. If the data that was moved out is needed again later, it is swapped back into RAM, which may require moving something else out to make room.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
4A laptop with 4 GB of RAM becomes very slow when the user has several applications open at once. Explain why this happens and recommend a solution.6 marks
Explain

Mark scheme0 / 6
  • L4 GB of RAM fills up when several applications are open
  • LThe operating system starts using virtual memory on secondary storage
  • LData is repeatedly swapped between RAM and secondary storage
  • LSecondary storage is far slower to access than RAM
  • LThe CPU spends time waiting rather than executing instructions, which the user experiences as slowdown
  • LRecommends installing more RAM, so fewer programs need to be swapped out
Model answer

With only 4 GB of RAM, opening several applications at once quickly fills the available physical memory. Once RAM is full the operating system falls back on virtual memory, which is an area of the laptop's secondary storage used as if it were RAM. Data belonging to programs that have not been used recently is written out to the swap file, and when the user switches back to those programs that data has to be read back into RAM again, usually forcing something else out. Because secondary storage is thousands of times slower to access than RAM, each of these swaps takes a substantial amount of time, and the CPU sits waiting for data instead of executing instructions. When it happens continuously it is known as disk thrashing, and the user experiences it as severe slowdown. The most effective solution is to install more RAM, for example upgrading to 16 GB, because all the open applications can then be held in physical memory at once and swapping is largely eliminated. Replacing a mechanical hard disk with an SSD would reduce the penalty of each swap, but it treats the symptom rather than the cause.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
5Describe the role of primary storage in a computer system.3 marks
Describe

Mark scheme0 / 3
  • LPrimary storage is directly accessible by the CPU
  • LIt holds the data and instructions currently in use
  • LPrograms are copied from secondary storage into primary storage before they can be executed
Model answer

Primary storage is the memory that the CPU is able to access directly, and it holds the data and instructions that are currently being used, including the operating system and any programs the user has open. The CPU cannot execute a program directly from secondary storage, so when a program is opened it is first copied from secondary storage into primary storage, and the CPU then fetches its instructions from there during the fetch decode execute cycle.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
Machine mark 0 / 18