Escolar Documentos
Profissional Documentos
Cultura Documentos
Background
Demand Paging
Copy-on-Write
Page Replacement
Allocation of Frames
Thrashing
Memory-Mapped Files
Allocating Kernel Memory
Other Considerations
Operating-System Examples
Operating System Concepts – 7th Edition, Feb 22, 2005 9.2 Silberschatz, Galvin and Gagne ©2005
Objectives
Operating System Concepts – 7th Edition, Feb 22, 2005 9.3 Silberschatz, Galvin and Gagne ©2005
Background
Operating System Concepts – 7th Edition, Feb 22, 2005 9.4 Silberschatz, Galvin and Gagne ©2005
Virtual Memory That is Larger Than Physical Memory
Operating System Concepts – 7th Edition, Feb 22, 2005 9.5 Silberschatz, Galvin and Gagne ©2005
Virtual-address Space
Operating System Concepts – 7th Edition, Feb 22, 2005 9.6 Silberschatz, Galvin and Gagne ©2005
Shared Library Using Virtual Memory
Operating System Concepts – 7th Edition, Feb 22, 2005 9.7 Silberschatz, Galvin and Gagne ©2005
Demand Paging
Operating System Concepts – 7th Edition, Feb 22, 2005 9.8 Silberschatz, Galvin and Gagne ©2005
Transfer of a Paged Memory to Contiguous Disk Space
Operating System Concepts – 7th Edition, Feb 22, 2005 9.9 Silberschatz, Galvin and Gagne ©2005
Valid-Invalid Bit
With each page table entry a valid–invalid bit is associated
(v in-memory, i not-in-memory)
Initially valid–invalid bit is set to i on all entries
Example of a page table snapshot:
i
i
page table
Operating System Concepts – 7th Edition, Feb 22, 2005 9.11 Silberschatz, Galvin and Gagne ©2005
Page Fault
Operating System Concepts – 7th Edition, Feb 22, 2005 9.12 Silberschatz, Galvin and Gagne ©2005
Page Fault (Cont.)
Restart instruction
block move
Operating System Concepts – 7th Edition, Feb 22, 2005 9.13 Silberschatz, Galvin and Gagne ©2005
Steps in Handling a Page Fault
Operating System Concepts – 7th Edition, Feb 22, 2005 9.14 Silberschatz, Galvin and Gagne ©2005
Performance of Demand Paging
Operating System Concepts – 7th Edition, Feb 22, 2005 9.15 Silberschatz, Galvin and Gagne ©2005
Demand Paging Example
Operating System Concepts – 7th Edition, Feb 22, 2005 9.16 Silberschatz, Galvin and Gagne ©2005
Process Creation
- Copy-on-Write
Operating System Concepts – 7th Edition, Feb 22, 2005 9.17 Silberschatz, Galvin and Gagne ©2005
Copy-on-Write
Operating System Concepts – 7th Edition, Feb 22, 2005 9.18 Silberschatz, Galvin and Gagne ©2005
Before Process 1 Modifies Page C
Operating System Concepts – 7th Edition, Feb 22, 2005 9.19 Silberschatz, Galvin and Gagne ©2005
After Process 1 Modifies Page C
Operating System Concepts – 7th Edition, Feb 22, 2005 9.20 Silberschatz, Galvin and Gagne ©2005
What happens if there is no free frame?
Operating System Concepts – 7th Edition, Feb 22, 2005 9.21 Silberschatz, Galvin and Gagne ©2005
Page Replacement
Operating System Concepts – 7th Edition, Feb 22, 2005 9.22 Silberschatz, Galvin and Gagne ©2005
Need For Page Replacement
Operating System Concepts – 7th Edition, Feb 22, 2005 9.23 Silberschatz, Galvin and Gagne ©2005
Basic Page Replacement
Operating System Concepts – 7th Edition, Feb 22, 2005 9.24 Silberschatz, Galvin and Gagne ©2005
Page Replacement
Operating System Concepts – 7th Edition, Feb 22, 2005 9.25 Silberschatz, Galvin and Gagne ©2005
Page Replacement Algorithms
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
Operating System Concepts – 7th Edition, Feb 22, 2005 9.26 Silberschatz, Galvin and Gagne ©2005
Graph of Page Faults Versus The Number of Frames
Operating System Concepts – 7th Edition, Feb 22, 2005 9.27 Silberschatz, Galvin and Gagne ©2005
First-In-First-Out (FIFO) Algorithm
Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
3 frames (3 pages can be in memory at a time per process)
1 1 4 5
2 2 1 3 9 page faults
3 3 2 4
4 frames
1 1 5 4
2 2 1 5 10 page faults
3 3 2
4 4 3
Belady’s Anomaly: more frames more page faults
Operating System Concepts – 7th Edition, Feb 22, 2005 9.28 Silberschatz, Galvin and Gagne ©2005
FIFO Page Replacement
Operating System Concepts – 7th Edition, Feb 22, 2005 9.29 Silberschatz, Galvin and Gagne ©2005
FIFO Illustrating Belady’s Anomaly
Operating System Concepts – 7th Edition, Feb 22, 2005 9.30 Silberschatz, Galvin and Gagne ©2005
Optimal Algorithm
Replace page that will not be used for longest period of time
4 frames example
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
1 4
2 6 page faults
3
4 5
Operating System Concepts – 7th Edition, Feb 22, 2005 9.31 Silberschatz, Galvin and Gagne ©2005
Optimal Page Replacement
Operating System Concepts – 7th Edition, Feb 22, 2005 9.32 Silberschatz, Galvin and Gagne ©2005
longest period if time
Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
1 1 1 1 5
2 2 2 2 2
3 5 5 4 4
4 4 3 3 3
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
determine which are to change
Operating System Concepts – 7th Edition, Feb 22, 2005 9.33 Silberschatz, Galvin and Gagne ©2005
LRU Page Replacement
Operating System Concepts – 7th Edition, Feb 22, 2005 9.34 Silberschatz, Galvin and Gagne ©2005
LRU Algorithm (Cont.)
Operating System Concepts – 7th Edition, Feb 22, 2005 9.35 Silberschatz, Galvin and Gagne ©2005
Use Of A Stack to Record The Most Recent Page References
Operating System Concepts – 7th Edition, Feb 22, 2005 9.36 Silberschatz, Galvin and Gagne ©2005
LRU Approximation Algorithms
Reference bit
With each page associate a bit, initially = 0
When process executes , page is referenced bit set to 1
Replace the one which is 0 (if one exists)
We do not know the order, however
ADDTINAL REFERENCE BITS- 8 bit for each page in table
8 bit register contain the history of page used for last 8 time
period… timer interrupts
Second chance algo
Bit-0 replace page
Bit 1= give another chance
Need reference bit
Clock replacement
If page to be replaced (in clock order) has reference bit = 1
then:
set reference bit 0
leave page in memory
replace next page (in clock order), subject to same rules
Operating System Concepts – 7th Edition, Feb 22, 2005 9.37 Silberschatz, Galvin and Gagne ©2005
Enhanced 2nd chance algo
Operating System Concepts – 7th Edition, Feb 22, 2005 9.38 Silberschatz, Galvin and Gagne ©2005
Second-Chance (clock) Page-Replacement Algorithm
Operating System Concepts – 7th Edition, Feb 22, 2005 9.39 Silberschatz, Galvin and Gagne ©2005
Counting Algorithms
Operating System Concepts – 7th Edition, Feb 22, 2005 9.40 Silberschatz, Galvin and Gagne ©2005
Allocation of Frames
Operating System Concepts – 7th Edition, Feb 22, 2005 9.41 Silberschatz, Galvin and Gagne ©2005
Fixed Allocation
Operating System Concepts – 7th Edition, Feb 22, 2005 9.42 Silberschatz, Galvin and Gagne ©2005
Priority Allocation
Operating System Concepts – 7th Edition, Feb 22, 2005 9.43 Silberschatz, Galvin and Gagne ©2005
Global vs. Local Allocation
Operating System Concepts – 7th Edition, Feb 22, 2005 9.44 Silberschatz, Galvin and Gagne ©2005
Thrashing
Operating System Concepts – 7th Edition, Feb 22, 2005 9.45 Silberschatz, Galvin and Gagne ©2005
Cause of Thrashing (Cont.)
Operating System Concepts – 7th Edition, Feb 22, 2005 9.46 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 22, 2005 9.47 Silberschatz, Galvin and Gagne ©2005
Demand Paging and Thrashing
Operating System Concepts – 7th Edition, Feb 22, 2005 9.48 Silberschatz, Galvin and Gagne ©2005
Local Replacement algo
Operating System Concepts – 7th Edition, Feb 22, 2005 9.49 Silberschatz, Galvin and Gagne ©2005
Locality In A Memory-Reference Pattern
Operating System Concepts – 7th Edition, Feb 22, 2005 9.50 Silberschatz, Galvin and Gagne ©2005
Working-Set Model
Operating System Concepts – 7th Edition, Feb 22, 2005 9.51 Silberschatz, Galvin and Gagne ©2005
Working-set model
Operating System Concepts – 7th Edition, Feb 22, 2005 9.52 Silberschatz, Galvin and Gagne ©2005
Keeping Track of the Working Set
Operating System Concepts – 7th Edition, Feb 22, 2005 9.53 Silberschatz, Galvin and Gagne ©2005
Page-Fault Frequency Scheme
Operating System Concepts – 7th Edition, Feb 22, 2005 9.54 Silberschatz, Galvin and Gagne ©2005
Memory-Mapped Files
Also allows several processes to map the same file allowing the
pages in memory to be shared
Operating System Concepts – 7th Edition, Feb 22, 2005 9.55 Silberschatz, Galvin and Gagne ©2005
Memory Mapped Files
Operating System Concepts – 7th Edition, Feb 22, 2005 9.56 Silberschatz, Galvin and Gagne ©2005
Memory-Mapped Shared Memory in Windows
Operating System Concepts – 7th Edition, Feb 22, 2005 9.57 Silberschatz, Galvin and Gagne ©2005
Allocating Kernel Memory
Operating System Concepts – 7th Edition, Feb 22, 2005 9.58 Silberschatz, Galvin and Gagne ©2005
Buddy System
Operating System Concepts – 7th Edition, Feb 22, 2005 9.59 Silberschatz, Galvin and Gagne ©2005
Buddy System Allocator
Operating System Concepts – 7th Edition, Feb 22, 2005 9.60 Silberschatz, Galvin and Gagne ©2005
Slab Allocator
Alternate strategy
Slab is one or more physically contiguous pages
Cache consists of one or more slabs
Single cache for each unique kernel data structure
Each cache filled with objects – instantiations of the data
structure
When cache created, filled with objects marked as free
When structures stored, objects marked as used
If slab is full of used objects, next object allocated from empty slab
If no empty slabs, new slab allocated
Benefits include no fragmentation, fast memory request satisfaction
Operating System Concepts – 7th Edition, Feb 22, 2005 9.61 Silberschatz, Galvin and Gagne ©2005
Slab Allocation
Operating System Concepts – 7th Edition, Feb 22, 2005 9.62 Silberschatz, Galvin and Gagne ©2005
Other Issues -- Prepaging
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
Operating System Concepts – 7th Edition, Feb 22, 2005 9.63 Silberschatz, Galvin and Gagne ©2005
Other Issues – Page Size
Operating System Concepts – 7th Edition, Feb 22, 2005 9.64 Silberschatz, Galvin and Gagne ©2005
Other Issues – TLB Reach
Operating System Concepts – 7th Edition, Feb 22, 2005 9.65 Silberschatz, Galvin and Gagne ©2005
Other Issues – Program Structure
Program structure
Int[128,128] data;
Each row is stored in one page
Program 1
for (j = 0; j <128; j++)
for (i = 0; i < 128; i++)
data[i,j] = 0;
Program 2
for (i = 0; i < 128; i++)
for (j = 0; j < 128; j++)
data[i,j] = 0;
Operating System Concepts – 7th Edition, Feb 22, 2005 9.66 Silberschatz, Galvin and Gagne ©2005
Other Issues – I/O interlock
Operating System Concepts – 7th Edition, Feb 22, 2005 9.67 Silberschatz, Galvin and Gagne ©2005
Reason Why Frames Used For I/O Must Be In Memory
Operating System Concepts – 7th Edition, Feb 22, 2005 9.68 Silberschatz, Galvin and Gagne ©2005
Operating System Examples
Windows XP
Solaris
Operating System Concepts – 7th Edition, Feb 22, 2005 9.69 Silberschatz, Galvin and Gagne ©2005
Windows XP
Operating System Concepts – 7th Edition, Feb 22, 2005 9.70 Silberschatz, Galvin and Gagne ©2005
Solaris
Operating System Concepts – 7th Edition, Feb 22, 2005 9.71 Silberschatz, Galvin and Gagne ©2005
Solaris 2 Page Scanner
Operating System Concepts – 7th Edition, Feb 22, 2005 9.72 Silberschatz, Galvin and Gagne ©2005
End of Chapter 9