IB COMPUTER SCIENCE | A1.1.4 Types of Primary Memory

Lesson objective

Explain the purposes of RAM, ROM, registers and L1, L2 and L3 cache, how they support CPU performance, and the meaning of cache hits and misses.

Learn

A1.1.4 | TYPES OF PRIMARY MEMORY

01 | WHY A COMPUTER USES MORE THAN ONE KIND OF MEMORY

Imagine opening a program and calculating a running total. Its saved file may begin on an SSD. The active instructions and data are made available in main memory. Copies of useful information may be held in cache, while registers hold the addresses, instructions and working values needed immediately by the processor.

These locations are not interchangeable. A register is fast but tiny. Main RAM can hold much more, but accessing it normally takes longer. Non-volatile firmware memory has a different purpose: keeping essential code available when power has been switched off.

Primary memory supports the CPU’s immediate operation. For this IB objective, study RAM, ROM, cache at L1, L2 and L3, and registers. Explain why each is used and how the combination supports processing.

The important question is not simply “which is fastest?” Ask what the information is needed for, how quickly it must be accessed, how much must be held and whether it must survive loss of power.

02 | SEE THE WORKING MEMORY HIERARCHY

A TYPICAL WORKING-DATA HIERARCHY
REGISTERSCurrent instruction, addresses and working values inside the CPU.
L1 CACHEVery small, very fast cache close to a core’s execution resources.
L2 CACHEA larger cache level, typically slower to access than L1.
L3 CACHEA further cache level, often larger and shared by several cores.
MAIN RAMMuch larger working space for active instructions and data.

Moving down this typical hierarchy: capacity generally increases, while access latency increases. Exact sizes, timings and sharing arrangements depend on the processor.

The diagram is a conceptual hierarchy, not a statement that every value must physically pass through every level in a fixed sequence. Cache organisation varies, and a processor can access different registers, instructions and data for different reasons.

ROM is shown separately because its distinctive role is retaining firmware, not acting as the next larger cache. Secondary storage such as an SSD is also separate from the CPU’s immediate working-memory hierarchy.

03 | RAM: SPACE FOR ACTIVE PROGRAMS AND DATA

Random-access memory, or RAM, provides read-and-write working storage. In the usual desktop or laptop context, main RAM holds active program instructions and data needed while the computer runs. Random access means locations can be accessed by their addresses without reading through every preceding location.

When you open a document, its contents can be read from secondary storage into working memory. As you edit, the active data changes in RAM. Saving writes the required changes to non-volatile storage; holding a document in RAM is not the same as saving it.

Main RAM is normally volatile: it loses its contents when power is removed. This is why a power failure can lose unsaved work. The software and storage system determine exactly when a saved change has become durable.

More RAM can allow a larger active working set to be held without resorting as often to slower secondary-storage-backed paging. It does not automatically make the CPU’s arithmetic operations faster, and adding RAM beyond the workload’s needs may provide little benefit.

04 | DRAM AND SRAM: USEFUL TECHNOLOGY CONTEXT

Main RAM is commonly implemented using dynamic RAM (DRAM). It stores bits in cells that require periodic refresh to retain their values while powered. DRAM offers high storage density and a relatively low cost per bit, making it suitable for a large main memory.

CPU caches are commonly built using static RAM (SRAM). SRAM retains a bit while powered without the periodic refresh required by DRAM. It is fast but uses more area per bit, making large capacities comparatively costly.

Both are volatile. Static does not mean “permanent”, and dynamic does not mean “only changes when software edits it”. These names describe aspects of the memory technology, not whether a user file has been saved.

This context helps explain the hierarchy: a computer can provide a modest amount of fast SRAM cache alongside a much larger DRAM main memory. You do not need transistor-level circuit designs to explain the purpose of the memory types.

05 | ROM: CODE THAT MUST REMAIN WITHOUT POWER

Read-only memory, or ROM, is non-volatile memory used to retain instructions or data that should remain available when power is removed. A key application is firmware: software closely associated with operating hardware.

At start-up, a computer needs instructions before the normal operating system is running. Non-volatile firmware storage makes that initial code available. It can initialise hardware and help begin the process of loading the operating system from a suitable storage device.

