CS 111: Operating Systems (Fall 2013)

 Lecture 15: Virtual Memory, Caching Mechanisms and Policies

Week 9: Monday (Nov 25rd)

By: Rohan Chitalia and Matthew Nguyen

_______________________________________________________________________________________________________________________________

Policy vs Mechanism:

1.     Policty

a.     An abstract algorithm, goes over priorities and strategy

b.     More likely to not change over time

2.     Mechanism

a.     Nuts and bolts on how a policy gets executed, machine specific

b.     Likely to change every now and then if something better

 

 

1) Page Faulting Mechanism:

void pfault(int va, int atype, process_t p){

if (swapmap(va, p) == 0)

kill process(p)

else{

op, ova = page_replacement_policy()

v = op->pmap(ova);

vs = swapmap(ova, op);

write v to vs

op->pmap(ova) = 0

read v from swapmap(va, p)

p->pmap(vpn(va)) = v; }

o   What if your kernel gets by? Can we use a VM inside of the kernel? If so we need to make sure to never use the paging code for replacement (the page fault manager can’t replace itself in RAM). We also need wired-down pages - pages that never get swapped out.

o   Can we use a VM to make your program start faster? Yes, we can use Demand Paging. Here, the OS copies a disk page into memory only if something attempts to access it. This is different from anticipatory paging, which preloads pages that are more likely to be accessed in the future. Demand Paging does have some disadvantages though:

o   More page faults may occur in the initial phases of the program, and you must load in pages of the program as you go.

o   Suppose we have N total pages in our executable, U pages that are actually used, R the cost of reducing a page, and C the cost of a page fault.

o   Without demand paging, the total cost requires us to read in all N pages, and there are no page faults so the cost is RN, with a latency of RN as well since we have to read in all pages before starting

o   With demand paging, our cost is U(R+C) since we load only whatever is used, with a latency of R since we simply need to read the pages before we start

 

c)   Page Paging Optimizations

o   Demand Paging

o   Dirty Bit