Skip to main content
Logo image

Dive Into Systems: Exercises

Section 13.3 Virtual Memory

Checkpoint 13.3.1. Program Memory Regions.

Checkpoint 13.3.2. Program Memory Regions.

Checkpoint 13.3.3. Virtual Address Space.

    True or False: To ensure that processes cannot access each other’s data, the OS divides the virtual address space up between multiple processes.
  • True
  • Incorrect.
  • False
  • Correct! The virtual-memory abstraction gives each process its own separate entire virtual address space.

Checkpoint 13.3.4. Virtual Addresses.

    True or False: The same virtual address in two different processes can map to two different physical addresses.
  • True
  • Correct!
  • False
  • Incorrect. See Figures 2 and 3 in Section 13.3.

Checkpoint 13.3.5. Virtual-to-Physical Memory Mapping.

    True or False: Pages 100 and 101 of virtual memory can never map to frames 500 and 501, respectively, of physical memory.
  • True
  • Incorrect. There is no guarantee where two consecutive pages will be located in physical memory, but nothing prevents them from being mapped to consecutive frames.
  • False
  • Correct!

Checkpoint 13.3.6. Virtual Memory.

    Which of the following is NOT an advantage of using virtual memory?
  • Eliminates the need for physical memory in the system
  • Correct!
  • Allows programs to use more memory than physically available
  • Incorrect.
  • Increases system security by isolating process’s memory
  • Incorrect.
  • Enables efficient multitasking by providing separate address spaces for processes
  • Incorrect.

Checkpoint 13.3.7. Address Translation.

Fill in the blanks with the appropriate word:
The MMU translates from addresses to addresses.

Checkpoint 13.3.8. Virtual and Physical Address Lengths.

    True or False: To support virtual memory the OS must ensure that the length of the virtual addresses are the same as the length of physical addresses (the same number of bits).
  • True
  • Incorrect. Refer to Figures 6 and 7 in Section 13.3.3.
  • False
  • Correct!

Checkpoint 13.3.9. Vocabulary.

Checkpoint 13.3.10. Virtual Addresses.

    In a virtual memory system, what is the primary role of the offset portion of a virtual address?
  • Specifies the exact byte location within a page
  • Correct!
  • Identifies the specific page within the page table
  • Incorrect.
  • Determines the frame number in physical memory
  • Incorrect.
  • Maps virtual addresses to physical addresses in the cache
  • Incorrect.

Checkpoint 13.3.11. Virtual to Physical Address Translation.

    Which of the following must the OS do during a context switch to support virtual address to physical address translation?
  • Update the MMU hardware to refer to the swapped-on process’s virtual memory.
  • Correct!
  • Select a physical frame for each page of the process’s virtual memory.
  • Incorrect.
  • Zero out (erase) the contents of the swapped-out process’s virtual memory.
  • Incorrect.
  • Find enough contiguous frames of RAM to fit the swapped-on process’s virtual pages.
  • Incorrect.

Checkpoint 13.3.12. Memory Address Size.

    In a computer system that uses 8 bits for a memory address, what is the range of valid addresses?
  • 0 – 255
  • Correct!
  • 0 - 7
  • Incorrect.
  • 0 - 8
  • Incorrect.
  • 0 - 256
  • Incorrect.

Checkpoint 13.3.13. Virtual vs. Physical Addresses.

    In a computer system with 32-bit virtual addresses, a physical memory size of 1 GB, and a page size of 4 KB, how many bits are used for the virtual page number (VPN) and for the physical frame number (PFN)?
  • VPN: 20 bits, PFN: 18 bits
  • Correct!
  • VPN: 10 bits, PFN: 8 bits
  • Incorrect.
  • VPN: 18 bits, PFN: 20 bits
  • Incorrect.
  • VPN: 20 bits, PFN: 20 bits
  • Incorrect.
Hint.
1 GB is 220 bytes, 1 KB is 210 bytes

Checkpoint 13.3.14. Physical Memory Size.

    If there are 4192 frames of physical memory, and the page size is 512 bytes, how large is the physical memory space in bytes?
  • \(2^{9}\) bytes
  • Incorrect.
  • \(2^{10}\) bytes
  • Incorrect.
  • \(2^{12}\) bytes
  • Incorrect.
  • \(2^{20}\) bytes
  • Incorrect.
  • \(2^{21}\) bytes
  • Correct!
Hint.
Physical memory size depends on the number of frames and the size of each frame (the page size).

Checkpoint 13.3.15. Fork and Memory.

    Given the following C code:
       pid_t pid1;
       int x;
    
    
       x = 1;
       pid1 = fork();
       if (pid1 == 0) {
           x = 2;
       } else {
           x = 3;
       }
       printf("x = %d\n", x);
    
    When run, the print statement will be executed twice, once by the parent and once by the child process.
    Choose the answer that describes the two values of x that are printed and the justification.
  • The two values are different because the variable x in each of their virtual memory spaces is mapped to is mapped to different physical memory addresses.
  • Correct!
  • Both values of x are the same because the variable x in each of their virtual memory spaces is mapped to the same physical memory address.
  • Incorrect.
  • The two values are different because the child process executes before the parent process.
  • Incorrect.
  • The two values are the same because the value written by the child process overwrites the value written by the parent process.
  • Incorrect.

Checkpoint 13.3.16. Page Tables.

    Where is the page table stored?
  • in memory (RAM)
  • Correct!
  • on disk
  • Incorrect.
  • in the page table base register (PTBR)
  • Incorrect.
  • none of these
  • Incorrect.

Checkpoint 13.3.17. Virtual Address Translation.

    Why is the offset part of a virtual address unchanged when translated to a physical address?
  • The offset is used for indexing within a page, which is the same offset for indexing into the frame.
  • Correct!
  • The offset bits determine the page number, which is the same as the frame number in the physical address.
  • Incorrect.
  • The OS ensures that virtual pages and physical frames are different sizes.
  • Incorrect.
  • The Memory Management Unit (MMU) modifies only the offset during address translation.
  • Incorrect.
Hint.
The size of a page is the same as the size of a frame.

Checkpoint 13.3.18. Virtual and Physical Memory.

    Which of the following statements are true?
  • The virtual pages of a process must be laid out in consecutive virtual addresses.
  • Correct!
  • Physical frames should be larger than virtual pages so that pages can fit within them.
  • Incorrect.
  • Physical frames allocated to a process must be laid out in consecutive physical addresses.
  • Incorrect.

Checkpoint 13.3.19. Page Table Entries.

Checkpoint 13.3.20. Address Translation.

Order the following steps for translating a virtual address to a physical address when there is not a page fault.

Checkpoint 13.3.21. Handling a Page Fault.

Order the following steps for translating a virtual address to a physical address when there is a page fault.

Checkpoint 13.3.22. Paging During Context Switches.

    Which of the following actions must the OS take during a context switch to support paging?
  • Save the current process’s PTBR value, restore the new process’s PTBR value
  • Correct!
  • Set the valid bit of each page in the current process’s page table to 0.
  • Incorrect.
  • Set the valid bit of each page in the new process’s page table to 1.
  • Incorrect.