![Page 1: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/1.jpg)
VIRTUAL MEMORY AND PAGE REPLACEMENT ALGORITHM
![Page 2: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/2.jpg)
Presented to
Sir Tahir Presented By Ch Muhammad Awais
2695/FBAS/BSCS4/F13(A)
M Mansoor Ul Haq 2736/FBAS/BSCS4/F13(A)
Nouman Dilshad 2709/FBAS/BSCS4/F13(A)
Faheem Akhtar 2710/FBAS/BSCS4/F13(A)
Muddasir Shabbir 2739/FBAS/BSCS4/F13(A)
![Page 3: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/3.jpg)
VIRTUAL MEMORY
![Page 4: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/4.jpg)
Now the Question is
What Is Virtual Memory ??
![Page 5: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/5.jpg)
Virtual memory
“separation of user logical memory from physical memory.”
Only part of the program needs to be in memory for execution Logical address space can therefore be much larger than physical
address space Allows address spaces to be shared by several processes Allows for more efficient process creation
![Page 6: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/6.jpg)
Virtual Memory which is larger than Physical Memory
![Page 7: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/7.jpg)
Virtual Address Space
![Page 8: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/8.jpg)
Advantages Of Virtual Memory:Multitasking
Allocating Memory Is Easy and Cheap
More Efficient Swapping
Process may even be larger than all of the physical memory.
This concept is very helpful in implementing multiprogramming environment.
![Page 9: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/9.jpg)
Disadvantage's Of Virtual Memory:
Longer Memory Access Time As HDD Is Slower.
Memory Requirement.
Applications run slower if the system is using virtual memory.
It takes more time to switch between applications.
Less hard drive space for your use.
![Page 10: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/10.jpg)
PAGE REPLACEMENT
![Page 11: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/11.jpg)
Prevent over-allocation of memory by modifying page-fault service routine to include page replacement
Use modify 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
Page Replacement
![Page 12: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/12.jpg)
Need For Page Replacement
![Page 13: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/13.jpg)
1. Find the location of the desired page on disk
2. Find a free frame: - If there is a free frame, use it - If there is no free frame, use a page replacement algorithm to select a victim frame
3. Bring the desired page into the (newly) free frame; update the page and frame tables
4. Restart the process
Basic Page Replacement
![Page 14: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/14.jpg)
Page Replacement
![Page 15: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/15.jpg)
Why and When We Use Page Replacement Algorithm ?
Want lowest page-fault rate
Evaluate algorithm by running it on a particular string of memory references (reference string) and computing the number of page faults on that string
In all our examples, the reference string is
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
![Page 16: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/16.jpg)
ALGORITHMS
![Page 17: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/17.jpg)
FIFO(FIRST IN FIRST OUT) ALGORITHMTreats page frames allocated to a process as a circular buffer:When the buffer is full, the oldest page is replaced. Hence first-in, first-out:A frequently used page is often the oldest, so it will be repeatedly paged out by FIFO.
Simple to implement: requires only a pointer that circles through the page frames of the process.
![Page 18: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/18.jpg)
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)
4 frames
First In First Out Algorithms
1
2
3
4
1
2
5
3
4
1
2
3
9 page faults
1
2
3
1
2
3
5
1
2
4
5 10 page faults
44 3
![Page 19: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/19.jpg)
• 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
How do you know this? Used for measuring how well your algorithm performs
Optimal Algorithm
1
2
3
4
6 page faults
4 5
![Page 20: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/20.jpg)
• Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
• 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
5
2
4
3
1
2
3
4
1
2
5
4
1
2
5
3
1
2
4
3
Least Recent Used (LRU) Algorithm
![Page 21: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/21.jpg)
Use of a stack to Record The Most Recent Page Reference
![Page 22: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/22.jpg)
LRU Approximation Algorithms • Reference bit
o With each page associate a bit, initially = 0o When page is referenced bit set to 1o Replace the one which is 0 (if one exists)
• Second chanceo Need reference bito Clock replacemento 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
![Page 23: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/23.jpg)
LRU(LEAST RECENT USED) ALGORITHMAdvantages :- LRU policy is often used as a page replacement algorithm It is quite good algorithm. It is easy to choose that has already page faulted and not in use for long period.
Disadvantages:- Problem is how to implement LRU replacement Require substantial hardware assistance
Problem is determine the frame order by the time of last use.
![Page 24: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/24.jpg)
Counting Algorithms
Keep a counter of the number of references that have been made to each page
LFU Algorithm: replaces page with smallest count
MFU Algorithm: based on the argument that the page with the smallest count was probably just brought in and has yet to be used
![Page 25: Virtual memory and page replacement algorithm](https://reader036.vdocuments.net/reader036/viewer/2022062412/587bbd821a28abb8258b6c6f/html5/thumbnails/25.jpg)
ANY QUESTION
Thanks Powered By: ProgCoders