📝 Basic concepts of Demand Paging (23 MCQs)
Virtual Memory Loading Through Page Faults
Demand paging is a virtual-memory technique in which an operating system loads a page into physical memory only when a process actually references it. Initially, some virtual pages remain on secondary storage or have not yet been allocated physical frames. The memory management unit detects an unavailable mapping and generates a page fault. The kernel handles the exception, obtains the required page, updates its mapping, and resumes execution.
Why Processes Do Not Need Every Page in RAM
Loading an entire program before execution wastes memory when some routines, arrays, or program paths are never accessed. Demand paging reduces this requirement by bringing only referenced pages into RAM. It also allows programs whose virtual address spaces exceed available physical memory to execute. The approach relies on valid virtual-memory mappings, backing storage where required, and hardware capable of detecting missing resident pages.
Page-Fault Handling and Demand Loading Sequence
When a process references a nonresident valid page, the MMU raises a page fault. The kernel verifies the address and access permissions, locates the required contents, and obtains a free frame or selects a victim page. It loads the required page, updates the page table, refreshes relevant translation information, and restarts the interrupted instruction.
Loading a Page After an Invalidation Fault
Suppose a process accesses virtual page 4, which is valid but not resident in RAM. The MMU generates a page fault, and the operating system locates its contents in the backing store. After loading the page into frame 9, the kernel updates the page-table entry. The interrupted instruction executes again using the new mapping.
Memory Savings and First-Access Latency
Demand paging increases effective memory utilisation because unused pages occupy no physical frames. It allows more processes to remain active and supports large virtual address spaces. However, a page fault requires exception handling and potentially slow storage access. Frequent faults can reduce CPU utilisation and cause thrashing, so performance depends heavily on locality, available frames, and storage speed.
Distinguishing Demand Paging from Invalid References
'Every page fault indicates an illegal address' is incorrect because a valid nonresident page also causes a fault. 'Demand paging loads the entire executable' is incorrect because pages are loaded individually when referenced. 'A page fault always requires disk access' is incorrect because some faults involve zero-filled pages, copy-on-write, or other operations without reading an existing disk page.
Exam Focus: Page-Fault Handling and Demand Loading
Trace the complete page-fault sequence, including address validation, frame allocation, page loading, page-table modification, and instruction restart. Distinguish valid nonresident pages from invalid references. Understand how demand paging interacts with page replacement when no free frame exists. Questions may also examine page-fault overhead, locality, and the difference between lazy loading and complete program loading.
Key Terms of Demand Paging
- Demand paging - Loads pages when referenced.
- Page fault - Exception for an unavailable mapping.
- Resident page - Page currently in RAM.
- Backing store - Stores nonresident page contents.
- Free frame - Available physical memory block.
- Locality - Concentration of memory references.
📝 All Basic concepts of Demand Paging MCQs
Q1. What is the term for a fixed-size block of physical memory used to hold a page?
📖 Explanation: A frame is a fixed-size block of physical memory that holds a page. Option A is correct because the MMU places each virtual page into a frame. Options B, C, and D refer to other memory concepts that do not describe the physical block used for paging. Understanding frames is essential when mapping virtual pages to real memory, which enables efficient use of limited physical resources.
Q2. Which component translates virtual addresses to physical addresses?
📖 Explanation: The Memory Management Unit (MMU) performs the translation from virtual to physical addresses, making option B correct. The CPU executes instructions but does not handle address translation directly, so option A is wrong. GPUs and DMA controllers deal with graphics and direct memory transfers, not address translation, so options C and D are incorrect. The MMU’s role is central to virtual memory operation.
Q3. How does the heap typically grow in a virtual address space?
📖 Explanation: In most systems the heap expands toward higher memory addresses, so option A is correct. Downward growth (option B) applies to the stack, not the heap. Both directions (option C) is not typical for a single region, and option D suggests no growth, which contradicts dynamic allocation behavior. Recognizing heap direction helps developers predict memory layout and avoid collisions.
Q4. Why can virtual memory be larger than physical memory?
📖 Explanation: Virtual memory exceeds physical memory primarily because paging allows only needed pages to reside in RAM, making option A correct. Caching (option B) speeds up access but does not increase addressable space. Compression (option C) reduces size but is not the main mechanism for expansion. Swapping moves pages to disk but still relies on paging, so option D is incomplete.
Q5. What is the main advantage of noncontiguous physical page allocation for a process?
📖 Explanation: Noncontiguous allocation reduces external fragmentation by allowing pages to be placed in any free frame, so option A is correct. Increasing speed (option B) is not guaranteed; allocation may even incur extra lookups. Simplifying code (option C) is unrelated to allocation strategy. Swapping (option D) is still required when memory pressure occurs, making that option incorrect.
Q6. How does the stack typically grow in most architectures?
📖 Explanation: The stack usually grows toward lower memory addresses, which is option B. Upward growth (option A) describes the heap, not the stack. Both directions (option C) are not standard for a single stack region. Random growth (option D) would break predictability and is not used in real systems. Knowing stack direction is crucial for avoiding overflow into adjacent memory areas.
Q7. What is the role of a page table in virtual memory?
📖 Explanation: A page table records the mapping from virtual pages to physical frames, making option A correct. It does not hold the actual data (option B) or instructions (option C); those reside in memory pages themselves. Registers (option D) are part of the CPU state, not managed by the page table. Accurate mappings enable correct address translation and protection.
Q8. Why must the MMU be consulted on every memory access?
📖 Explanation: The MMU checks access rights for each reference, enforcing protection, so option A is correct. Increasing latency (option B) is a side effect, not a purpose. Data compression (option C) is handled elsewhere, and cache management (option D) is performed by cache hardware, not the MMU. Protection ensures processes cannot corrupt each other's memory.
Q9. How does sharing a library affect the virtual address space of multiple processes?
📖 Explanation: When a library is shared, each process maps the same physical pages into its own virtual space, so option A is correct. Creating separate copies (option B) would waste memory. Separate address spaces (option C) is true overall but does not describe the sharing mechanism. Option D is false because sharing changes memory usage.
Q10. What would happen if a process's heap exceeds its allocated virtual address space?
📖 Explanation: Exceeding the allocated virtual region triggers a segmentation fault, making option A correct. A page fault (option B) occurs when a valid page is not in memory, not when the address is out of range. Overflow into the stack (option C) describes a collision scenario, not the immediate fault. Automatic expansion (option D) does not happen without explicit OS support.
Q11. How does demand paging improve system performance?
📖 Explanation: Demand paging loads a page the first time it is accessed, conserving memory and I/O, so option A is correct. Loading all pages at startup (option B) would waste resources. Prefetching (option C) can help but is not the core benefit of demand paging. Eliminating swapping (option D) is unrealistic; swapping may still occur.
Q12. If a program accesses address 0x7FFF with a 4 KB page size, which page number is being accessed?
📖 Explanation: Dividing 0x7FFF (32767 decimal) by 4096 yields page number 7, so option A is correct. Option B (0x7F) would be the offset within the page, not the page number. Option C (0x7FF) and option D (0x7FFF) represent larger values and are incorrect for page indexing. Correct page identification is essential for handling page faults.
Q13. In a system with 16 GB physical memory and 64 GB virtual memory per process, what fraction of virtual memory can be resident at any time?
📖 Explanation: Physical memory (16 GB) can hold at most one‑quarter of a 64 GB virtual space, so option A (1/4) is correct. One‑half (option B) would require 32 GB of RAM, which exceeds the physical limit. One‑eighth (option C) and one‑sixteenth (option D) are smaller fractions than actually possible. Understanding this ratio helps predict paging activity.
Q14. A program requests 500 KB of heap memory, but the system uses 4 KB pages. How many pages must be allocated?
📖 Explanation: 500 KB equals 512 000 bytes; dividing by a 4 KB (4096‑byte) page gives 124.9, which rounds up to 125 pages, so option A is correct. Options B–D overestimate the required pages. Correct page count ensures the program receives enough memory without unnecessary waste, illustrating how paging granularity impacts allocation.
Q15. If a process's virtual address space is 2^{32} bytes and the page size is 4 KB, how many entries are needed in its page table?
📖 Explanation: Dividing the 2^{32}‑byte space by a 2^{12}‑byte page yields 2^{20} entries, which we placed as option C. Options A, B, and D represent incorrect powers of two. Knowing the number of page‑table entries helps estimate memory overhead for the table itself and informs OS design choices.
Q16. A system has 8 physical frames and runs two processes each needing 5 pages. Can both be resident simultaneously without swapping?
📖 Explanation: The total demand is 10 pages, but only 8 frames exist, so both processes cannot fully reside, making option B correct. Option A is impossible due to insufficient frames. Option C is partially true but the question asks about both being resident, which they cannot. Sharing (option D) would require common pages, which the scenario does not guarantee.
Q17. If the stack grew upward instead of downward, which memory layout change would be required?
📖 Explanation: When the stack grows upward, it must occupy the region traditionally used by the heap, so swapping their positions (option A) is necessary. Simply increasing heap size (option B) would not resolve the conflict. Adjusting MMU mapping (option C) alone cannot change growth direction. No change (option D) would lead to overlap and crashes.
Q18. If a process's heap and stack grow toward each other and meet, what is the likely result?
📖 Explanation: When the two regions collide, the operating system raises a segmentation fault because the process has exceeded its addressable space, so option A is correct. A page fault (option B) occurs for missing pages, not for address collisions. Memory leaks (option C) are unrelated, and normal termination (option D) would not happen abruptly.
Q19. A system uses a two‑level page table with 1024 entries at each level and 4 KB pages. What is the maximum virtual address space supported?
📖 Explanation: The total addressable space is 1024 × 1024 × 4 KB = 2^{10} × 2^{10} × 2^{12} = 2^{32} bytes, which equals 4 GB, so option A is correct. Options B, C, and D represent incorrect calculations of the addressable range. This shows how hierarchical tables scale to large address spaces.
Q20. A program repeatedly allocates and frees memory dynamically. Which virtual‑memory technique helps keep performance stable?
📖 Explanation: Demand paging loads pages only when they are accessed, reducing unnecessary I/O and keeping performance steady, making option D correct. Simple paging (option A) describes the mechanism but not the on‑demand aspect. Swapping (option B) moves whole processes and can degrade performance. Garbage collection (option C) is a language‑level concept, not a virtual‑memory technique.
Q21. When a process writes to a read‑only page, what exception occurs and how should the OS respond?
📖 Explanation: Writing to a read‑only page triggers a page fault; the OS then creates a private copy (copy‑on‑write) and updates the mapping, so option C is correct. Simply terminating (options A and B) would be unnecessarily harsh. Ignoring the fault (option D) would violate protection rules. Copy‑on‑write balances safety with efficiency.
Q22. A developer notices crashes when the stack exceeds 1 MB. Which configuration change could prevent this?
📖 Explanation: Raising the stack size limit allows the stack to grow larger before triggering a fault, making option B correct. Changing page size (option A) does not directly affect stack limits. Guard pages (option C) detect overflows but do not increase usable space. Reducing heap size (option D) does not address stack overflow.
Q23. If a page‑table entry is corrupted and points to the wrong physical frame, what symptom is most likely?
📖 Explanation: An incorrect mapping causes the CPU to fetch data from the wrong location, leading to wrong values being read, so option A is correct. A segmentation fault (option B) occurs for illegal addresses, not for mis‑mapped but valid frames. A page fault (option C) is raised when a page is absent, not when present but wrong. Latency (option D) may increase slightly but is not the primary symptom.