Virtual Memory: Algorithms, Page Faults, and Performance, Slides of Computer Science

Various aspects of virtual memory, including page fault algorithms, replacement policies, and performance considerations. Topics include the working set algorithm, page fault frequency algorithm, lru algorithm, optimal algorithm, and clock algorithm. Discussions cover page access, page fault generation, and page replacement strategies to minimize page faults and optimize system performance.

Typology: Slides

2012/2013

Uploaded on 03/20/2013

dharmaketu
dharmaketu 🇮🇳

4.6

(165)

99 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
More on Virtual Memory
COMP755 1
Virtual Memory
Virtual Memory
COMP755 Advanced Operating
COMP755 Advanced Operating
Systems
Systems
Virtual Memory Performance
Virtual Memory Performance
Size of the Page
Size of the Page
Fetch Policy
Fetch Policy
Placement Policy
Placement Policy
Cleaning policy
Cleaning policy
Resident Set Management
Resident Set Management
Replacement Policy
Replacement Policy
Multiprogramming Level
Multiprogramming Level
Resident Set Management
Resident Set Management
Should all programs have an equal
Should all programs have an equal
number of pages? If there are N programs
number of pages? If there are N programs
running, should each program have 1/N of
running, should each program have 1/N of
the total RAM?
the total RAM?
When a program gets a page fault and
When a program gets a page fault and
needs another page, should the new page
needs another page, should the new page
replace only a page in that user
replace only a page in that user
s program
s program
or can it replace any page from any
or can it replace any page from any
program?
program?
Resident Set Management
Resident Set Management
Fixed or variable number of pages per
Fixed or variable number of pages per
process.
process.
Pages replaced globally or within a
Pages replaced globally or within a
process.
process.
Working Set Algorithm looks at the
Working Set Algorithm looks at the
number of pages recently accessed to
number of pages recently accessed to
determine how many pages a program
determine how many pages a program
should have.
should have.
Allocating Pages
Allocating Pages
If free pages are available, it is usually
If free pages are available, it is usually
advantageous to give more pages to a
advantageous to give more pages to a
program.
program.
When few or no free pages are available,
When few or no free pages are available,
giving pages to one program means taking
giving pages to one program means taking
pages from another.
pages from another.
Taking pages from another program will
Taking pages from another program will
likely increase that program
likely increase that program
s page fault
s page fault
rate.
rate.
The goal is to reduce the total number of
The goal is to reduce the total number of
page faults in the system.
page faults in the system.
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Virtual Memory: Algorithms, Page Faults, and Performance and more Slides Computer Science in PDF only on Docsity!

Virtual Memory Virtual Memory

COMP755 Advanced OperatingCOMP755 Advanced OperatingSystemsSystems

Virtual Memory Performance Virtual Memory Performance

Size of the PageFetch Policy Size of the Page Fetch Policy Placement PolicyCleaning policy Placement Policy Cleaning policy Resident Set ManagementReplacement Policy Resident Set Management Replacement Policy Multiprogramming Level Multiprogramming Level

Resident Set Management Resident Set Management

Should all programs have an equalShould all programs have an equalnumber of pages? If there are N programsnumber of pages? If there are N programs running, should each program have 1/N ofrunning, should each program have 1/N ofthe total RAM?the total RAM? When a program gets a page fault andWhen a program gets a page fault andneeds another page, should the new pageneeds another page, should the new page replace only a page in that userreplace only a page in that user’or can it replace any page from anyor can it replace any page from any’s programs program program?program?

Resident Set ManagementResident Set Management

Fixed or variable number of pages perprocess. Fixed or variable number of pages perprocess. Pages replaced globally or within aprocess. Pages replaced globally or within aprocess. Working Set Algorithm looks at thenumber of pages recently accessed to Working Set Algorithm looks at thenumber of pages recently accessed to determine how many pages a programshould have.determine how many pages a programshould have.

If free pages are available, it is usuallyIf free pages are available, it is usuallyAllocating Pages^ Allocating Pages

advantageous to give more pages to aadvantageous to give more pages to aprogram.program. When few or no free pages are available,When few or no free pages are available,giving pages to one program means takinggiving pages to one program means taking pages from another.pages from another. Taking pages from another program willTaking pages from another program will likely increase that programlikely increase that program’rate.rate. ’s page faults page fault The goal is to reduce the total number ofThe goal is to reduce the total number ofpage faults in the system.page faults in the system.

