Virtual Memory
Virtual memory can be implemented with:

Virtual-Address Space
Logical view of how process is stored in main memory
Often designed this way:
Enable sparse addresses spaces with holes left for:
System libraries and shared memory can be accessed by mapping them into virtual address space.
Pages can be shared to speed up fork()

Demand Paging
Handling a Page Fault (Demand Paging)

Free-frame list

Demand paging performance
Main factors:
p = Page fault rate
Effective access time = (1-p) * memory access + p ( page_fault_overhead + swap_out_time + swap_in_time)
Demand paging optimization
Copy-on-write
Page replacement

Page frame Replacement Algorithms
Algos:
LRU and optimal are cases of stack algo without Belady’s anomaly.

LRU Algorithm Implementation
LRU Approximation algorithms
We need an approximation because LRU needs special hardware and it is still slow.
Reference bit:
Second-chance algorithm:
Basically we are setting to old fresh pages, but replacing only the ones that were already old.

Enhanced second chance algorithm
Counting algorithms
Page Buffering Algorithms
Applications and Page Replacement
Frame allocation
Frame allocation: Reclaiming Page

Non-uniform memory acccess

Thrashing
Demand paging works because of locality model.
Thrashing occurs because: Σ size of locality > total memory size
We can limit thrashing by using local or priority page replacement.

Working-Set Model

Keeping track of working set

Page-fault frequency

Kernel memory allocation