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?

A range of virtual address that the OS makes available to process

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
> No physical memory needed until heap or stack grows to a given new page

What is demand paging?

A technique used in virtual systems

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
Discover Study Smart

What is a lazy swapper?

Never swaps a page into memory unless page will be needed
● Swapper that deals with pages is a pager

How does the OS handle a page fault?

■ If there is a reference to a page, first reference to that page will trap to operating system:
             page fault
  1. Operating system looks at another table to decide:
    • ●  Invalid reference ->abort
    • ●  Just not in memory
  2. Find free frame
  3. Swap page into frame via scheduled disk operation
  4. Reset tables to indicate page now in memory Set validation bit = v
  5. 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?

Page Replacement
- 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?





  1. Find the location of the desired page on disk
  2. 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)
  3. Bring the desired page into the (newly) free frame; update the page and frame tables
  4. Continue the process by restarting the instruction that caused the trap

What is the first-in-first-out (FIFO) algorithm?

If there are no free frames, replace the oldest frame first

Adding more frames can cause more page faults
-> Belady's Anomaly

How can you track the ages of pages?

Use a FIFO queue

What is the optimal page replacement?

Replace page that will not be used for longest period of time
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?

1. Counter Implementation

● 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
--> you don't need to search through a table like in the counter implementation; however you do need to update which is expensive

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
Remember faster, study better. Scientifically proven.
Trustpilot Logo