Docsity.com

Page Fault Frequency Algorithm Page Fault Frequency Algorithm

If a program is generating more pageIf a program is generating more pagefaults than some limit, give the programfaults than some limit, give the program more pages in RAM.more pages in RAM. If the OS needs to take pages from aIf the OS needs to take pages from a program, remove them from a programprogram, remove them from a programthat is generating less than somethat is generating less than some minimum number of page faults.minimum number of page faults.

Working Set Strategy Working Set Strategy

For each program, the OS keeps residentFor each program, the OS keeps residentall pages that have been accessed in theall pages that have been accessed in the lastlast Increasing the parameterIncreasing the parameter^ ∆∆^ time units.time units. ∆∆ (^) increases theincreases the number of pages.number of pages. Usually implemented so that at a pageUsually implemented so that at a page fault the system keeps those pages thatfault the system keeps those pages thathave been accesses inhave been accesses in (^) ∆∆ time units.time units.

A system is said to be thrashing when it is A system is said to be thrashing when it isThrashing^ Thrashing

spending so much of its resourcesmaintaining the virtual memory that littlespending so much of its resourcesmaintaining the virtual memory that little actual work gets accomplished.As the number of running programsactual work gets accomplished. As the number of running programs increases, each program gets fewer pagesin RAM.increases, each program gets fewer pagesin RAM. With fewer pages in RAM, each programcreates more page faults. With fewer pages in RAM, each programcreates more page faults.

Replacement PolicyReplacement Policy

What page should be overwritten?What page should be overwritten? OptimalOptimal - requires looking forward in time.-requires looking forward in time. Useful for evaluating other algorithms.Useful for evaluating other algorithms. LRULRU (^) - - works well.works well. FIFOFIFO ClockClock^ - denies the concept of locality- - - used by Mac OS.denies the concept of localityused by Mac OS. Page BufferingPage Buffering available and released pages.available and released pages. - - System keeps a list ofSystem keeps a list of

Multiprogramming LevelMultiprogramming Level

How many programs can runsimultaneously? How many programs can runsimultaneously? Swap out idle programs Swap out idle programs

Docsity.com

The Program Accesses PageThe Program Accesses Page

The Program Accesses Page The Program Accesses Page

The Program Accesses PageThe Program Accesses Page

5 4 7 5 6 8 A5 4 7 5 6 8 A

The Program Accesses Page The Program Accesses Page

5 4 7 5 6 8 A 55 4 7 5 6 8 A 5

The Program Accesses PageThe Program Accesses Page

5 4 7 5 6 8 A 5 75 4 7 5 6 8 A 5 7

The Program Accesses Page The Program Accesses Page

5 4 7 5 6 8 A 5 7 65 4 7 5 6 8 A 5 7 6

Docsity.com

The Program Accesses PageThe Program Accesses Page

5 4 7 5 6 8 A 5 7 65 4 7 5 6 8 A 5 7 6

FF

The Program Accesses Page The Program Accesses Page

5 4 7 5 6 8 A 5 7 65 4 7 5 6 8 A 5 7 6

F AF A

The Program Accesses PageThe Program Accesses Page

5 4 7 5 6 8 A 5 7 65 4 7 5 6 8 A 5 7 6

F A 7F A 7

The Program Accesses Page The Program Accesses Page

5 4 7 5 6 8 A 5 7 65 4 7 5 6 8 A 5 7 6

F A 7 AF A 7 A

The Program Accesses PageThe Program Accesses Page

5 4 7 5 6 8 A 5 7 65 4 7 5 6 8 A 5 7 6

F A 7 A 6F A 7 A 6

The Program Accesses Page The Program Accesses Page

5 4 7 5 6 8 A 5 7 65 4 7 5 6 8 A 5 7 6

F A 7 A 6 5F A 7 A 6 5

Docsity.com

LRU Algorithm LRU Algorithm

5 4 7 5 6 8 A 5 7 6 5 4 7 5 6 8 A 5 7 6

F A 7 A 6 5 4 A F 5F A 7 A 6 5 4 A F 5

55

LRU Algorithm LRU Algorithm

5 4 7 5 6 8 A 5 7 65 4 7 5 6 8 A 5 7 6

F A 7 A 6 5 4 A F 5F A 7 A 6 5 4 A F 5

