1. Home
  2. Explore
  3. Computer Science
  4. Virtual Memory Explained

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Virtual Memory Explained

  • 28Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Physical Addressing and Fragmentation

What was the main problem with early physical addressing in memory management?

28 questions

  1. 1

    What was the main problem with early physical addressing in memory management?

    Model answer

    Programs could overwrite each other's memory because there was no abstraction or protection between them.

    Explanation

    In physical addressing, programs directly accessed hardware addresses, so a bug in one program could corrupt another's data or the OS.

  2. 2

    How did two programs collide in the physical addressing era?

    Model answer

    Both programs assumed they had the entire machine, so one could overwrite memory used by the other since there were no walls or protection.

    Explanation

    Without abstraction, programs stored data at specific physical addresses, leading to conflicts.

  3. 3

    What is external fragmentation?

    Model answer

    It is the inability to use free memory because it is split into small, non-contiguous chunks, preventing allocation of a single continuous block.

    Explanation

    Even if total free space is sufficient, no single gap is large enough for a program that requires contiguous memory.

  4. 4

    Describe the scenario with 64KB RAM, three 20KB programs (A, B, C) that illustrates external fragmentation.

    Model answer

    After loading A, B, C consecutively, the remaining space is 4KB. Closing B creates a 20KB hole in the middle, leaving 20KB + 4KB = 24KB free, but the largest contiguous gap is only 20KB, so a 22KB program cannot be loaded.

    Explanation

    This shows that total free memory (24KB) is enough, but fragmentation prevents usage.

  5. 5

    Why could a 22KB program not run when there was 24KB of free memory (20KB hole + 4KB end) in the early contiguous allocation systems?

    Model answer

    Because the program required a single contiguous block of memory, and the largest contiguous free block was only 20KB.

    Explanation

    Programs could not be split, so even though total free space was 24KB, the 22KB request could not be satisfied.

  6. 6

    What is the role of the Memory Management Unit (MMU) in base and bounds?

    Model answer

    The MMU translates virtual addresses to physical addresses by adding the base register value, and checks bounds for protection.

    Explanation

    It performs address translation and protection checks in hardware for every memory access.

  7. 7

    How do base and bound registers work for address translation in base and bounds?

    Model answer

    The OS stores the program's physical start address in the base register and its size in the bound register. The MMU adds the base to each virtual address to get the physical address, and checks that the virtual address is less than the bound.

    Explanation

    This gives each program a private, isolated region of physical memory while it thinks it starts at address 0.

  8. 8

    What happens when a program tries to access an address beyond its bound register value?

    Model answer

    The MMU detects the violation, blocks the access, and raises a segmentation fault (hardware exception), handing control to the OS which typically kills the program.

    Explanation

    This enforces memory protection, preventing programs from accessing memory outside their allocated region.

  9. 9

    What is a segmentation fault?

    Model answer

    A hardware exception triggered when a program attempts to access memory outside its assigned region, detected by the MMU using the bound register.

    Explanation

    It protects the system from malicious or buggy programs by stopping execution immediately.

  10. 10

    What is compaction and why was it needed in base and bounds systems?

    Model answer

    Compaction is the process of moving all active programs in RAM to close gaps and create a single contiguous free block, needed because external fragmentation prevented loading new programs.

    Explanation

    It was slow and wasted CPU time, as the OS had to stop everything and shift programs around.

  11. 11

    What is segmentation and how does it differ from base and bounds?

    Model answer

    Segmentation divides a program into multiple segments (code, heap, stack), each with its own base and bound (entry in segment table), allowing non-contiguous placement and per-segment permissions.

    Explanation

    Unlike base and bounds which treated the program as one block, segmentation allows finer-grained organization and sharing.

  12. 12

    How does segmentation enable code sharing between multiple instances of the same program?

    Model answer

    The OS can keep a single copy of the read-only code segment in physical RAM and map all program instances to it, while each instance has its own private data segments.

    Explanation

    Shared code saves memory and allows safe sharing of read-only instructions.

  13. 13

    What problem did segmentation still face despite its improvements?

    Model answer

    External fragmentation persisted because segments were variable-sized, so creating and destroying segments left small unusable holes in physical memory.

    Explanation

    The system still had to fit variable-sized chunks into RAM, leading to fragmentation despite better logical organization.

  14. 14

    What are page frames and pages in paging?

    Model answer

    Page frames are fixed-size slots (typically 4KB) that physical RAM is divided into. Pages are the same-size chunks that a program's virtual address space is divided into.

    Explanation

    Any page can be placed in any free frame, enabling non-contiguous allocation.

  15. 15

    How does paging eliminate external fragmentation?

    Model answer

    Since all page frames and pages are the same size, any free frame can hold any page. There are no variable-sized gaps, so memory can be fully utilized without holes.

    Explanation

    External fragmentation disappears because the smallest unit is fixed; no gap is too small to use.

  16. 16

    What is internal fragmentation in paging?

    Model answer

    Wasted space inside a page when a program allocates less than a full page; for example, a 1-byte request uses a 4KB page, wasting 4095 bytes.

    Explanation

    Internal fragmentation is a trade-off for eliminating external fragmentation, and it can accumulate with many small allocations.

  17. 17

    What is the role of the page table?

    Model answer

    The page table is a per-process data structure that maps each virtual page to its corresponding physical page frame, enabling the CPU to translate virtual addresses.

    Explanation

    It is the master map used by the operating system to track where each page resides in physical RAM.

  18. 18

    What is the TLB and why is it needed?

    Model answer

    The TLB (Translation Lookaside Buffer) is a small, fast hardware cache inside the CPU that stores recent virtual-to-physical address translations, needed to avoid slow page table walks for every memory access.

    Explanation

    Without the TLB, paging would double memory access time (first for page table, then for data), which is unacceptable for performance.

  19. 19

    What is a TLB hit and TLB miss?

    Model answer

    A TLB hit occurs when the translation for a virtual address is found in the TLB, allowing instant translation. A TLB miss occurs when it is not cached, requiring a page table walk (slower).

    Explanation

    Due to spatial locality, TLB hits occur over 99% of the time, making paging efficient.

  20. 20

    How does the TLB help improve memory access performance in paging?

    Model answer

    It caches recent translations so most memory accesses avoid the full page table lookup, reducing latency from two RAM accesses to one (or less).

    Explanation

    The TLB leverages locality to speed up address translation significantly.

  21. 21

    In a paging system, how does a program see its memory?

    Model answer

    The program sees a single, contiguous virtual address space starting at address 0, unaware that its pages are scattered across different physical frames.

    Explanation

    The illusion of contiguous memory is maintained by the page table and TLB working together.

  22. 22

    What is demand paging?

    Model answer

    A technique where the OS does not load an entire program into RAM at startup; instead, it loads only the pages needed immediately and marks others as 'not present' in the page table.

    Explanation

    This saves RAM and allows programs larger than physical memory to run, as pages are loaded on demand.

  23. 23

    What does the 'not present' flag do in the page table?

    Model answer

    It indicates that a virtual page is not currently in physical RAM. Accessing such a page triggers a page fault, causing the OS to load the page from disk.

    Explanation

    This flag is essential for demand paging and enables virtual memory to exceed physical RAM size.

  24. 24

    What is a page fault and how does the OS handle it?

    Model answer

    A page fault is a hardware exception when a program accesses a page marked 'not present'. The OS pauses the program, loads the missing page from disk into RAM, updates the page table, and resumes the program.

    Explanation

    The program is unaware of the delay; the OS transparently brings the needed page into memory.

  25. 25

    What is a replacement policy and give an example?

    Model answer

    A replacement policy decides which page to evict from RAM when a new page must be loaded and no free frames exist. An example is LRU (Least Recently Used), which evicts the page that has not been accessed for the longest time.

    Explanation

    Good policies aim to minimize future page faults by keeping frequently used pages in RAM.

  26. 26

    What is the LRU algorithm?

    Model answer

    LRU (Least Recently Used) evicts the page that has not been accessed for the longest period of time, under the assumption that recently used pages are likely to be used again soon.

    Explanation

    It approximates optimal replacement but requires tracking access history.

  27. 27

    What is thrashing and what are its symptoms?

    Model answer

    Thrashing occurs when the system spends most of its time swapping pages between RAM and disk instead of executing programs, causing extreme slowdown, stuttering cursor, and high disk activity.

    Explanation

    It happens when physical RAM is severely oversubscribed, leading to constant page faults and evictions.

  28. 28

    Why does thrashing slow down the system so much?

    Model answer

    The CPU spends less than 1% of time running code and 99% on swapping pages because pages are evicted and immediately needed again, causing a cycle of disk I/O.

    Explanation

    Disk I/O is orders of magnitude slower than RAM, so the system becomes I/O-bound and practically freezes.

1 of 28
Question 1 of 28

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent