Concepts and theorems · Intermediate

Virtual addresses: the addresses a process sees

Work through address translation, then separate process identity, protection, shared pages, TLB misses and page faults.

Ask Logeia about this articleTry the three questionsReview your answers

Updated

On this page
  1. An address belongs to an address space
  2. Calculate the page and offset
  3. A mapping is not permission for every operation
  4. Follow separate and shared mappings
  5. Separate a TLB miss from a page fault
  6. Mapping changes also need coordination
  7. Consider an access crossing a page boundary
  8. Ask Logeia about this articleCheck your understanding

An address belongs to an address space

A pointer value in an ordinary user process is normally interpreted within that process’s virtual address space. Two processes can both use the number 0x4000 without accessing the same physical storage. The address-space context is part of the meaning, much as a street number needs a city. This is a useful starting model, rather than a universal description of every execution environment. Kernels can maintain additional mappings, and virtualization can introduce another translation stage. Keep the first calculation to one user address space using paging. Once that calculation is clear, add the particular kernel or virtual-machine mechanism being investigated instead of silently treating every address as the same kind of number.

Calculate the page and offset

Assume an illustrative page size of 4 KiB, or 4096 bytes. Dividing virtual address 0x12345 by 4096 gives virtual page number 0x12 and remainder 0x345. If the page table maps page 0x12 to physical frame 0xAB, the frame starts at 0xAB000. Adding the unchanged byte offset gives physical address 0xAB345. Translation changes the page identifier, while retaining the position within the page. The assumption about page size is essential: a larger page changes how many low bits represent the offset. Do not use the twelve-bit rule simply because a diagram elsewhere used 4 KiB. First identify the actual mapping size and then perform the division or bit decomposition.

A mapping is not permission for every operation

Finding a physical frame does not authorize every access to it. Translation structures also carry protection information, such as whether a page is writable, executable, or accessible from user mode. A code page intended for reading and execution can therefore reject a write even while its contents are resident in RAM. Different mappings of the same frame can have different permissions, subject to the operating system and architecture. Trace three questions separately: which frame is selected, which operation was attempted, and which permission applies to that operation. This separation explains why a resident page can still fault. Removing protection to make the access succeed would change the security contract rather than repair an invalid pointer or operation.

Follow separate and shared mappings

Suppose processes A and B both use virtual page 0x12. If A maps it to frame 0xAB and B maps it to frame 0xCD, offset 0x345 reaches 0xAB345 in A and 0xCD345 in B. Mapping both pages to frame 0xAB instead permits shared contents. Read-only portions of shared libraries are one practical motivation. The virtual page numbers do not even need to match for two mappings to reach the same frame. Consequently, comparing printed pointer values is not a reliable test for shared storage. Determine the backing object, mapping mode and relevant permissions. Those facts explain both isolation and deliberate sharing without requiring either process to use physical addresses directly.

Separate a TLB miss from a page fault

A TLB caches translation information so that the processor need not repeat an expensive page-table lookup for every access. Missing in the TLB is not equivalent to fetching data from disk. If a valid, permitted mapping can be obtained from the page table, execution can continue without a page fault requiring operating-system resolution. A page fault instead signals that the current translation or protection cannot complete the access. Resolving it might require file I/O, allocation of an anonymous page, copy-on-write handling, or rejection of the access. Architecture details determine how the table walk occurs. Classify the translation and access failure before attributing observed latency to swapping, storage speed, or physical-memory shortage.

Mapping changes also need coordination

Changing a page-table entry is not sufficient if processors can continue using stale cached translations. The operating system must perform the appropriate invalidation and coordination for the affected mappings and CPUs. Applications normally request changes through supported interfaces such as mmap or mprotect; they do not directly repair hardware page tables. This distinction also matters for performance. Repeatedly creating and destroying many mappings can incur management and translation-invalidation costs even if the application touches relatively little data. Investigate the number of pages and the frequency of mapping changes alongside allocated bytes. A simple address-translation example explains correctness, but it does not by itself predict the total cost of mapping operations across a multicore machine.

Consider an access crossing a page boundary

With 4 KiB pages, a four-byte read starting at 0x1FFE spans two virtual pages. Bytes 0x1FFE and 0x1FFF belong to the first page, while 0x2000 and 0x2001 belong to the second. Those pages need not map to physically adjacent frames or have identical permissions. Successfully translating the starting address therefore does not establish that the complete requested range is accessible. This matters when validating a buffer supplied to an operating-system interface. The example describes address coverage, not atomicity or the detailed side effects of a faulting instruction. Those require separate architecture and interface contracts. Keeping those questions separate prevents a successful address calculation from being mistaken for a complete correctness argument about the load.

Reading and practice are recorded separately in this browser, for each language.

Learn this in order

Build your CS foundations · STEP 16

Understand the systems behind the web · STEP 6

Prepare for AI systems · STEP 6

Choose a learning path