TutorialsOperating Systems
Core CS

logical vs Physical address space

A logical address space is the set of all virtual addresses generated by the CPU while a program executes, representing memory from the process's own perspective. In contrast, a physical address space is the set of actual physical memory locations (RAM) where code and data physically reside. The Memory Management Unit (MMU) translates logical addresses into physical addresses at runtime, allowing programs to execute seamlessly without needing to know or manage their exact hardware memory locations.

<p></p><h2><!--StartFragment--><p><b>Definitions</b></p><ul><li><p><b>Logical Address Space:</b> An abstract view of memory created by the operating system and CPU for a running program. The program treats this address range (typically starting at 0 up to a maximum limit) as its private, contiguous workspace. Because it does not directly touch physical RAM chips, it is also referred to as virtual memory.</p></li><li><p><b>Physical Address Space:</b> The real, identifiable hardware memory locations available on the system’s RAM bus. Each physical address directly references a specific byte or word in main memory hardware.</p></li></ul><p><b>Key Differences &amp; Characteristics</b></p><ul><li><p><b>Generation:</b> Logical addresses are generated directly by the CPU during program compilation and runtime; physical addresses are accessed via memory buses on the physical RAM.</p></li><li><p><b>Hardware Intermediary:</b> The <b>Memory Management Unit (MMU)</b> translates logical addresses into physical addresses at runtime using techniques like base/relocation registers, paging, or segmentation.</p></li><li><p><b>User Visibility:</b> A programmer or process can directly view and work with logical addresses (e.g., pointers in C), but can never directly view or manipulate physical RAM addresses.</p></li><li><p><b>Size Independence:</b> Logical address space can be larger or smaller than physical address space. With virtual memory, a 64-bit program can address far more logical space than the physical RAM installed.</p></li></ul><table><thead><tr><td><strong>Feature</strong></td><td><strong>Logical Address Space</strong></td><td><strong>Physical Address Space</strong></td></tr></thead><tbody><tr><td><b>Generated By</b></td><td>CPU</td><td>Memory Management Unit (MMU) / RAM hardware</td></tr><tr><td><b>Alternative Name</b></td><td>Virtual Address Space</td><td>Real / Absolute Address Space</td></tr><tr><td><b>Visibility</b></td><td>Directly accessible by user programs</td><td>Handled strictly by OS and hardware</td></tr><tr><td></td><td></td><td><br></td></tr></tbody></table><p><b><br></b></p><p><b>Significance</b></p><ul><li><p><b>Process Isolation &amp; Protection:</b> Prevents a rogue or buggy process from overwriting another process's data or corrupting the operating system kernel.</p></li><li><p><b>Dynamic Relocation:</b> Programs can be loaded into any available slot in physical memory or swapped to secondary storage without rewriting their internal memory references.</p></li><li><p><b>Efficient Memory Utilization:</b> Physical memory does not need to be contiguous to hold a program; non-contiguous physical chunks (pages or frames) appear completely contiguous to the CPU.</p></li></ul><p><b>Advantages</b></p><ul><li><p><b>Multitasking Support:</b> Multiple processes can share physical memory concurrently without stepping on each other.</p></li><li><p><b>Virtual Memory Expansion:</b> Allows running programs whose memory footprint exceeds the capacity of available physical RAM.</p></li><li><p><b>Simplified Compiling:</b> Compilers generate code assuming a standard starting address (e.g., $0x00000000$) rather than calculating actual RAM layouts.</p></li></ul><p><b>Disadvantages</b></p><ul><li><p><b>Translation Overhead:</b> Every memory lookup requires an address translation step (via page tables or MMU registers), which can add latency (mitigated using TLBs).</p></li><li><p><b>Hardware Complexity:</b> Requires dedicated MMU hardware and operating system structures (like page tables) that consume additional memory overhead.</p></li><li><p><b>Page Fault Handling:</b> If a referenced logical address is swapped out to disk, handling the page fault incurs significant disk I/O delay.</p></li></ul></h2><p></p>