📝 Logical versus physical address space in Main memory (11 MCQs)
Two Address Spaces in Virtual Memory Systems
Logical and physical address spaces represent two different views of memory access within the memory-management subsystem. A logical address, commonly called a virtual address in modern systems, is generated by a running process. A physical address identifies an actual location in main memory. The operating system and MMU coordinate these spaces, allowing processes to use independent address ranges without owning fixed physical locations.
Why Programs Require Independent Address Spaces
Allowing every process to access identical physical addresses without translation would create conflicts and weaken memory protection. One program could otherwise overwrite another program's instructions or data. Separate logical address spaces solve this problem by providing independent address ranges mapped onto available physical memory. This arrangement also permits non-contiguous physical allocation and supports virtual memory larger than the currently available RAM.
MMU Translation from Logical to Physical Addresses
When a process accesses memory, the CPU generates a logical address. The MMU searches the TLB for an existing translation before consulting page tables when necessary. The translation identifies a physical frame, which is combined with the original page offset. The resulting physical address accesses memory. Invalid mappings or prohibited operations generate exceptions that the operating system must handle.
Calculating a Physical Address Using Paging
Consider a system using 4 KB pages and a logical address of 8196. Dividing by 4096 produces page number 2 and offset 4. Suppose page 2 maps to physical frame 7. The physical address becomes 7 multiplied by 4096, plus 4, producing 28676. Identical logical addresses in different processes can therefore identify different physical locations.
Isolation, Relocation and Address-Space Capacity
Separate address spaces improve protection, simplify program loading, and permit controlled memory sharing. Paging allows a process to use non-contiguous physical frames while maintaining a continuous logical address range. Translation introduces hardware and memory overhead because page tables and TLBs require resources. Large address spaces may also increase mapping costs, encouraging hierarchical, hashed, or inverted page-table structures in suitable systems.
Frequent Confusions Between Virtual and Physical Addresses
'A logical address always equals a physical address' is incorrect because the MMU can translate it elsewhere. 'Each process must occupy one contiguous physical region' is incorrect under paging because frames can be distributed across memory. 'A TLB stores program data' is incorrect because it caches address translations and associated attributes rather than ordinary application contents.
Exam Focus: Address Translation and Page Offsets
Practise dividing logical addresses by page size to obtain page numbers and offsets. Given a page table, identify the mapped frame and calculate the physical address. Compare the address spaces of different processes and explain why equal logical addresses need not identify equal physical locations. Distinguish translation, protection checking, TLB hits, and page faults in address-tracing problems.
Key Terms of Logical and Physical Addressing
- Logical address - Address generated by CPU.
- Physical address - Actual RAM location.
- Address space - Range of accessible addresses.
- MMU - Translates memory addresses.
- Page offset - Position within a page.
- TLB - Cache for address translations.
📝 All Logical versus physical address space in Main memory MCQs
Q1. What term describes the address generated by a program before any translation by the memory-management unit?
📖 Explanation: Logical (virtual) addresses are the values a program produces when it references memory. The MMU later maps these to actual locations in RAM. They differ from physical addresses, which refer directly to hardware cells. This separation lets the OS relocate programs, provide isolation, and implement paging. Hence the correct answer is B. The other choices describe physical or unrelated concepts, which the MMU does not generate from program code.
Q2. A process has a base register value of . If the program generates a logical address , what is the corresponding physical address?
📖 Explanation: The base register holds the start of the process’s segment in physical memory. Adding the logical offset to the base yields the physical address . Option A reflects this calculation. Option B omits the base, option C ignores the offset, and option D adds an incorrect amount. This demonstrates how simple base‑plus‑offset translation maps a program’s virtual view to actual RAM locations.
Q3. Why does an operating system prefer using logical addresses rather than physical addresses for program code?
📖 Explanation: Logical addresses give the OS flexibility to move code and data in RAM without changing the program itself. By translating these addresses at run time, the OS can place processes wherever free memory exists, supporting multitasking and protection. Option A states this benefit. Option B is inaccurate because translation adds overhead, option C is unrelated, and option D is false because paging is still needed for virtual memory.
Q4. Given a page size of 4 KB ( bytes) and a page‑table entry that maps virtual page 1 to physical frame 7, what physical address corresponds to the logical address ?
📖 Explanation: A 4 KB page means the lower 12 bits are the offset. The logical address has page number 1 (bits above the offset) and offset . The page table maps page 1 to frame 7, so the physical address is frame 7 × 0x1000 + offset = . Option A matches this result. The other options either ignore the frame mapping or mis‑calculate the offset.
Q5. Which statement best captures the primary difference between segmentation and paging memory management schemes?
📖 Explanation: Segmentation divides a program’s address space into logical sections that can vary in size, such as code or data segments. Paging, by contrast, breaks memory into equal‑sized pages, simplifying allocation and page‑table management. Option A correctly describes this distinction. Options B, C, and D are inaccurate: both schemes can use a TLB, both provide protection, and both perform logical‑to‑physical translation.
Q6. A TLB contains entries for virtual pages 0–3. When the CPU accesses virtual page 5, what event occurs?
📖 Explanation: The TLB (Translation Lookaside Buffer) caches recent virtual‑to‑physical translations. Since it only holds pages 0‑3, an access to page 5 is not cached, resulting in a TLB miss. The hardware then consults the page table to obtain the mapping, which is a page‑table walk, not a page fault. Therefore option C is correct. Option A incorrectly assumes a hit, option B confuses a miss with a fault, and option D misstates the mechanism.
Q7. How does assigning each process its own logical address space improve overall system security?
📖 Explanation: Separate logical address spaces isolate processes, so a program cannot directly address memory belonging to another process. The MMU enforces this isolation by translating each process’s virtual addresses to distinct physical frames, and any illegal access triggers a protection fault. Option A captures this security benefit. Options B, C, and D describe unrelated effects that do not stem from address‑space isolation.
Q8. In a two‑level page table, a 16‑bit virtual address is divided into a 4‑bit first‑level index, a 4‑bit second‑level index, and an 8‑bit offset (page size bytes). The first‑level entry for index points to a second‑level table located at physical frame . The second‑level entry for index contains frame number . What physical address corresponds to the virtual address ?
📖 Explanation: The virtual address splits as: first‑level index = 0xA, second‑level index = 0x5, offset = 0x9F. The first‑level entry directs to the second‑level table; the second‑level entry gives physical frame 0x7C. The final physical address is frame 0x7C × 0x100 (page size) + offset = . Option A reflects this calculation. The other options misplace the frame or ignore the offset.
Q9. A shared library is compiled to run at base address but the loader places it at . If a function inside the library has a compiled offset of , what runtime address will the program use to call this function?
📖 Explanation: The library’s compiled offset (0x200) is added to the actual load base (0x400000) to obtain the runtime address: . Option A shows this correct address. Option B uses the original compile‑time base, option C subtracts incorrectly, and option D adds an extra 0x200000, all of which would cause incorrect calls.
Q10. What is a key trade‑off when choosing a larger page size versus a smaller page size in a virtual‑memory system?
📖 Explanation: Larger pages mean each page holds more data, so unused space within a page (internal fragmentation) grows, but fewer pages are needed to cover a given address range, allowing a smaller TLB to cover more memory (better TLB coverage). Option B states this balance. Option A reverses the effects, option C is false because a TLB is still useful, and option D oversimplifies performance considerations.
Q11. A process uses demand paging with three physical frames and follows the reference string: 1,2,3,4,1,2,5,1,2,3,4,5. Using the FIFO replacement policy, how many page faults occur?
📖 Explanation: Starting with empty frames, each new page causes a fault. After loading pages 1,2,3 (3 faults), page 4 replaces page 1 (fault), then page 1 replaces page 2 (fault), page 2 replaces page 3 (fault), page 5 replaces page 4 (fault), pages 1 and 2 hit, page 3 replaces page 5 (fault), page 4 replaces page 1 (fault), and page 5 replaces page 2 (fault). This totals 10 faults. Option C matches this count. The other numbers underestimate or overestimate the faults.