Describe the idea of virtual memory.
Virtual addressing allows us to access non-resident pages as if they were normal memory.
Define non-resident memory.
They are pages on a non-volatile backing store.
How is the valid/invalid bit used with virtual memory?
Valid/invalid bit is used to mark a page resident/non-resident.
State the purposes of using virtual memory.
Separate program logical memory from physical memory, allowing logical address space to be much larger than physical address space.
Explain the benefits of using virtual memory.
Portability: programs work regardless of how much physical memory there is. Convenience: less of the program needs to be in memory at once, making multi-programming more efficient. Efficiency: doesn’t waste physical memory on code or data that isn’t used.
Describe the virtual address space.
Gives a logical view of how processes are stored in memory. Contiguous address starting at address 0 until end of space.
State the hardware requirement for virtual addressing.
The memory management unit to map logical to physical addresses.
Describe how the stack and heap are stored in virtual address space.
The stack starts at maximum logical address and grows down. The heap starts at minimum logical address and grows up.
Explain why internal fragmentation in virtual address space does not waste physical memory.
Physical memory is not allocated until the heap or stack grows to a new page.
Describe how system libraries are shared with virtual addressing.
Shared memory between processes by mapping pages into the virtual address space of the processes.
Define page fault.
A page fault is a trap to the OS sent when an invalid page is referenced.
Describe what happens on a page fault.
If invalid memory reference, abort. If valid but not resident, find a free page and swap the page in. The page is then marked as valid, and the instruction causing the fault is restarted.
State the challenge of handling page faults for instructions that access several memory locations and how to solve it.
An instruction may modify memory before causing a page fault, but it must be restarted from the start. Handled by checking all memory locations that will be accessed before running the instruction.
What is a double fault?
It is when the page fault handler itself triggers a fault.
Describe pure demand paging.
Start with every page marked as invalid. Bring pages into memory as needed.
State the benefit of demand paging.
Reduced IO/memory needed and response time.
State the hardware requirement for demand paging.
Page table with valid/invalid bit. Secondary memory (swap device). Ability to restart instructions.
Describe a lazy swapper.
It never swaps a page into memory unless the page is needed.
State the formula for effective access time (demand paging)
$$\text{ETA}=(1-p) \times \text{memory access time} + p \times \text{page fault service time}$$ where $p$ is the page fault rate.
Describe copy on write.
Parent and child process initially share the same pages in memory. Only copy when a process modifies the shared page.
State the benefit of using copy on write.
Allows for efficient process creation.
State the optimisations for demand paging.
Using copy on write. Writing to IO in larger chunks. Keeping a pool of free pages (so you don’t need to free a page during a page fault).
How to create a child with copy on write on UNIX?
vfork creates a child with a copy on write address space of the parent.
How are page faults handled if there are no free frames?
Locate a victim page and write it to disk. Restart the faulting process.