How Computers Work

Follow how a CPU runs instructions, how caches and DRAM serve data, and how modern interconnects, I/O, and NUMA affect performance.

published: reading time: 10 min read author: Geek Workbench
Quick Summary

Follow how a CPU runs instructions, how caches and DRAM serve data, and how modern interconnects, I/O, and NUMA affect performance.

How Computers Work: CPU, Memory, Interconnects, and I/O

Introduction

A line such as total += prices[i] needs several parts of a computer. A CPU core fetches and decodes the instruction, reads the value, adds it to a register, and eventually writes the result. If the value is not in a nearby cache, the core waits while the memory system finds it.

That path is a useful starting point for understanding performance. The same machine also translates virtual addresses, coordinates data shared between cores, and moves device traffic through several kinds of interconnects. The exact layout differs by processor and platform, so this article uses a simplified model and calls out where the details change.

A processor runs instructions

A program is a sequence of machine instructions. The program counter identifies the next instruction to execute. The core fetches instruction bytes, decodes them into operations, and uses registers and execution units to carry them out.

The familiar fetch-decode-execute cycle is a teaching model. Modern CPUs overlap these stages, predict branches, and may execute operations out of order when dependencies allow. They still preserve the architectural result the program expects.

Registers hold values that instructions are using directly. Caches hold copies of recently used instructions and data so the core can often avoid waiting for DRAM. The number, size, sharing, and latency of those caches depend on the processor. There is no single cache layout that describes every computer.

The memory hierarchy

A core may find a value in a register, a cache, DRAM, or persistent storage. The closer a storage level is to the core, the smaller it tends to be and the less time it usually takes to access. The levels also serve different purposes:

Level What it holds What to remember
Registers Operands and results used by instructions The compiler and CPU allocate them within the rules of the instruction set.
CPU caches Copies of instructions and data A cache hit avoids a request to a slower level. Cache levels and policies vary by processor.
DRAM Working data for running programs The memory controller schedules reads, writes, and refreshes.
SSD or other storage Files and data kept across restarts Storage is not a direct substitute for RAM; the operating system must move data into memory before a CPU can use it.

Caches work because programs often reuse recently accessed values or nearby addresses. A cache line is the unit moved between cache levels and memory; its size is architecture-specific. If one core changes a line that another core has cached, the hardware’s coherence system coordinates the copies. The protocols and interconnects vary, but software must see a consistent result under the architecture’s memory model.

An instruction that misses cache

Consider a CPU instruction that loads an array element. The instruction itself may already be in the instruction cache; the data load takes a separate path. This trace shows one possible route. A miss in one cache does not mean the request immediately reaches DRAM.

1. Fetch instruction bytes from the instruction cache (or a lower level).
2. Decode the instruction and issue its data load.
3. Look for the requested cache line in the core's L1 data cache.
      hit  -> return the line to the core
      miss -> check the next cache/coherence level
4. If another cache or coherent peer has the line, transfer it to the requester.
5. If the relevant cache levels miss, send a request over the platform interconnect.
6. The memory controller selects the channel and DRAM location.
      NUMA system: the page may be local or attached to another node
7. DRAM returns the cache line; the memory system supplies it to the core.
8. The dependent instruction can continue once its value is available.

The ordering and names in the trace are illustrative. Some processors use different cache topologies or lookup strategies. Intel’s optimization manual describes a specific processor family and notes that memory latency changes with controller queues, DRAM configuration, timings, and row state. Use measurements for the actual processor instead of treating a cycle count as universal. Intel’s CPU metrics reference distinguishes cache hits, cache misses, and requests served by local or remote DRAM.

From a shared bus to modern interconnects

A basic computer diagram often shows a shared system bus carrying data, addresses, and control signals between the CPU, memory, and devices. That model helps explain how an address selects a target and why components need a way to coordinate transfers. It also describes older systems and some small embedded designs.

Most modern computers do not use one shared bus for every transfer. A processor package may contain multiple cores, private caches, a shared cache, memory controllers, and on-chip links or fabrics. Separate point-to-point links connect some components. PCI Express uses a switched topology for devices such as network cards, storage controllers, and GPUs. Server systems can also link processor sockets over cache-coherent interconnects.

These links do not eliminate contention. Cores may compete for cache or memory bandwidth; devices may share a switch or root port; and requests may queue at a memory controller. The path depends on the platform. In a multi-socket or multi-node machine, some memory is farther from a CPU than other memory.

DRAM, data rates, and refresh

DRAM stores each bit as charge in a small cell. The charge leaks, so the memory system periodically refreshes rows. The memory controller schedules these operations; software normally does not issue a refresh for each read.

Refresh timing depends on the DRAM device, temperature range, density, and refresh mode. As one scoped example, Micron’s DDR5 white paper gives a 16Gb device timing for normal all-bank refresh: a refresh command is issued at an average interval of 3.9 microseconds and occupies the device for 295 nanoseconds. Fine-granularity and same-bank modes use different timings. This example does not establish a fixed percentage of lost bandwidth for all DRAM systems. See Micron’s DDR5 refresh discussion.