Traditional ROM is not changed during normal operation. Many modern systems store updateable firmware in flash memory rather than permanently fixed mask ROM. Flash is non-volatile and can be reprogrammed using a controlled update process.

So avoid two extremes: ROM is not the general-purpose space where all running programs are edited, but the label does not mean all modern firmware can never be updated. Its important purpose here is persistent availability of essential code.

06 | REGISTERS: THE CPU’S IMMEDIATE WORKING VALUES

Registers are very small, fast storage locations inside the CPU. They hold information directly involved in the processor’s current work, rather than a whole application or a library of saved files.

From A1.1.1, the PC holds the next instruction address, IR holds the current instruction, MAR holds a memory-access address, MDR holds a transferred value and AC holds a working value or result in our teaching model.

If AC contains a running total of 12, that value is immediately available for suitable processor operations. A later store instruction can place it into a memory location. A value being in a register does not imply it is already saved in RAM or on an SSD.

Registers normally lose their state without power. They are part of the processor’s execution state. Their speed and small capacity support immediate processing, while RAM and cache provide different kinds of supporting storage.

07 | CACHE: KEEP USEFUL COPIES CLOSE TO PROCESSING

The CPU can often perform operations faster than main memory can supply new instructions or data. If every access had to wait for main RAM, memory delays could leave execution resources waiting. Cache helps reduce the average access time.

A CPU cache holds copies of selected instructions or data associated with memory addresses. When a requested item is already available in the relevant cache, the processor can obtain it there rather than going to a slower level.

An address identifies what is being requested. A cache hit is not simply finding the same number somewhere: the cache must hold a valid copy corresponding to the requested location. Real cache entries contain information that allows that match to be checked.

Cache is normally managed by hardware, rather than by the user choosing which document to put there. It is not the same as a browser cache on disk, and it is not an extra permanent storage area for saved work.

08 | WHY CACHE OFTEN WORKS: LOCALITY

Programs tend to reuse information in patterns. Temporal locality means a recently accessed item may be accessed again soon. For example, the instructions in a small loop are repeated. Keeping them near the CPU can avoid repeatedly obtaining them from a slower memory level.

Spatial locality means locations near a requested address may be accessed soon. Reading consecutive items in an array or neighbouring instruction bytes can make nearby information useful.

Real caches generally transfer blocks called cache lines, not just one isolated value. Bringing a block into cache can make nearby locations available before a later request needs them.

These are tendencies, not guarantees. A program with little reuse or a working set much larger than the cache can have many misses. Cache capacity, organisation, access patterns and replacement choices all affect the result.

09 | L1, L2 AND L3 HAVE DIFFERENT TRADE-OFFS

LevelTypical characteristicsPurpose
L1Smallest and fastest cache level, usually closely associated with a core; often split into instruction and data caches.Supply frequently needed instructions and data with very low access latency.
L2Typically larger than L1, with higher access latency. It may be private to a core or shared, depending on the processor.Retain more useful information when it is not found in L1.
L3Often larger again and shared among several cores; usually higher latency than the closer cache levels.Provide an additional opportunity to serve a request before accessing main memory.

This is a common arrangement, not a universal specification. Some processors have no L3, use other sharing arrangements or have further levels. For an IB explanation, describe the purpose of the levels without inventing fixed capacities for every CPU.

A larger cache can reduce some misses, but size alone does not determine the overall result. Access latency, the data that the workload reuses and the way the memory system is organised also matter.

10 | CACHE HIT AND CACHE MISS: NAME THE LEVEL

A cache hit occurs when the requested information is found as a valid copy in the cache being checked. A cache miss occurs when it is not found there, so another source must supply it.

An L1 miss does not necessarily mean a RAM access. The item may be found in L2 or L3. In a simplified hierarchy, the request proceeds through those opportunities before main memory supplies the value if all relevant cache levels miss.

After obtaining the information, the system can place a copy into cache so later requests may be served more quickly. If the cache is full, some existing entry may need to be replaced. Real fill and replacement policies differ between processors.

A miss is an ordinary processing event, not necessarily an error or a loss of data. Its performance cost comes from the extra work and waiting needed to obtain the requested information.

