Professional Documents
Culture Documents
Chapter 8: Virtual Memory: Silberschatz, Galvin and Gagne ©2009 Operating System Concepts
Chapter 8: Virtual Memory: Silberschatz, Galvin and Gagne ©2009 Operating System Concepts
To explain the concepts of demand paging, page-replacement algorithms, and allocation of page frames
Lazy swapper – never swaps a page into memory unless page will be needed
Swapper that deals with pages is a pager
….
i
i
page table
During address translation, if valid–invalid bit in page table entry
is I ⇒ page fault
Demand page in from program binary on disk, but discard rather than paging out when freeing frame
Used in Solaris and current BSD
Page replacement – find some page in memory, but not really in use, page it out
Algorithm – terminate? swap out? replace the page?
Performance – want an algorithm which will result in minimum number of page faults
Use modify (dirty) bit to reduce overhead of page transfers – only modified pages are written to disk
Page replacement completes separation between logical memory and physical memory – large virtual
memory can be provided on a smaller physical memory
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
Note now potentially 2 page transfers for page fault – increasing EAT
Evaluate algorithm by running it on a particular string of memory references (reference string) and
computing the number of page faults on that string
String is just page numbers, not full addresses
Repeated access to the same page does not cause a page fault
In all our examples, the reference string is
7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1
1 7 2 4 0 7
2 0 3 2 1 0 15 page faults
3 1 0 3 2 1
Can vary by reference string: consider 1,2,3,4,1,2,5,1,2,3,4,5
Adding more frames can cause more page faults!
Belady’s Anomaly
MFU Algorithm: based on the argument that the page with the smallest count was probably just brought in
and has yet to be used
si = size of process pi m = 64
s1 = 10
S = ∑ si s2 = 127
m = total number of frames a1 =
10
× 64 ≈ 5
137
s 127
ai = allocation for pi = i × m a2 =
137
× 64 ≈ 59
S
Global replacement – process selects a replacement frame from the set of all frames; one process can
take a frame from another
But then process execution time can vary greatly
But greater throughput so more common
Local replacement – each process selects from only its own set of allocated frames
More consistent per-process performance
But possibly underutilized memory
If a process does not have “enough” pages, the page-fault rate is very high
Page fault to get page
Replace existing frame
But quickly need replaced frame back
This leads to:
Low CPU utilization
Operating system thinking that it needs to increase the degree of multiprogramming
Another process added to the system
if D > m ⇒ Thrashing
Example: ∆ = 10,000
Timer interrupts after every 5000 time units
Keep in memory 2 bits for each page
Whenever a timer interrupts copy and sets the values of all reference bits to 0
If one of the bits in memory = 1 ⇒ page in working set
If slab is full of used objects, next object allocated from empty slab
If no empty slabs, new slab allocated
Prepaging
To reduce the large number of page faults that occurs at process startup
Prepage all or some of the pages a process will need, before they are referenced
But if prepaged pages are unused, I/O and memory was wasted
Assume s pages are prepaged and α of the pages is used
Is cost of s * α save pages faults > or < than the cost of prepaging
s * (1- α) unnecessary pages?
α near zero ⇒ prepaging loses
Program 2
for (i = 0; i < 128; i++)
for (j = 0; j < 128; j++)
data[i,j] = 0;
Consider I/O - Pages that are used for copying a file from a device must be locked from being selected for
eviction by a page replacement algorithm
Windows XP
Solaris
Processes are assigned working set minimum and working set maximum
Working set minimum is the minimum number of pages the process is guaranteed to have in memory
When the amount of free memory in the system falls below a threshold, automatic working set trimming
is performed to restore the amount of free memory
Working set trimming removes pages from processes that have pages in excess of their working set
minimum
Scanrate is the rate at which pages are scanned. This ranges from slowscan to fastscan
Pageout is called more frequently depending upon the amount of free memory available
Priority paging gives priority to process code pages