Virtual Memory
15 important questions on Virtual Memory
What are 3 benefits of partially-loading a program?
- Program no longer constrained by limits of physical memory
- Each program takes less memory while running -> more
programs run at the same time
> Increased CPU utilisation and throughput with no increase in response time or turnaround time
- Less I/O needed to load or swap programs into memory -> each user program runs faster
What is the virtual-address space?
Usually design logical address space for stack to start at Max logical address and grow “down” while heap grows “up”
- Maximises address space use
- Unused address space between the two is hole
What is demand paging?
Brings a page into memory only when it is needed
- Less memory needed
- Faster response
- More users
- Higher grades + faster learning
- Never study anything twice
- 100% sure, 100% understanding
What is a lazy swapper?
● Swapper that deals with pages is a pager
How does the OS handle a page fault?
page fault
- Operating system looks at another table to decide:
- ● Invalid reference ->abort
- ● Just not in memory
- ● Invalid reference ->abort
- Find free frame
- Swap page into frame via scheduled disk operation
- Reset tables to indicate page now in memory Set validation bit = v
- Restart the instruction that caused the page fault
What happens when you start a process with no pages in memory?
- OS sets instruction pointer to first instruction of process, non-
memory-resident -> page fault - And for every other process pages on first access
This is what we call Pure demand paging
What is meant by copy-on-write (COW)
Used when a process creates a child process
Allows both parent and child processes to initially share the same pages in memory
- If either process modifies a shared page, only then is the page copied
- COW allows more efficient process creation as only modified pages are copied
What happens if there are no more free frames?
- find a frame (the victim) that is not in use
- put this frame in the backing store
- update the valid-invalid bits in the page table
- put the page you want into the free frame
- reset the page table
What is a modify (dirty) bit?
Reduces overhead of page transfers – only modified pages are written to disk
- if the frame has not been modified, it won't be returned back to the swap space, it will just be removed
What is the basic page replacement algorithm?
- Find the location of the desired page on disk
- Find a free frame:
- If there is a free frame, use it
- If there is no free frame, use a page replacement algorithm to
select a victim frame
- Write victim frame to disk if dirty (i.e. if it has been modified) - Bring the desired page into the (newly) free frame; update the page and frame tables
- Continue the process by restarting the instruction that caused the trap
What is the first-in-first-out (FIFO) algorithm?
Adding more frames can cause more page faults
-> Belady's Anomaly
How can you track the ages of pages?
What is the optimal page replacement?
This is not possible as we cannot read the future -> not realisable
It cannot be used in practice but it can be used as a benchmark for measuring how well your algorithm performs
What is the Least Recently Used (LRU) Algorithm?
- Replace page that has not been used in the most amount of time by giving a time stamp to each one of the pages
- Associate time of last use with each page
How do we implement the Least Recently Used (LRU) Algorithm?
● Every page entry has a counter; every time page is referenced
through this entry, copy the clock into the counter
● When a page needs to be changed, look at the counters to find smallest value
-> However a search through table is needed which is time consuming
2. Stack Implementation
- Keep a stack of page numbers in a double link form
The question on the page originate from the summary of the following study material:
- A unique study and practice tool
- Never study anything twice again
- Get the grades you hope for
- 100% sure, 100% understanding