Request outcomeWhat it means
L1 hitThe requested information is already available at L1.
L1 miss, L2 hitL1 cannot supply it; L2 can.
L1 and L2 miss, L3 hitThe closer levels cannot supply it; L3 can.
Miss at all three levelsThis simplified example obtains the value from RAM.

11 | TRY THE CACHE LOOKUP MODEL

The model begins with address 10 or 11 in L1, 20 or 21 in L2, and 30 or 31 in L3. All addresses from 0 to 63 also have a fixed value in RAM. Enter an address and follow where the requested value is found.

For example, try 10, 20, 30 and 40. Then request 40 again. The first request for 40 must use RAM; the second can use the copy placed into L1. RAM’s value has not changed.

This model holds two single-address items in L1. On an L1 miss, it copies the requested item into L1 and replaces the oldest entry if needed. The supplied L2 and L3 contents stay fixed. Real caches normally use cache lines and more complex policies; this read-only model deliberately leaves those out.

The invented lookup costs are L1 = 1, L2 = 4, L3 = 12 and RAM = 80 time units. Costs add along the visited path: an L2 hit costs 1 + 4 = 5, while a RAM read costs 1 + 4 + 12 + 80 = 97. These are not measured processor timings.

L1 | TWO ITEMS

L2 | FIXED CONTENTS

20 → 67
21 → 70

L3 | FIXED CONTENTS

30 → 97
31 → 100

Cache entries show address → value. In this model, RAM[address] = 3 × address + 7. Reset restores the original entries and counters.

12 | HOW THE TYPES WORK TOGETHER

Follow a simple editing session. Start-up firmware remains in non-volatile memory while the machine is off. When the computer starts, that code helps initialise the system and begin loading the operating system.

When you open an application and document, the active instructions and data are made available in RAM. Hardware can retain copies of useful information in caches. Registers hold the immediate addresses, instructions and working values used during execution.

As you work, the memory system must preserve correct values as changes move between the processor, caches and RAM. A cache is not an unrelated second version that software may freely allow to become incorrect. Detailed write policies are beyond this introductory model.

Saving the document writes the required information to non-volatile secondary storage. If power is then removed, volatile RAM, cache and register state is lost, while saved files and non-volatile firmware remain.

NeedSuitable memory or storageWhy
Retain essential start-up code without powerROM or other non-volatile firmware memoryThe code must remain available before normal applications run.
Hold a large active program and documentMain RAMIt provides substantial read-and-write working space.
Reduce repeated waits for useful instructions and dataCPU cacheNearby copies can serve many accesses more quickly.
Hold the current instruction or immediate arithmetic resultRegistersTheir small, fast locations directly support execution.
Retain the user’s saved document after shutdownSecondary storage, such as an SSDThat is persistent file storage, not volatile working memory.

13 | EXPLAIN THE PURPOSE USING A REASON

For explain, connect a property to its benefit. “RAM stores data” is a start, but it does not explain why RAM is used for active programs. “RAM provides read-and-write working space, so the processor can access and update the instructions and data needed during operation” is more complete.

For cache, explain the relationship: “Because programs often reuse information, keeping valid copies in faster cache can reduce the average time spent obtaining instructions and data from main memory.”

For ROM, connect persistence to start-up: “Because the initial firmware must remain available after power loss, it is held in non-volatile memory rather than depending on the previous contents of RAM.”

For registers, connect speed and role: “Registers hold the processor’s immediate addresses and working values, enabling the CPU to coordinate and perform current operations without treating all those values as whole programs in main memory.”

14 | COMMON CONFUSIONS TO CHECK

ConfusionCorrection
Static RAM retains data after power loss.SRAM is volatile; static refers to its storage mechanism while powered.
ROM and RAM differ only in capacity.They have different normal write behaviour and retention purposes.
Cache is a replacement for all RAM.It is smaller supporting storage for selected useful copies.
An L1 miss always means a RAM read.A lower cache level may provide a hit.
A cache miss means the data is corrupted.It normally means the requested valid copy is absent at that level.
L3 is always slower than RAM.A common purpose of L3 is to serve requests faster than accessing main RAM, though timings vary.
Saving a file means leaving it in RAM.Saving requires persistent storage; volatile working state is not enough.
More memory always makes every program faster.The benefit depends on what limits the workload.