55 44

LRU Algorithm LRU Algorithm

5 4 7 5 6 8 A 5 7 65 4 7 5 6 8 A 5 7 6

F A 7 A 6 5 4 A F 5F A 7 A 6 5 4 A F 5

55 44 77

LRU Algorithm LRU Algorithm

5 4 7 55 4 7 5 6 8 A 5 7 66 8 A 5 7 6

F A 7 A 6 5 4 A F 5F A 7 A 6 5 4 A F 5

55 44 77

LRU Algorithm LRU Algorithm

5 4 7 55 4 7 5 66 8 A 5 7 68 A 5 7 6

F A 7 A 6 5 4 A F 5F A 7 A 6 5 4 A F 5

55 44 77 66

LRU Algorithm LRU Algorithm

5 4 7 55 4 7 5 66 88 A 5 7 6A 5 7 6

F A 7 A 6 5 4 A F 5F A 7 A 6 5 4 A F 5

(^55887766)

Docsity.com

LRU Algorithm LRU Algorithm

5 4 7 55 4 7 5 66 88 AA 5 7 65 7 6

F A 7 A 6 5 4 A F 5F A 7 A 6 5 4 A F 5

55 88 AA 66

LRU Algorithm LRU Algorithm

5 4 7 55 4 7 5 66 88 AA 55 7 67 6

F A 7 A 6 5 4 A F 5F A 7 A 6 5 4 A F 5

55 88 AA 66

LRU Algorithm LRU Algorithm

5 4 7 55 4 7 5 66 88 AA 55 77 6 6

F A 7 A 6 5 4 A F 5F A 7 A 6 5 4 A F 5

55 88 AA^77

LRU Algorithm LRU Algorithm

5 4 7 55 4 7 5 66 88 AA 55 77 6 6

F A 7 A 6 5 4 A F 5F A 7 A 6 5 4 A F 5

(^5566) AA (^77)

LRU Algorithm LRU Algorithm

5 4 7 55 4 7 5 66 88 AA 55 77 6 6

F A 7 A 6 5 4 A F 5F A 7 A 6 5 4 A F 5

55 66 FF^77

LRU Algorithm LRU Algorithm

5 4 7 55 4 7 5 66 88 AA 55 77 6 6

F AF A 7 A 6 5 4 A F 57 A 6 5 4 A F 5

AA 66 FF (^77)

Docsity.com

LRU Algorithm LRU Algorithm

5 4 7 55 4 7 5 66 88 AA 55 77 6 6

F AF A 77 AA 66 55 44 AA FF 5 5

AA FF 55 44

LRU Algorithm LRU Algorithm

5 4 7 55 4 7 5 66 88 AA 55 77 6 6

F AF A 77 AA 66 55 44 AA FF 5 5

AA FF 55 44 13 total page faults

Optimal AlgorithmOptimal Algorithm

The optimal algorithm looks forward inThe optimal algorithm looks forward intime and replaces the page that will not betime and replaces the page that will not be referenced again or will be referenced thereferenced again or will be referenced thefarthest in the future.farthest in the future. Cannot be implemented.Cannot be implemented. Provides a theoretical minimum number ofProvides a theoretical minimum number of page faultspage faults

Optimal Algorithm Optimal Algorithm

5 4 7 5 6 8 A 5 7 6 5 4 7 5 6 8 A 5 7 6

F A 7 A 6 5 4 A F 5F A 7 A 6 5 4 A F 5

(^55)

Optimal AlgorithmOptimal Algorithm

5 4 7 5 6 8 A 5 7 65 4 7 5 6 8 A 5 7 6

F A 7 A 6 5 4 A F 5F A 7 A 6 5 4 A F 5

55 44

Optimal Algorithm Optimal Algorithm

5 4 7 5 6 8 A 5 7 65 4 7 5 6 8 A 5 7 6

F A 7 A 6 5 4 A F 5F A 7 A 6 5 4 A F 5

55 44 77

Docsity.com

Optimal AlgorithmOptimal Algorithm

5 4 7 55 4 7 5 6 8 A 5 7 66 8 A 5 7 6

F A 7 A 6 5 4 A F 5F A 7 A 6 5 4 A F 5

55 44 77

Optimal Algorithm Optimal Algorithm

5 4 7 55 4 7 5 66 8 A 5 7 68 A 5 7 6