Memory data rate is measured in transfers per second, or MT/s. It is not the same as the memory clock in MHz, and it does not directly state the sustained bandwidth of a whole machine. Micron lists DDR5 component rates from 4,800 to 8,800 MT/s on its DDR5 product page. For a nominal 64-bit data channel, those rates correspond to an ideal arithmetic ceiling of about 38.4 to 70.4 GB/s before command overhead and other limits. Actual throughput depends on the CPU, memory controller, number of channels, DIMMs, access pattern, and competing traffic.

Virtual addresses and page tables

Programs use virtual addresses. The memory management unit (MMU) translates them to physical addresses, usually by consulting a translation lookaside buffer (TLB) that caches recent translations. On a TLB miss, hardware walks the page tables using a format defined by the processor architecture and current paging mode.

A page fault means the requested virtual mapping needs operating-system attention. It does not always mean a disk read: the OS may resolve a minor fault using memory already present. A major fault can require data from storage and take much longer. The number of page-table levels and the time for a walk depend on the architecture, page size, and whether the translation is cached.

I/O and DMA

Devices communicate through interfaces such as PCI Express, USB, or a system-on-chip fabric. A device may use direct memory access (DMA) to transfer a block of data to or from RAM while the CPU works on other instructions. The CPU still sets up the operation and handles completion or errors, often through an interrupt. DMA traffic uses the memory system too, so a device can compete with CPU cores for bandwidth.

An IOMMU can restrict which memory regions a device may access and translate device-visible addresses. Drivers must follow the operating system’s mapping APIs and device-specific ordering rules. A device register is not ordinary RAM; reading or writing it may trigger hardware behavior.

NUMA and memory locality

Non-uniform memory access (NUMA) systems have multiple groups of CPUs and memory. In cache-coherent NUMA (ccNUMA), memory is visible across the system and hardware maintains cache coherence, but access time and effective bandwidth depend on distance. A CPU can reach memory attached to another node, though remote access generally costs more than access to local memory.

The Linux kernel’s NUMA documentation describes how Linux maps hardware cells to NUMA nodes and normally tries to allocate memory near the CPU that requests it. This can change if a thread moves after allocation or if local memory is exhausted. Tools such as numactl can show node topology and control placement, but pinning threads or memory without measurements can make performance worse.

For a NUMA-sensitive workload, measure first. Compare throughput and tail latency with the same workload, inspect local versus remote memory traffic where the platform exposes counters, and check whether threads and their data stay near each other. Intel’s VTune memory metrics include metrics for cache misses serviced by local or remote DRAM on supported processors.

Cache-line contention

A common multicore problem is false sharing. Two threads update different variables, but those variables occupy the same cache line. The coherence system must move ownership of the line between cores even though the threads never read or write the same variable.

Padding or grouping data by writer can help, but it increases memory use and can make other access patterns worse. First measure the workload and confirm that cache-line transfers are the bottleneck. The line size and performance counters depend on the processor.

Common pitfalls

  • Treating a cache miss as an automatic DRAM access. A lower cache or another coherent cache may supply the line.
  • Quoting one cache size, latency, or hit rate as true for all CPUs. Check the processor documentation or measure the workload.
  • Calling MT/s a memory clock speed or equating peak channel bandwidth with application throughput.
  • Assigning a universal bandwidth penalty to DRAM refresh. Refresh timing and overlap depend on the device and memory-controller mode.
  • Drawing one system bus between every component in a modern PC or server. The real route depends on caches, controllers, switches, and platform links.
  • Assuming point-to-point links cannot contend. Their endpoints, switches, and downstream memory can still be shared.
  • Assuming every page fault reads from disk. Some faults are resolved from memory.

Quick recap

  • The fetch-decode-execute cycle is a useful model; real CPUs overlap work and may execute independent instructions out of order.
  • Caches reduce average access time, but cache layouts and timing vary across processors.
  • DRAM refresh is required, though its schedule and cost are device- and mode-specific.
  • Interconnects connect cores, memory, and devices through different topologies; there is no universal system bus.
  • NUMA locality and cache-line sharing can affect performance, so measure the platform and workload before tuning.

Further reading

Conclusion

When a program pauses for data, the delay may come from its instruction path, a cache miss, DRAM, a remote NUMA node, or device traffic. Following the request through those layers is more useful than assuming every computer has the same bus or cache timings. For the platform at hand, processor documentation and measurements tell you which part of the path matters.

Category

Related Posts

ASLR & Stack Protection

Explore ASLR, PIE, stack canaries, and NX on Linux with GCC, then inspect a harmless C program to see what each mitigation does and where it falls short.

#operating-systems #aslr-stack-protection #computer-science

Assembly Language Basics: Writing Code the CPU Understands

Learn x86-64 Linux assembly with the System V ABI: track registers, assemble and run a small program, debug it in GDB, then compare AArch64.

#operating-systems #assembly-language-basics #computer-science

Boolean Logic & Gates

Understanding AND, OR, NOT gates and how they combine into arithmetic logic units — the building blocks of every processor.

#operating-systems #boolean-logic-gates #computer-science