Translates

How to say it in other languages, and what words mean

Spanish

Linear Address Space: Definition & Address Translation

· 8 min read · Spanish

In this article
  1. Background: Why Linear Address Spaces Exist
  2. How Address Translation Works: The Page Table Path
  3. Multi-Level Page Tables and 64-bit Systems
  4. Common Problems and Misconceptions
  5. Address Translation in Practice: Virtual Memory and Paging
  6. How to Choose: Page Sizes and Translation Strategies
  7. Frequently Asked Questions
  8. Alternatives and Related Concepts

A linear address space is a flat, contiguous range of memory addresses that a program or process can use, starting at 0 and extending to a maximum limit. In modern computing, it is the virtual address space presented to a running process by the CPU's memory management unit (MMU). Address translation is the hardware and operating-system process that maps each linear address to a physical address in RAM (or to a page on disk). This mapping is what allows every process to have its own private, seemingly large memory region while the physical memory is shared and protected.

Background: Why Linear Address Spaces Exist

Early computers used physical addresses directly: a program's memory references corresponded exactly to RAM locations. That worked for single-tasking systems, but as multitasking became common, several problems emerged. Programs could overwrite each other's memory, a bug in one program could crash the whole system, and the total memory available to all programs was limited by the size of physical RAM.

The solution was to introduce a layer of indirection. Each process gets its own linear address space—a virtual, flat range of addresses that looks like a simple 0-to-N sequence. The CPU's MMU, with the operating system's help, translates each linear address to a physical address on every memory access. This design provides isolation (each process's linear space is separate), flexibility (a process can use more memory than physically available by swapping pages to disk), and simpler programming (no need to manage physical memory fragmentation).

How Address Translation Works: The Page Table Path

Address translation is performed by the MMU using data structures called page tables. The linear address space is divided into fixed-size blocks called pages (typically 4 KB on x86 systems, but larger sizes exist). Physical memory is divided into frames of the same size. A page table entry (PTE) stores the frame number that corresponds to a given linear page, plus permission bits (read, write, execute) and status bits (present, dirty, accessed).

Here is the step-by-step process for a single memory access:

  1. The CPU generates a linear address (e.g., 0x00401000).
  2. The MMU splits the address into a page number (the high bits) and an offset (the low bits). For a 4 KB page, the offset is the lower 12 bits; the page number is the rest.
  3. The MMU looks up the page number in the page table. The base of the page table is held in a control register (e.g., CR3 on x86).
  4. If the page table entry is present, the MMU combines the frame number from the entry with the offset to produce the physical address (e.g., 0x12345000 + 0x1000 = 0x12346000).
  5. If the entry is not present, the MMU raises a page fault exception, and the operating system decides whether to load the page from disk, allocate a new frame, or terminate the process (if the access is invalid).

To speed up this process, the CPU uses a translation lookaside buffer (TLB), a small cache of recent translations. Without a TLB, every memory access would require multiple memory reads for the page table, making the system impractically slow.

Multi-Level Page Tables and 64-bit Systems

On 32-bit systems, a single-level page table would have up to 1 million entries (for 4 KB pages in 4 GB of address space), which is too large to keep in memory for each process. Therefore, modern CPUs use multi-level page tables. For example, x86-64 uses four levels: PML4, PDPT, PD, and PT. The linear address is split into several fields, each indexing into one level. This hierarchical structure allows page tables to be sparse—only the entries that are actually used need to be allocated.

On 64-bit systems, the linear address space is enormous (typically 2^48 or 2^57 bytes, depending on the architecture). However, not all of it is usable by user programs; the upper half is reserved for the kernel. The linear address space is thus split into user space and kernel space, with a boundary that the operating system defines.

Common Problems and Misconceptions

One common misconception is that a linear address is the same as a physical address. In reality, a linear address is virtual; it only becomes physical after translation. For example, a program might read from address 0x1000, but the actual RAM location could be 0x7F00 or any other frame. This is why debugging tools that show physical addresses are rarely useful to programmers—they see only linear addresses.

Another issue is fragmentation. Physical memory can become fragmented, but the linear address space hides this because the page table maps non-contiguous frames to contiguous linear pages. However, the page table itself can become a performance bottleneck if not managed well. Also, a process can run out of linear address space if it uses too much virtual memory (e.g., due to a memory leak), even if physical RAM is available.

Security is also a concern. Translation is what enforces memory protection: a process cannot access a linear page unless the page table entry grants permission. A bug in the translation logic (e.g., a TLB not being flushed after a page table change) can lead to security vulnerabilities, so operating systems must carefully manage TLB invalidation.

Address Translation in Practice: Virtual Memory and Paging

The linear address space is the foundation of virtual memory. When a process accesses a linear address that is not present in physical memory, the MMU triggers a page fault. The operating system then reads the page from disk (the swap file or page file) into a free frame, updates the page table, and resumes the process. This allows programs to run even when they are larger than physical RAM.

For example, on a 64-bit Linux system, a process's linear address space typically includes:

  • Text segment (executable code)
  • Data segment (initialized and uninitialized variables)
  • Heap (dynamically allocated memory)
  • Memory-mapped files (shared libraries, etc.)
  • Stack (local variables and call frames)
  • Kernel region (reserved, not accessible to user)

Each of these regions is mapped to physical pages via the page table. The operating system decides which pages to keep in memory and which to evict, using algorithms like LRU (least recently used).

How to Choose: Page Sizes and Translation Strategies

System designers and administrators can influence translation performance by choosing page sizes. Larger pages (e.g., 2 MB or 1 GB on x86-64) reduce the number of page table entries and improve TLB hit rates, which is beneficial for applications with large memory footprints, such as databases or virtual machines. However, larger pages can waste memory if the application uses only a small portion of a page (internal fragmentation).

When configuring an operating system, you might enable huge pages or transparent huge pages (THP) to improve performance. The choice depends on the workload:

  • If the workload uses many small objects, standard 4 KB pages are often better.
  • If the workload uses large contiguous buffers (e.g., a key-value store), huge pages can reduce TLB misses.
  • For virtualization, the hypervisor may use nested page tables (EPT on Intel, NPT on AMD) to translate guest linear addresses to host physical addresses, adding another layer.

Frequently Asked Questions

What is the difference between a linear address and a virtual address?

In most modern architectures, they are the same thing. The term "linear address" is used on x86 to refer to the address before segmentation (if segmentation is enabled) but after paging is applied. In practice, with flat memory models (as used by all mainstream operating systems), the linear address is the virtual address seen by the process.

Why does a process have its own linear address space?

To provide isolation and protection. If all processes shared the same physical addresses, one program could read or modify another's memory, causing crashes or security breaches. Each process's linear address space is mapped to different physical frames, so they cannot interfere.

What happens when a program accesses an invalid linear address?

The MMU raises a page fault. The operating system checks whether the address is valid (e.g., within the process's allocated regions). If it is invalid, the OS sends a segmentation fault signal to the process, typically terminating it. If it is valid but not in memory, the OS loads the page from disk and resumes.

Can a linear address space be larger than physical RAM?

Yes, that is the whole point of virtual memory. The linear address space is limited by the CPU's address width (e.g., 2^48 on x86-64), not by RAM size. Pages that are not accessed can be stored on disk and swapped in on demand.

What is the TLB and why does it matter?

The TLB is a hardware cache that stores recent linear-to-physical translations. Without it, every memory access would require multiple memory reads to walk the page table, slowing down the system by an order of magnitude. The TLB is managed by the CPU and the OS (e.g., flushing on context switch).

While linear address spaces with paging are the dominant model, there are alternatives. Some systems use segmentation, where addresses are composed of a segment selector and an offset. However, modern operating systems use a flat model where segmentation is essentially disabled, and paging handles all translation. Another alternative is single-address-space operating systems (like IBM AS/400), where all processes share one large address space and protection is done via capabilities rather than isolation. These are rare and specialized.

In embedded systems without an MMU (e.g., microcontrollers), there is no linear address translation—the CPU accesses physical memory directly. This is simpler but offers no protection or virtual memory.

Understanding linear address spaces is crucial for systems programming, debugging memory issues, and optimizing performance. The concept is fundamental to how modern operating systems provide the illusion of unlimited, private memory to each running program.