How does a memory access travel from CPU to DRAM?
When a user-space process accesses memory, the CPU generates a virtual address, which is translated into a physical address by the MMU. The CPU then checks the cache hierarchy before accessing DRAM.
1. Complete memory access flow
2. Step-by-step explanation
Step 1: User process generates a memory request
int a = 10;
int *ptr = &a;
int x = *ptr;
Assuming the compiler generates an actual load instruction, the CPU executes it to read memory.
For ARM64:
LDR W0, [X1]
Here, X1 contains the virtual address.
Step 2: MMU checks the TLB
The Memory Management Unit (MMU) checks the Translation Lookaside Buffer (TLB).
- TLB hit: Physical page address is obtained directly.
- TLB miss: Hardware performs a page table walk on modern ARM64 and x86 processors.
The TLB caches address translations, not actual application data.
Step 3: Page table walk
For a typical Linux ARM64 system using four-level page tables:
PGD → PUD → PMD → PTE
The MMU uses the page table base register (TTBR0_EL1 on ARM64 for user-space addresses) to locate the page tables.
The page table entry contains information such as the physical page frame, access permissions and memory attributes.
Step 4: Virtual-to-physical address translation
For a 4 KB page:
Virtual address: 0x12345678
Physical address: 0xABCDE678
The page number changes, but the page offset remains the same.
Step 5: Page fault handling (if required)
If the page is not mapped or access permissions are violated, the CPU generates a synchronous exception.
The Linux kernel page fault handler may allocate a physical page, load data from a file or swap, update the page table and retry the instruction.
If the access is invalid and cannot be resolved, Linux typically sends SIGSEGV to the process.
Step 6: CPU checks the cache hierarchy
Once the address translation and permission checks are resolved, the CPU obtains data through the cache hierarchy.
| Memory level | Approximate latency |
|---|---|
| L1 cache | 1 ns |
| L2 cache | 3–5 ns |
| L3 cache | 10–30 ns |
| DRAM | 60–120 ns |
These are illustrative values and vary by processor.
If data is available in a cache, DRAM access is unnecessary. Data may also be obtained from another CPU core's cache through the cache-coherency mechanism.
Step 7: SoC interconnect and memory controller
If the cache hierarchy cannot supply the data, the request travels through the system interconnect to the memory controller.
On ARM-based SoCs, this may involve an AXI or coherent interconnect.
The memory controller translates the system physical address into DRAM-specific addressing:
- Channel
- Rank
- Bank
- Row
- Column
Step 8: DRAM access
The memory controller issues DDR commands:
| Command | Purpose |
|---|---|
ACTIVATE |
Opens a row into the row buffer |
READ |
Reads the requested column data |
WRITE |
Writes data into the selected location |
PRECHARGE |
Closes the active row |
If the required row is already open, the controller can avoid another activation.
Step 9: Data returns to CPU
The requested data returns through the memory controller and interconnect. It typically fills the appropriate caches as a cache line (commonly 64 bytes), and the requested value is delivered to the CPU register.
The instruction completes.
3. What happens during a memory write?
For a typical write-back, write-allocate cache:
*ptr = 20;
CPU → Store Buffer → L1 Cache
↓
Dirty cache line
↓
Eventual write-back
↓
Memory Controller
↓
DRAM
A CPU write does not necessarily update DRAM immediately.
4. Important interview follow-up questions
| Question | Answer |
|---|---|
| Does every memory access enter kernel mode? | No, only when an exception or another kernel entry is required. |
| Does every TLB miss cause a page fault? | No, a valid page table entry can resolve it. |
| Does every cache miss access DRAM? | No, another cache level or core may supply data. |
| Where are page tables stored? | Physical memory; their entries can also be cached. |
| Who configures page tables? | The OS kernel. |
| Who translates virtual addresses? | MMU hardware. |
| Who manages DDR timing? | Memory controller. |
Does volatile bypass CPU cache? |
No. |
Interview-ready answer: A user-space memory access generates a virtual address. The MMU translates it using the TLB or a page table walk and verifies access permissions. The CPU checks its cache hierarchy. If the data cannot be supplied by caches, the request travels through the system interconnect to the memory controller, which issues DDR commands to retrieve data from DRAM. The data returns to the CPU, completing the instruction.