F A 7 A 6 5 4 A F 5F A 7 A 6 5 4 A F 5

55 44 77 66

Optimal AlgorithmOptimal Algorithm

5 4 7 55 4 7 5 66 88 A 5 7 6A 5 7 6

F A 7 A 6 5 4 A F 5F A 7 A 6 5 4 A F 5

55 88 77 66

Optimal Algorithm Optimal Algorithm

5 4 7 55 4 7 5 66 88 AA 5 7 65 7 6

F A 7 A 6 5 4 A F 5F A 7 A 6 5 4 A F 5

55 AA 77 66

Optimal AlgorithmOptimal Algorithm

5 4 7 55 4 7 5 66 88 AA 55 7 67 6

F A 7 A 6 5 4 A F 5F A 7 A 6 5 4 A F 5

55 AA^7766

Optimal Algorithm Optimal Algorithm

5 4 7 55 4 7 5 66 88 AA 55 77 6 6

F A 7 A 6 5 4 A F 5F A 7 A 6 5 4 A F 5

55 AA 77 66

Docsity.com

Optimal AlgorithmOptimal Algorithm

5 4 7 55 4 7 5 66 88 AA 55 77 6 6

F AF A 77 AA 66 55 4 A F 54 A F 5

FF AA 55 66

Optimal Algorithm Optimal Algorithm

5 4 7 55 4 7 5 66 88 AA 55 77 6 6

F AF A 77 AA 66 55 44 A F 5A F 5

FF AA 55 44

Optimal AlgorithmOptimal Algorithm

5 4 7 55 4 7 5 66 88 AA 55 77 6 6

F AF A 77 AA 66 55 44 AA F 5F 5

FF AA (^5544)

Optimal Algorithm Optimal Algorithm

5 4 7 55 4 7 5 66 88 AA 55 77 6 6

F AF A 77 AA 66 55 44 AA FF 5 5

FF AA 55 44

Optimal AlgorithmOptimal Algorithm

5 4 7 55 4 7 5 66 88 AA 55 77 6 6

F AF A 77 AA 66 55 44 AA FF 5 5

FF AA (^5544) 9 Total Page Faults

Clock AlgorithmClock Algorithm

Considers if a page has been referencedand if it has been modified. Considers if a page has been referencedand if it has been modified. Unmodified pages are replaced beforemodified pages to avoid having to write the Unmodified pages are replaced beforemodified pages to avoid having to write the old page back to disk.Pages are kept in a circular queue with aold page back to disk. Pages are kept in a circular queue with a pointer to the page after last replacedpage.pointer to the page after last replacedpage.

Docsity.com

Clock AlgorithmClock Algorithm

Scan 1Scan 1 –pages are scanned for one that has notpages are scanned for one that has not– Beginning with the pointer, theBeginning with the pointer, the been referenced or modified. The first pagebeen referenced or modified. The first pagefound is replaced.found is replaced. Scan 2Scan 2 –a page that has not been referenced buta page that has not been referenced but– Starting from the pointer, look forStarting from the pointer, look for has been modified. As the pages arehas been modified. As the pages arechecked, clear the referenced bit.checked, clear the referenced bit.

Clock AlgorithmClock Algorithm

Scan 3 -pages are scanned for one that has not Scan 3pages are scanned for one that has not- Starting from the pointer, theStarting from the pointer, the been referenced or modified.Scan 4 -been referenced or modified. Scan 4- Starting from the pointer, look forStarting from the pointer, look for a page that has not been referenced buthas been modified.a page that has not been referenced buthas been modified.

Page Buffering Page Buffering

The OS maintains a list of free pages.The OS maintains a list of free pages. Pages are taken from the free list wheneverPages are taken from the free list whenever a new page is needed.a new page is needed. When a page is replaced, it is put on the endWhen a page is replaced, it is put on the end of the free list if it has not been modified.of the free list if it has not been modified. If the page was modified, it is put on aIf the page was modified, it is put on a modified list.modified list.

Page BufferingPage Buffering

Pages on the modified list are written todisk when the system is idle. Cleaned Pages on the modified list are written todisk when the system is idle. Cleaned pages are put on the free list.When a page fault occurs, the systempages are put on the free list. When a page fault occurs, the system checks these lists to see if the page is stillin RAM.checks these lists to see if the page is stillin RAM.

Docsity.com