Memory Management Basics and Hierarchy: Address Translation Worked Example

Build the memory hierarchy from CPU registers to storage, then follow a 16-bit logical address through a page table to its exact physical address.

KnowledgeGate Team

Exam prep & CS education

Updated 1 Dec 20265 min read
Memory Management Basics and Hierarchy: Address Translation Worked Example

A laptop has registers, caches, RAM, storage, and virtual addresses, but they are not interchangeable names for memory. Confusion starts when a question asks for page bits, an offset, or a physical address. The hierarchy runs from the CPU outward, while the operating system creates mappings and the MMU translates logical addresses into physical addresses. These ideas sit across CS Fundamentals for Exams & Placements, where computer architecture supplies the hardware hierarchy and operating systems supplies address mapping.

What memory management is solving

Memory management connects three actors. A process issues logical, or virtual, addresses. The memory-management unit (MMU) translates each permitted address, while physical memory holds instructions and data.

The operating system creates and manages mappings. Hardware performs each permitted translation using the active mapping data, making translation fast without giving a process unrestricted access to RAM.

It must also track free and occupied memory, allocate and reclaim regions, relocate addresses, enforce protection, allow controlled sharing, and decide what remains resident when RAM is limited. Together, these decisions give every process usable memory without exposing all physical memory.

Processes P1 and P2 may both issue logical address 0x1000. Separate mappings can send the references to different physical locations, while permissions keep either process out of the other's memory. A process address is not automatically a raw RAM address.

The memory hierarchy and why it works

From nearest to farthest from the CPU, the hardware levels are registers, processor caches, main memory, and secondary storage. Closer generally means lower latency, lower capacity, and higher cost per bit. Farther away generally reverses those trends.

The hierarchy works because programs show locality. Temporal locality means recently used data is likely to be reused, as when a loop updates the same counter or array block. Spatial locality means nearby data is likely to be used soon. Reading A[0], A[1], A[2], and A[3] demonstrates it.

Locality keeps a small active working set near the CPU instead of building every byte from the fastest technology. TLB behaviour, multilevel tables, and effective-access-time calculations follow in Memory Hierarchy and Virtual Memory: paging, the TLB, and address translation. Hierarchy-order questions need the four hardware levels and both locality types.

Virtual memory is an address-space abstraction and management mechanism, not another storage chip below secondary storage. Needed parts can be mapped into RAM, while other parts are backed by secondary storage when required.

Memory-hierarchy pyramid showing CPU registers, processor caches, main memory, and secondary storage, with a locality trace from A[0] through A[3] returning to A[0].

Logical addresses, physical addresses, pages, and frames

An address space is the set of addresses a process can generate. Paging divides it into equal-sized pages and RAM into equal-sized frames. A page table records each page-to-frame mapping. The offset selects a byte inside the page and remains unchanged during translation.

Under contiguous allocation, a process occupies one continuous physical region, and relocation can use a base address. Under paging, logical pages may occupy non-adjacent frames. Equal size does not make page and frame numbers interchangeable.

A segment is a variable-sized logical unit such as code, data, or a stack, while a page has fixed size. Segmentation bounds, TLB timing, and multilevel page-table structure are treated in Memory management in OS: paging and segmentation explained. A single-level page table is enough to isolate the invariant used in this calculation: translation replaces the page number with a frame number and preserves the offset. Paging removes external fragmentation, but a partly used final page can still create internal fragmentation.

Worked example: translate logical address 13,845

Assume a byte-addressable system with 16-bit logical addresses and 1 KiB pages. Since 1 KiB = 1,024 bytes = 2^10 bytes, the offset needs 10 bits. The page number gets 16 - 10 = 6 bits, giving 2^6 = 64 logical pages.

Translate logical address 13,845. In hexadecimal it is 0x3615. Its 16-bit binary form, split into page and offset fields, is 001101 | 1000010101.

  1. Compute the page number: floor(13,845 / 1,024) = 13.

  2. Compute the offset: 13,845 - (13 x 1,024) = 13,845 - 13,312 = 533.

  3. Check the bit fields: binary 001101 is decimal 13, and binary 1000010101 is decimal 533.

  4. Read the page table: page 13 has a valid entry that maps to frame 42.

  5. Form the physical address: (42 x 1,024) + 533 = 43,008 + 533 = 43,541.

The result is decimal 43,541, or hexadecimal 0xAA15. Check it with 43,541 mod 1,024 = 533. If page 13 were absent or lacked permission, hardware would trap to the operating system instead of forming the address.

Address-translation pipeline showing logical address 13,845 split into page 13 and offset 533, mapped to frame 42 and physical address 43,541.

Traps that turn easy memory questions into wrong answers

Tempting move

Correction

Reason

Treat 1 KiB as 1,000 bytes

Use 1,024 bytes

1 KiB = 2^10 bytes

Use all 16 bits as offset bits

Use 10 offset bits

Page size sets the offset

Change the offset during translation

Preserve offset 533

Translation replaces the page field with a frame field

Treat page 13 and frame 42 alike

Keep their roles separate

Pages are logical; frames are physical

Read frame 42 as byte address 42

Start at 42 x 1,024 = 43,008

A frame number identifies a block

A cache miss is not automatically a page fault, and virtual memory is not identical to secondary storage. Equal page and frame sizes do not make their numbers equal. Paging can still leave internal fragmentation.

The worked values give a fast check. Page 13 with offset 533 must retain offset 533. Any physical answer whose remainder after division by 1,024 is not 533 is wrong. Page-table-size and effective-memory-access-time numericals use different calculations.

How exams and interviews test basics and hierarchy

Stable question forms ask you to order hierarchy levels, identify each kind of locality, distinguish logical from physical addresses, derive page and offset bits, or translate through a supplied page-table entry.

Try three checks. A[0], A[1], A[2], A[3] shows spatial locality through consecutive locations. A 1 KiB page needs 10 offset bits because 1,024 = 2^10. Page 13 mapped to frame 42 keeps offset 533. Using 1,000 bytes or swapping page and frame produces a wrong result.

Interview follow-ups ask why two processes can safely use the same logical address, why locality makes a hierarchy effective, and what happens after an invalid page-table entry. Strong answers connect mapping, protection, and locality instead of treating them as separate definitions.

The short version and next step

The hierarchy balances latency, capacity, and cost. Locality makes that balance useful by keeping active data nearer the CPU. The operating system manages protected mappings between logical pages and physical frames. The MMU uses those mappings to translate each permitted address.

The decisive result is 13,845 = page 13 + offset 533; page 13 maps to frame 42, so the physical address is 43,541.

Redraw the hierarchy and translation pipeline from memory, then repeat the calculation after changing only the mapping from frame 42 to frame 27. You should obtain (27 x 1,024) + 533 = 27,648 + 533 = 28,181, with offset 533 unchanged.

For a structured route through Operating Systems and the broader CS sequence, continue with the Zero to Hero Complete CS Course.