Memory System Organisation

A computer’s memory system holds instructions and data for the CPU. It uses several kinds of storage because no single type is simultaneously very fast, large and inexpensive.

The memory hierarchy

Memory is arranged in levels. Moving down the hierarchy, storage usually becomes larger and cheaper per byte, but slower for the CPU to access.

Level

Typical role

Speed and size

CPU registers

Values the CPU is using right now

Fastest; smallest

Cache

Frequently or recently used instructions and data

Very fast; small

RAM

Programs and data currently in use

Larger; slower than cache

Secondary storage

Files and programs kept long term

Largest; slower than RAM

The CPU checks faster levels first. If the required data is not there, it may need to retrieve it from a slower level.

Cache memory

A cache is small, fast memory close to or inside the CPU. It keeps copies of data or instructions the CPU may need soon.

Processors commonly use levels such as:

  • L1: smallest and fastest, usually close to each CPU core.

  • L2: larger than L1, but typically slower.

  • L3: often larger and shared across cores, but slower than L1 and L2.

A cache hit means the needed data is in the cache. A cache miss means it must be fetched from another level, which takes longer.

Caches work well because programs often show:

  • Temporal locality: recently used data is likely to be used again.

  • Spatial locality: data near recently used data is likely to be used soon.

RAM and virtual memory

RAM holds the parts of programs and data currently in use. It is volatile, so its contents are lost when power is removed.

An operating system gives each process a virtual address space. The process uses virtual addresses, which hardware and the OS translate to physical RAM addresses. This helps isolate processes and lets each process work with a simpler view of memory.

When RAM is under pressure, the OS may move less-used memory contents to storage, such as a page file or swap area. This is called paging or swapping, depending on the context. Storage is much slower than RAM, so frequent paging can make a computer feel slow.

Memory protection

Memory-management hardware helps prevent one process from reading or changing another process’s memory without permission. The OS sets up the rules, and the processor checks memory accesses.

If a process accesses an invalid or unauthorised address, the processor may raise an exception, which the OS handles.

Key distinctions

  • Cache is not the same as RAM: cache is smaller and faster, and managed largely by hardware.

  • RAM is not the same as storage: RAM is working memory and volatile; storage retains files without power.

  • Virtual memory is not extra physical RAM: it is an OS and hardware memory-management approach that uses address translation and may use storage when needed.

Why this matters for security

Memory organisation supports process isolation, but vulnerabilities can still arise from bugs in software or hardware. For example, a program that writes outside its allocated memory may corrupt data or create a security weakness.

Key terms to remember

Memory hierarchy · cache · cache hit · cache miss · locality · RAM · virtual address · physical address · paging · swap · memory protection

Check your understanding

  1. Put registers, cache, RAM and secondary storage in order from fastest to slowest.

  2. What is the difference between a cache hit and a cache miss?

  3. Why can heavy paging slow a system down?

  4. What is the difference between a virtual address and a physical address?

  5. Why does the OS use memory protection?

Answers:

  1. Registers → cache → RAM → secondary storage.

  2. A hit finds the data in cache; a miss requires fetching it from a slower level.

  3. Storage is much slower than RAM, so moving data between them repeatedly takes time.

  4. A virtual address is used by a process; a physical address identifies a location in RAM after translation.

  5. To restrict unauthorised access between processes and protect system memory.