Use the Questions tab to test the differences, then explain one complete example from start-up code to a saved document. The next lesson applies the CPU registers and memory interactions to the fetch, decode and execute cycle.

Further reading: Cornell’s cache and locality notes · Arm’s memory hierarchy guide

MATCH THE MEMORY TERM TO ITS MEANING

Terminology

Terminology

Primary memory

Memory supporting the CPU’s immediate operation, including the types studied in this objective.

RAM

Read-and-write working memory; main RAM normally holds active programs and data.

ROM

Non-volatile memory used to retain code or data that is not normally changed during operation.

Volatile

Losing stored contents when power is removed.

Non-volatile

Retaining stored contents without power.

Firmware

Software closely associated with operating hardware.

DRAM

Dynamic RAM, commonly used for main memory and requiring periodic refresh while powered.

SRAM

Static RAM, commonly used for cache and retaining bits while powered without DRAM-style refresh.

Register

A small, fast storage location inside the processor for immediate processing state.

Cache

Storage retaining selected valid copies of instructions or data to reduce access delays.

L1 cache

A small, fast cache level closely associated with a core.

L2 cache

A further cache level, typically larger and slower to access than L1.

L3 cache

An additional cache level, often larger and shared among cores.

Cache hit

Finding the requested information as a valid copy in the cache level being checked.

Cache miss

Not finding the requested information in the cache level being checked.

Temporal locality

The tendency for recently accessed information to be accessed again soon.

Spatial locality

The tendency for nearby memory locations to be accessed around the same time.

Cache line

A block of information transferred and managed as a cache unit.

Replacement

Choosing an entry to remove when cache space is required.

Memory address

An identifier selecting a memory location, distinct from its contents.

Capacity

The amount of information a memory can hold.

Latency

The delay involved in completing an access or operation.

Memory hierarchy

An arrangement of storage levels balancing properties such as capacity and access speed.

Working set

The instructions and data actively needed by a workload over an interval.

Flash memory

Reprogrammable non-volatile memory used for purposes including firmware and storage.

Secondary storage

Persistent storage for files and programs, such as an SSD. It is distinct from the working memory studied here.

Questions

Questions

CHECK YOUR UNDERSTANDING

Select all correct choices. Each exact set earns one point.

1. Why is main RAM used for active programs and data?
2. Which statements about ROM and firmware are correct?
3. Which pairings are accurate?
4. Which memory is most directly suited to holding the current instruction in the CPU?
5. L1 misses, but L2 contains a valid copy of the requested item. What follows?
6. Which illustrate locality?
7. Which are typical cache-level relationships?
8. What does a cache miss normally mean?
9. Which states normally disappear when power is removed?
10. Why might a second request be faster after a first RAM read?

EXPLAIN AND COMPARE

Write your answers before revealing each sample.

1. Explain why RAM is used for active programs and data.

2. Explain why start-up firmware needs non-volatile memory.

3. Explain how registers and RAM have different purposes.

4. Explain why a computer uses cache as well as main RAM.

5. Explain the typical purposes of L1, L2 and L3.

6. Explain the difference between an L1 miss and a miss throughout the cache hierarchy.

7. Explain temporal and spatial locality with examples.

8. Explain why SRAM is not permanent storage despite its name.

9. Explain why adding RAM does not guarantee faster arithmetic.

10. Explain why a computed document change may still be lost in a power failure.

APPLY IT | AN UNSAVED ROBOTICS PROGRAM

A student opens a saved robotics program, edits it and calculates a new motor target. Before saving, the power fails. Explain the roles of non-volatile firmware, RAM, cache and registers during this work, and distinguish the lost working state from the previously saved file on secondary storage.

Flashcards

Flashcards

Click to flip. Select the ideas you need to revisit.

0 cards selected for revision.

    Selections are kept while this page is open.

    Workbook

    Workbook

    COMING SOON

    The workbook for A1.1.4 Types of Primary Memory is coming soon. Complete the matching task and written questions in your exercise book.