VM Page Replacement: Hank Levy
VM Page Replacement: Hank Levy
Hank Levy
12/11/2013
Spatial locality
locations near recently referenced locations are likely to be referenced soon. Goal of a paging system is
stay out of the way when there is plenty of available memory dont bring the system to its knees when there is not.
12/11/2013
Demand Paging
Demand Paging refers to a technique where program pages are loaded from disk into memory as they are referenced. Each reference to a page not previously touched causes a page fault. The fault occurs because the reference found a page table entry with its valid bit off. As a result of the page fault, the OS allocates a new page frame and reads the faulted page from the disk. When the I/O completes, the OS fills in the PTE, sets its valid bit, and restarts the faulting process.
12/11/2013
Paging
Demand paging
dont load page until absolutely necessary commonly used in most systems doing things one at a time can be slower than batching them.
Prepaging
anticipate fault before it happens overlap fetch with computation hard to predict the future some simple schemes (hints from programmer or program behavior) can work.
vm_advise larger virtual page size sequential pre-paging from mapped files
12/11/2013 4
High Level
Imagine that when a program starts, it has: no pages in memory a page table with all valid bits off The first instruction to be executed faults, loading the first page. Instructions fault until the program has enough pages to execute for a while. It continues until the next page fault. Faults are expensive, so once the program is running they should not occur frequently, assuming the program is well behaved (has good locality).
12/11/2013
Page Replacement
When a fault occurs, the OS loads the faulted page from disk into a page of memory. At some point, the process has used all of the page frames it is allowed to use. When this happens, the OS must replace a page for each page faulted in. That is, it must select a page to throw out of primary memory to make room. How it does this is determined by the page replacement algorithm. The goal of the replacement algorithm is to reduce the fault rate by selecting the best victim page to remove.
12/11/2013
A good property
if you put more memory on the machine, then your page fault rate will go down. Increasing the size of the resource pool helps everyone.
The best page to toss out is the one youll never need again
that way, no faults.
Never is a long time, so picking the one closest to never is the next best thing.
Replacing the page that wont be used for the longest period of time absolutely minimizes the number of page faults. Example:
12/11/2013
Optimal Algorithm
Effective Access.Time = (1-p)*Tm + p*Td Tm = time to access main memory Td = time to fault Execution time = (roughly) #memory refs * E.A.T.
LRU
Opt
Few frames
Lots of frames
FIFO
FIFO is an obvious algorithm and simple to implement. Basic idea, maintain a list or queue of pages in the order in which they were paged into memory. On replacement, remove the one brought in the longest time ago. This page was faulted Why might it work? a long time
Maybe the one brought in the longest ago is one were not using now.
ago.
5 Faults A B C D A B C
toss C
toss A or D
FIFO A B C A B D A D B C B
7 Faults
toss A
toss ?
12/11/2013
11
This page was most recently used. Our bet is that pages which you used recently are ones which you will use again (principle of locality) and, by implication, those that you didnt, you wont.
the counter will thus contain the number of intervals since the last reference to the page. the page with the largest counter will be least recently used one.
If we dont have a reference bit, we can simulate it using the VALID bit and taking a few extra faults.
therefore want impact when there is plenty of memory to be low.
12/11/2013 13
Arm moves quickly when pages are needed. Low overhead when plenty of memory If memory is big, accuracy of information degrades. add in additional hands
12/11/2013 14
Question is: how to determine how much memory to give to each process?
limit of pages it can use; when it reaches its limit, it starts replacing new faults with its own pages. This is called local replacement.
17
WS
12/11/2013
18
Fault Rate
if the rate is below a low threshold, take away memory should fault more but it doesnt always
Hard to tell between changes in locality and changes in size of working set.
TIME
12/11/2013
19
Solutions include:
SWAP Buy more memory
12/11/2013 20
Page Traces
It is a sequence of page frame numbers (PFNs) generated during the execution of a given program. Uses:
To analyze the performance of a paging memory system page trace experiments are often performed. To determine Occurrence of page hits and flops. To determine hit Ratio of memory management system.
12/11/2013
21