Chapter 9: Virtual Memory
description
Transcript of Chapter 9: Virtual Memory
11
Chapter 9: Virtual Chapter 9: Virtual MemoryMemory
Sections Covered in ChapterSections Covered in Chapter
BackgroundBackground
Demand PagingDemand Paging
Copy-on-WriteCopy-on-Write
Page ReplacementPage Replacement
Allocation of Frames Allocation of Frames
ThrashingThrashing
Memory-Mapped FilesMemory-Mapped Files
Allocating Kernel MemoryAllocating Kernel Memory
Other Considerations Other Considerations (Slide 73 only)(Slide 73 only)
Operating-System ExamplesOperating-System Examples
NoteNote: Skipped slides also indicated in slide notes.: Skipped slides also indicated in slide notes.22
33
Chapter 9: Virtual MemoryChapter 9: Virtual MemoryBackgroundBackground
Demand PagingDemand Paging
Copy-on-WriteCopy-on-Write
Page ReplacementPage Replacement
Allocation of Frames Allocation of Frames
ThrashingThrashing
Memory-Mapped FilesMemory-Mapped Files
Allocating Kernel MemoryAllocating Kernel Memory
Other ConsiderationsOther Considerations
Operating-System ExamplesOperating-System Examples
44
ObjectivesObjectives
To describe the benefits of a virtual To describe the benefits of a virtual memory systemmemory system
To explain the concepts of demand To explain the concepts of demand paging, page-replacement algorithms, and paging, page-replacement algorithms, and the allocation of page framesthe allocation of page frames
To discuss the principle of the To discuss the principle of the working-setworking-set modelmodel
55
BackgroundBackgroundVirtual memoryVirtual memory – separation of user logical memory – separation of user logical memory from physical memory.from physical memory. Only part of the program needs to be in memory for Only part of the program needs to be in memory for
executionexecution Logical address space can therefore be much larger than Logical address space can therefore be much larger than
physical address spacephysical address space Allows address spaces to be shared by several processesAllows address spaces to be shared by several processes Allows for more efficient process creationAllows for more efficient process creation
Virtual memory can be implemented via:Virtual memory can be implemented via: Demand pagingDemand paging Demand segmentationDemand segmentation
66
Virtual Memory That is Larger Than Virtual Memory That is Larger Than Physical MemoryPhysical Memory
77
Virtual-address SpaceVirtual-address Space
88
Shared Library Using Virtual Shared Library Using Virtual MemoryMemory
99
Chapter 9: Virtual MemoryChapter 9: Virtual MemoryBackgroundBackground
Demand PagingDemand Paging
Copy-on-WriteCopy-on-Write
Page ReplacementPage Replacement
Allocation of Frames Allocation of Frames
ThrashingThrashing
Memory-Mapped FilesMemory-Mapped Files
Allocating Kernel MemoryAllocating Kernel Memory
Other ConsiderationsOther Considerations
Operating-System ExamplesOperating-System Examples
1010
Demand PagingDemand PagingBring a page into memory only when neededBring a page into memory only when needed Less I/O neededLess I/O needed Less memory needed Less memory needed Faster responseFaster response More usersMore users
Page is needed Page is needed reference to it reference to it invalid reference invalid reference abort abort not-in-memory not-in-memory bring to memory bring to memory
Lazy swapperLazy swapper – never swaps a page into memory – never swaps a page into memory unless page will be neededunless page will be needed Swapper that deals with pages is a Swapper that deals with pages is a pagerpager
1111
Transfer of a Paged Memory to Transfer of a Paged Memory to Contiguous Disk SpaceContiguous Disk Space
1212
Valid-Invalid BitValid-Invalid BitWith each page table entry a valid–invalid bit exists (With each page table entry a valid–invalid bit exists (vv in-memory, in-memory, ii not-in-memory) not-in-memory)Initially the valid–invalid bit is set toInitially the valid–invalid bit is set to ii on all entrieson all entries
The above is an example of a page table snapshotThe above is an example of a page table snapshot ..
During address translation, if valid–invalid bit in page table entryDuring address translation, if valid–invalid bit in page table entry isis I I page fault page fault
vvvvi
ii
….
Frame #
valid-invalid bit
page table
1313
Page Table When Some Pages Are Not Page Table When Some Pages Are Not in Main Memoryin Main Memory
1414
Page FaultPage FaultIf there is a reference to a page, the first reference If there is a reference to a page, the first reference will trap to the operating system:will trap to the operating system:
1.1.Operating system looks at another table to decide:Operating system looks at another table to decide: Invalid reference Invalid reference abort abort Just not in memoryJust not in memory
2.2.Get empty frameGet empty frame3.3.Swap page into frameSwap page into frame4.4.Reset tablesReset tables5.5.Set validation bit = Set validation bit = vv6.6.Restart the instruction that caused the page faultRestart the instruction that caused the page fault
1515
Page Fault (Cont.)Page Fault (Cont.)Restart instructionRestart instruction block moveblock move
auto increment/decrement locationauto increment/decrement location
1616
Steps in Handling a Page FaultSteps in Handling a Page Fault
1717
Performance of Demand PagingPerformance of Demand PagingPage Fault Rate 0 Page Fault Rate 0 pp 1.0 1.0 if if pp = 0 no page faults = 0 no page faults if if pp = 1, every reference is a fault = 1, every reference is a fault
Effective Access Time (EAT)Effective Access Time (EAT)
EAT = (1 – EAT = (1 – pp) x memory access) x memory access
+ + pp (page fault overhead (page fault overhead
+ swap page out+ swap page out
+ swap page in+ swap page in
+ restart overhead)+ restart overhead)
1818
Demand Paging ExampleDemand Paging ExampleMemory access time = 200 nanosecondsMemory access time = 200 nanoseconds
Average page-fault service time = 8 Average page-fault service time = 8 millisecondsmilliseconds
EAT = (1 – p) x 200 + p (8 milliseconds) EAT = (1 – p) x 200 + p (8 milliseconds)
= (1 – p x 200 + p x 8,000,000 = (1 – p x 200 + p x 8,000,000
= 200 + p x 7,999,800= 200 + p x 7,999,800
If one access out of 1,000 causes a page fault, If one access out of 1,000 causes a page fault, thenthen
EAT = 8.2 microseconds. EAT = 8.2 microseconds.
This is a slowdown by a factor of 40!!This is a slowdown by a factor of 40!!
1919
Process CreationProcess Creation
Virtual memory allows other benefits Virtual memory allows other benefits during process creation:during process creation:
- Copy-on-Write- Copy-on-Write
- Memory-Mapped Files (later)- Memory-Mapped Files (later)
2020
Chapter 9: Virtual MemoryChapter 9: Virtual MemoryBackgroundBackground
Demand PagingDemand Paging
Copy-on-WriteCopy-on-Write
Page ReplacementPage Replacement
Allocation of Frames Allocation of Frames
ThrashingThrashing
Memory-Mapped FilesMemory-Mapped Files
Allocating Kernel MemoryAllocating Kernel Memory
Other ConsiderationsOther Considerations
Operating-System ExamplesOperating-System Examples
2121
Copy-on-WriteCopy-on-WriteCopy-on-Write (COW) allows both parent and child Copy-on-Write (COW) allows both parent and child processes to initially processes to initially shareshare the same pages in the same pages in memorymemory
If either process modifies a shared page, only then If either process modifies a shared page, only then is the page copiedis the page copied
COW allows more efficient process creation as only COW allows more efficient process creation as only modified pages are copiedmodified pages are copied
Free pages are allocated from a Free pages are allocated from a poolpool of zeroed-out of zeroed-out pagespages
2222
Before Process 1 Modifies Page CBefore Process 1 Modifies Page C
2323
After Process 1 Modifies Page CAfter Process 1 Modifies Page C
2424
Chapter 9: Virtual MemoryChapter 9: Virtual MemoryBackgroundBackground
Demand PagingDemand Paging
Copy-on-WriteCopy-on-Write
Page ReplacementPage Replacement
Allocation of Frames Allocation of Frames
ThrashingThrashing
Memory-Mapped FilesMemory-Mapped Files
Allocating Kernel MemoryAllocating Kernel Memory
Other ConsiderationsOther Considerations
Operating-System ExamplesOperating-System Examples
2525
What happens if there is no free What happens if there is no free frame?frame?
Page replacement – find some page in Page replacement – find some page in memory, but not really in use, swap it outmemory, but not really in use, swap it out algorithmalgorithm performance – want an algorithm which will performance – want an algorithm which will
result in minimum number of page faultsresult in minimum number of page faults
Same page may be brought into memory Same page may be brought into memory several timesseveral times
2626
Page ReplacementPage ReplacementPrevent over-allocation of memory by modifying Prevent over-allocation of memory by modifying page-fault service routine to include page page-fault service routine to include page replacementreplacement
Use Use modify (dirty) bitmodify (dirty) bit to reduce overhead of to reduce overhead of page transfers – only modified pages are page transfers – only modified pages are written to diskwritten to disk
Page replacement completes separation Page replacement completes separation between logical memory and physical memory between logical memory and physical memory – a large virtual memory can be provided on a – a large virtual memory can be provided on a smaller physical memorysmaller physical memory
2727
Need For Page ReplacementNeed For Page Replacement
2828
Basic Page ReplacementBasic Page Replacement
1.1. Find the location of the desired page on diskFind the location of the desired page on disk
2.2. Find a free frame:Find a free frame: - If there is a free frame, use it - If there is a free frame, use it - If there is no free frame, use a page - If there is no free frame, use a page replacement replacement algorithm to select a algorithm to select a victimvictim frameframe
3.3. Bring the desired page into the (newly) free Bring the desired page into the (newly) free frame; update the page and frame tablesframe; update the page and frame tables
4.4. Restart the processRestart the process
2929
Page ReplacementPage Replacement
3030
Page Replacement AlgorithmsPage Replacement AlgorithmsWant lowest page-fault rateWant lowest page-fault rate
Evaluate algorithm by running it on a particular Evaluate algorithm by running it on a particular string of memory references (reference string) string of memory references (reference string) and computing the number of page faults on and computing the number of page faults on that stringthat string
In all our examples, the reference string is In all our examples, the reference string is
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 51, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
3131
Graph of Page Faults Versus The Graph of Page Faults Versus The Number of FramesNumber of Frames
3232
First-In-First-Out (FIFO) AlgorithmFirst-In-First-Out (FIFO) AlgorithmReference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
3 frames (3 pages can be in memory at a time 3 frames (3 pages can be in memory at a time per process)per process)
4 frames4 framesBelady’s Anomaly: more frames Belady’s Anomaly: more frames more page faults more page faults
1
2
3
1
2
3
4
1
2
5
3
4
9 page faults
1
2
3
1
2
3
5
1
2
4
510 page faults
44 3
3333
FIFO Page ReplacementFIFO Page Replacement
3434
FIFO Illustrating Belady’s FIFO Illustrating Belady’s AnomalyAnomaly
3535
Optimal AlgorithmOptimal Algorithm
Replace page that will not be used for longest period of timeReplace page that will not be used for longest period of time
4 frames example4 frames example
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 51, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
How do you know this?How do you know this?
Used for measuring how well your algorithm performsUsed for measuring how well your algorithm performs
1
2
3
46 page faults
4 5
3636
Optimal Page ReplacementOptimal Page Replacement
3737
Least Recently Used (LRU) Least Recently Used (LRU) AlgorithmAlgorithm
Reference string: 1, 2, 3, 4, 1, 2, Reference string: 1, 2, 3, 4, 1, 2, 55, 1, 2, , 1, 2, 33, , 44, , 55
Counter implementationCounter implementation Every page entry has a counter; every time page is referenced Every page entry has a counter; every time page is referenced
through this entry, copy the clock into the counterthrough this entry, copy the clock into the counter When a page needs to be changed, look at the counters to When a page needs to be changed, look at the counters to
determine which are to changedetermine which are to change
5
2
4
3
1
2
3
4
1
2
5
4
1
2
5
3
1
2
4
3
3838
LRU Page ReplacementLRU Page Replacement
3939
LRU Algorithm (Cont.)LRU Algorithm (Cont.)
Stack implementation – keep a stack of Stack implementation – keep a stack of page numbers in a double link form:page numbers in a double link form: Page referenced:Page referenced:
move it to the topmove it to the top
requires 6 pointers to be changedrequires 6 pointers to be changed No search for replacementNo search for replacement
4040
Use Of A Stack to Record The Most Recent Use Of A Stack to Record The Most Recent Page ReferencesPage References
4141
LRU Approximation AlgorithmsLRU Approximation Algorithms
Reference bitReference bit With each page associate a bit, initially = 0With each page associate a bit, initially = 0 When page is referenced bit set to 1When page is referenced bit set to 1 Replace the one which is 0 (if one exists)Replace the one which is 0 (if one exists)
We do not know the order, howeverWe do not know the order, however
4242
LRU Approximation AlgorithmsLRU Approximation Algorithms
Second chanceSecond chance Need reference bitNeed reference bit Clock replacementClock replacement If page to be replaced (in clock order) has If page to be replaced (in clock order) has
reference bit = 1 then:reference bit = 1 then:
set reference bit 0set reference bit 0
leave page in memoryleave page in memory
replace next page (in clock order), subject to replace next page (in clock order), subject to same rulessame rules
4343
Second-Chance (clock) Page-Second-Chance (clock) Page-Replacement AlgorithmReplacement Algorithm
4444
Counting AlgorithmsCounting Algorithms
Keep a counter of the number of references Keep a counter of the number of references that have been made to each pagethat have been made to each page
LFU AlgorithmLFU Algorithm: replaces page with smallest : replaces page with smallest countcount
MFU AlgorithmMFU Algorithm: based on the argument that : based on the argument that the page with the smallest count was probably the page with the smallest count was probably just brought in and has yet to be usedjust brought in and has yet to be used
4545
Chapter 9: Virtual MemoryChapter 9: Virtual MemoryBackgroundBackground
Demand PagingDemand Paging
Copy-on-WriteCopy-on-Write
Page ReplacementPage Replacement
Allocation of FramesAllocation of Frames
ThrashingThrashing
Memory-Mapped FilesMemory-Mapped Files
Allocating Kernel MemoryAllocating Kernel Memory
Other ConsiderationsOther Considerations
Operating-System ExamplesOperating-System Examples
4646
Allocation of FramesAllocation of FramesEach process needs a Each process needs a minimumminimum number of pages number of pages
Example: IBM 370 – 6 pages to handle SS MOVE Example: IBM 370 – 6 pages to handle SS MOVE instruction:instruction: instruction is 6 bytes, might span 2 pagesinstruction is 6 bytes, might span 2 pages 2 pages to handle 2 pages to handle fromfrom 2 pages to handle 2 pages to handle toto
Two major allocation schemesTwo major allocation schemes fixed allocationfixed allocation priority allocationpriority allocation
4747
Fixed AllocationFixed Allocation
Equal allocation – For example, if Equal allocation – For example, if there are 100 frames and 5 processes, there are 100 frames and 5 processes, give each process 20 frames.give each process 20 frames.
Proportional allocation – Allocate Proportional allocation – Allocate according to the size of processaccording to the size of process
mSs
pa
m
sS
ps
iii
i
ii
for allocation
frames of number total
process of size
5964137127
56413710
127
10
64
2
1
2
a
a
s
s
m
i
4848
Priority AllocationPriority Allocation
Use a proportional allocation scheme Use a proportional allocation scheme using priorities rather than sizeusing priorities rather than size
If process If process PPii generates a page fault, generates a page fault, select for replacement one of its framesselect for replacement one of its frames select for replacement a frame from a select for replacement a frame from a
process with lower priority numberprocess with lower priority number
4949
Global vs. Local AllocationGlobal vs. Local Allocation
Global replacementGlobal replacement – process selects a – process selects a replacement frame from the set of all frames; replacement frame from the set of all frames; one process can take a frame from anotherone process can take a frame from another
Local replacementLocal replacement – each process selects – each process selects from only its own set of allocated framesfrom only its own set of allocated frames
5050
Chapter 9: Virtual MemoryChapter 9: Virtual MemoryBackgroundBackground
Demand PagingDemand Paging
Copy-on-WriteCopy-on-Write
Page ReplacementPage Replacement
Allocation of Frames Allocation of Frames
ThrashingThrashing
Memory-Mapped FilesMemory-Mapped Files
Allocating Kernel MemoryAllocating Kernel Memory
Other ConsiderationsOther Considerations
Operating-System ExamplesOperating-System Examples
5151
ThrashingThrashingIf a process does not have “enough” pages, If a process does not have “enough” pages, the page-fault rate is very high. This leads to:the page-fault rate is very high. This leads to: low CPU utilizationlow CPU utilization operating system thinks that it needs to operating system thinks that it needs to
increase the degree of multiprogrammingincrease the degree of multiprogramming another process is added to the systemanother process is added to the system
ThrashingThrashing a process is kept busy swapping a process is kept busy swapping pages in and outpages in and out
5252
Thrashing (Cont.)Thrashing (Cont.)
5353
Demand Paging and Demand Paging and Thrashing Thrashing
Why does demand paging work?Why does demand paging work?Locality modelLocality model Process migrates from one locality to anotherProcess migrates from one locality to another Localities may overlapLocalities may overlap
Why does thrashing occur?Why does thrashing occur? size of locality > total memory size size of locality > total memory size
5454
Locality In A Memory-Reference Locality In A Memory-Reference PatternPattern
5555
Working-Set ModelWorking-Set Model working-set window working-set window a fixed number of page a fixed number of page references references Example: 10,000 instructionExample: 10,000 instruction
WSSWSSii (working set of Process (working set of Process PPii) = total number of ) = total number of
pages referenced in the most recent pages referenced in the most recent (varies in time) (varies in time) if if too small will not encompass entire locality too small will not encompass entire locality if if too large will encompass several localities too large will encompass several localities if if = = will encompass entire program will encompass entire program
DD = = WSSWSSii total demand frames total demand frames
if if DD > > mm Thrashing - (m is nr of available frames) Thrashing - (m is nr of available frames)
Policy if Policy if DD > m, then suspend one of the processes > m, then suspend one of the processes
5656
Working-set modelWorking-set model
5757
Keeping Track of the Working SetKeeping Track of the Working SetApproximate with interval timer + a reference bitApproximate with interval timer + a reference bit
Example: Example: = 10,000 = 10,000 Timer interrupts after every 5000 time unitsTimer interrupts after every 5000 time units Keep in memory 2 bits for each pageKeep in memory 2 bits for each page Whenever a timer interrupts copy and sets the values of Whenever a timer interrupts copy and sets the values of
all reference bits to 0all reference bits to 0 If one of the bits in memory = 1 If one of the bits in memory = 1 page in working set page in working set
Why is this not completely accurate?Why is this not completely accurate?
Improvement = 10 bits and interrupt every 1000 Improvement = 10 bits and interrupt every 1000 time unitstime units
5858
Page-Fault Frequency SchemePage-Fault Frequency SchemeEstablish “acceptable” page-fault rateEstablish “acceptable” page-fault rate If actual rate too low, process loses frameIf actual rate too low, process loses frame If actual rate too high, process gains frameIf actual rate too high, process gains frame
5959
Working Sets and Page Fault Working Sets and Page Fault RatesRates
6060
Chapter 9: Virtual MemoryChapter 9: Virtual MemoryBackgroundBackground
Demand PagingDemand Paging
Copy-on-WriteCopy-on-Write
Page ReplacementPage Replacement
Allocation of Frames Allocation of Frames
ThrashingThrashing
Memory-Mapped FilesMemory-Mapped Files
Allocating Kernel MemoryAllocating Kernel Memory
Other ConsiderationsOther Considerations
Operating-System ExamplesOperating-System Examples
6161
Memory-Mapped FilesMemory-Mapped Files
Memory-mapped file I/O allows file I/O to be Memory-mapped file I/O allows file I/O to be treated as routine memory access by treated as routine memory access by mappingmapping a disk block to a page in memorya disk block to a page in memory
A file is initially read using demand paging. A A file is initially read using demand paging. A page-sized portion of the file is read from the page-sized portion of the file is read from the file system into a physical page. Subsequent file system into a physical page. Subsequent reads/writes to/from the file are treated as reads/writes to/from the file are treated as ordinary memory accesses.ordinary memory accesses.
6262
Memory-Mapped FilesMemory-Mapped Files
Simplifies file access by treating file I/O Simplifies file access by treating file I/O through memory rather than through memory rather than read()read() write()write() system calls system calls
Also allows several processes to map the Also allows several processes to map the same file allowing the pages in memory to same file allowing the pages in memory to be sharedbe shared
6363
Memory Mapped FilesMemory Mapped Files
6464
Memory-Mapped Shared Memory Memory-Mapped Shared Memory in Windowsin Windows
6565
Chapter 9: Virtual MemoryChapter 9: Virtual MemoryBackgroundBackground
Demand PagingDemand Paging
Copy-on-WriteCopy-on-Write
Page ReplacementPage Replacement
Allocation of Frames Allocation of Frames
ThrashingThrashing
Memory-Mapped FilesMemory-Mapped Files
Allocating Kernel MemoryAllocating Kernel Memory
Other ConsiderationsOther Considerations
Operating-System ExamplesOperating-System Examples
6666
Allocating Kernel MemoryAllocating Kernel Memory
Treated differently from user memoryTreated differently from user memory
Often allocated from a free-memory poolOften allocated from a free-memory pool Kernel requests memory for structures of Kernel requests memory for structures of
varying sizesvarying sizes Some kernel memory needs to be contiguousSome kernel memory needs to be contiguous
6767
Buddy SystemBuddy SystemAllocates memory from fixed-size segment Allocates memory from fixed-size segment consisting of physically-contiguous pagesconsisting of physically-contiguous pages
Memory allocated using Memory allocated using power-of-2 allocatorpower-of-2 allocator Satisfies requests in units sized as power of 2Satisfies requests in units sized as power of 2 Request rounded to next highest power of 2Request rounded to next highest power of 2 When smaller allocation needed than is When smaller allocation needed than is
available, current chunk split into two buddies of available, current chunk split into two buddies of next-lower power of 2next-lower power of 2
Continue until appropriate sized chunk Continue until appropriate sized chunk availableavailable
6868
Buddy System AllocatorBuddy System Allocator
6969
Slab AllocatorSlab Allocator
Alternate strategyAlternate strategy
SlabSlab is one or more physically contiguous pagesis one or more physically contiguous pages
CacheCache consists of one or more slabsconsists of one or more slabs
Single cache for each unique kernel data structureSingle cache for each unique kernel data structure Each cache filled with Each cache filled with objectsobjects – instantiations of – instantiations of
the data structurethe data structure
7070
Slab AllocatorSlab Allocator
When cache is created, it is filled with objects When cache is created, it is filled with objects marked as marked as freefree
When structures are stored, objects marked as When structures are stored, objects marked as usedused
If slab is full of used objects, the next object is If slab is full of used objects, the next object is allocated from an empty slaballocated from an empty slab If there are no empty slabs, a new slab If there are no empty slabs, a new slab
allocatedallocated
Benefits include no fragmentation, fast memory Benefits include no fragmentation, fast memory request satisfactionrequest satisfaction
7171
Slab AllocationSlab Allocation
7272
Chapter 9: Virtual MemoryChapter 9: Virtual MemoryBackgroundBackground
Demand PagingDemand Paging
Copy-on-WriteCopy-on-Write
Page ReplacementPage Replacement
Allocation of Frames Allocation of Frames
ThrashingThrashing
Memory-Mapped FilesMemory-Mapped Files
Allocating Kernel MemoryAllocating Kernel Memory
Other ConsiderationsOther Considerations
Operating-System ExamplesOperating-System Examples
7373
Other Issues -- PrepagingOther Issues -- PrepagingPrepaging Prepaging To reduce the large number of page faults that occurs To reduce the large number of page faults that occurs
at process startupat process startup Prepage all or some of the pages a process will need, Prepage all or some of the pages a process will need,
before they are referencedbefore they are referenced But if prepaged pages are unused, I/O and memory But if prepaged pages are unused, I/O and memory
was wastedwas wasted Assume Assume ss pages are prepaged and pages are prepaged and αα of the pages is of the pages is
usedused
Is cost of Is cost of s * s * αα save pages faults > or < than the cost save pages faults > or < than the cost of prepagingof prepaging s * (1- s * (1- αα) ) unnecessary pagesunnecessary pages? ?
αα near zero near zero prepaging loses prepaging loses
7474
Other Issues – Page SizeOther Issues – Page Size
Page size selection must take into Page size selection must take into consideration:consideration: fragmentationfragmentation table size table size I/O overheadI/O overhead localitylocality
7575
Other Issues – TLB Reach Other Issues – TLB Reach
TLB ReachTLB Reach - The amount of memory accessible from - The amount of memory accessible from the TLBthe TLB
TLB Reach = (TLB Size) X (Page Size)TLB Reach = (TLB Size) X (Page Size)
Ideally, the working set of each process is stored in Ideally, the working set of each process is stored in the TLBthe TLB Otherwise there is a high degree of page faultsOtherwise there is a high degree of page faults
7676
Increase the Page SizeIncrease the Page Size This may lead to an increase in fragmentation This may lead to an increase in fragmentation
as not all applications require a large page as not all applications require a large page sizesize
Provide Multiple Page SizesProvide Multiple Page Sizes This allows applications that require larger This allows applications that require larger
page sizes the opportunity to use them page sizes the opportunity to use them without an increase in fragmentationwithout an increase in fragmentation
7777
Other Issues – Program Other Issues – Program StructureStructure
Program structureProgram structure Int[128,128] data;Int[128,128] data; Each row is stored in one page Each row is stored in one page Program 1 Program 1
for (j = 0; j <128; j++)for (j = 0; j <128; j++) for (i = 0; i < 128; i++) for (i = 0; i < 128; i++) data[i,j] = 0; data[i,j] = 0; 128 x 128 = 16,384 page faults 128 x 128 = 16,384 page faults
7878
Other Issues – Program Other Issues – Program StructureStructure
Program 2 Program 2
for (i = 0; i < 128; i++)for (i = 0; i < 128; i++) for (j = 0; j < 128; j++) for (j = 0; j < 128; j++) data[i,j] = 0; data[i,j] = 0;
128 page faults in contrast to 128 x 128 128 page faults in contrast to 128 x 128 = 16,384 page faults != 16,384 page faults !
7979
Other Issues – I/O interlockOther Issues – I/O interlock
I/O InterlockI/O Interlock – Pages must sometimes be – Pages must sometimes be locked into memorylocked into memory
Consider I/O - Pages that are used for copying Consider I/O - Pages that are used for copying a file from a device must be locked from being a file from a device must be locked from being selected for eviction by a page replacement selected for eviction by a page replacement algorithmalgorithm
8080
Reason Why Frames Used For I/O Reason Why Frames Used For I/O Must Be In MemoryMust Be In Memory
8181
Chapter 9: Virtual MemoryChapter 9: Virtual MemoryBackgroundBackground
Demand PagingDemand Paging
Copy-on-WriteCopy-on-Write
Page ReplacementPage Replacement
Allocation of Frames Allocation of Frames
ThrashingThrashing
Memory-Mapped FilesMemory-Mapped Files
Allocating Kernel MemoryAllocating Kernel Memory
Other ConsiderationsOther Considerations
Operating-System ExamplesOperating-System Examples
8282
Operating System ExamplesOperating System ExamplesWindows XPWindows XP
Solaris Solaris
8383
Windows XPWindows XP
Uses demand paging with Uses demand paging with clusteringclustering. . Clustering brings in pages surrounding the Clustering brings in pages surrounding the faulting pagefaulting page
Processes are assigned a Processes are assigned a working setworking set minimumminimum and and working set maximumworking set maximum
Working set minimum is the minimum Working set minimum is the minimum number of pages the process is guaranteed number of pages the process is guaranteed to have in memoryto have in memory
8484
A process may be assigned as many A process may be assigned as many pages up to its working set maximumpages up to its working set maximum
When the amount of free memory in the When the amount of free memory in the system falls below a threshold, system falls below a threshold, automaticautomatic working set trimmingworking set trimming is performed to is performed to restore the amount of free memoryrestore the amount of free memory
Working set trimming removes pages from Working set trimming removes pages from processes that have pages in excess of processes that have pages in excess of their working set minimumtheir working set minimum
8585
Solaris Solaris
Maintains a list of free pages to assign Maintains a list of free pages to assign faulting processesfaulting processes
LotsfreeLotsfree – threshold parameter (amount of – threshold parameter (amount of free memory) to begin pagingfree memory) to begin paging
DesfreeDesfree – threshold parameter to increasing – threshold parameter to increasing pagingpaging
MinfreeMinfree – threshold parameter to being – threshold parameter to being swappingswapping
8686
Paging is performed by a Paging is performed by a pageoutpageout process process
PageoutPageout scans pages using modified clock scans pages using modified clock algorithmalgorithm
ScanrateScanrate is the rate at which pages are is the rate at which pages are scanned. This ranges from scanned. This ranges from slowscanslowscan to to fastscanfastscan
Pageout is called more frequently Pageout is called more frequently depending upon the amount of free depending upon the amount of free memory availablememory available
8787
Solaris 2 Page ScannerSolaris 2 Page Scanner
8888
End of Chapter 9End of Chapter 9