Download - virtual memory Operating system
![Page 1: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/1.jpg)
Virtual Memory
![Page 2: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/2.jpg)
Virtual Memory
Virtual memory is a technique that is used to execute processes that are not in main memory completely. The remaining part are placed on the backing storage.
Demand paging
It is a technique that is used to bring a page into memory only when it is needed.
![Page 3: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/3.jpg)
Demand paging cycle Page is needed reference to it Referenced page not in real memory Page Fault Just not in memory Demand paging Find free frame Swap page into frame Reset tables to indicate page now in memory Restart the instruction that caused the page fault
![Page 4: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/4.jpg)
Page Replacement
“Page replacement completes separation between logical memory and physical memory large virtual memory can be provided on a smaller physical memory”
![Page 5: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/5.jpg)
How to solve page faults?
It terminates the program immediatelyOr
Swaps out program & frees all of its frames It reduces the degree of multiprogramming
![Page 6: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/6.jpg)
Basic Page ReplacementSteps performed by OS while replacing a page upon a page fault:
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; if the victim page is modified, write it back to disk.
3. Bring the desired page into the (new) free frame; update the page and frame tables
4. Restart the process
![Page 7: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/7.jpg)
Page-replacement algorithm
Want lowest page-fault rate on both first access and re-access
There is particular string of memory references. String is just page numbers, not full addresses Repeated access to the same page does not
cause a page fault Results depend on number of frames available
In all our examples, the reference string of referenced page numbers is 7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1
![Page 8: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/8.jpg)
First In First Out (FIFO) Algorithm
Oldest page in main memory is the one which will be selected for replacement
Easy to implement, keep a list, replace pages from the tail and add new pages at the head.
![Page 9: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/9.jpg)
First-In-First-Out (FIFO) Algorithm
Adding more frames can cause more page faults!
Belady’s Anomaly
15 page faults
![Page 10: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/10.jpg)
FIFO Illustrating Belady’s Anomaly
![Page 11: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/11.jpg)
Optimal Algorithm Replace page that will not be used for longest period of time How do you know this?
Used for measuring how well your algorithm performs
![Page 12: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/12.jpg)
Least Recently Used (LRU) Algorithm Use past knowledge rather than future Replace page that has not been used in the most amount of time
![Page 13: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/13.jpg)
12 faults – better than FIFO but worse than OPT Generally good algorithm and frequently used
![Page 14: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/14.jpg)
LRU Approximation Algorithm
Reference bitWith each page associate a bit, initially= 0When page is referenced bit set to 1
![Page 15: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/15.jpg)
Additional Reference Bits We can gain additional ordering information
by recording the reference bits at regular interval
We can keep 8-bit byte for each page in a table in memory
The OS shifts the reference bit for each page into the high-order bit of its 8-bit byte, shifting the other bit right by 1 bit and discard the low-order bit
![Page 16: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/16.jpg)
Second Chance Algorithm
This Algorithm is a FIFO replacement algorithm wit consideration given to the reference bit .when a page has been selected for replacement , its reference bit is inspected .
When a page is given a second chance its reference bit is cleared and its arrival time reset to the current time
![Page 17: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/17.jpg)
Enhanced Second-Chance Algorithm
Improve algorithm by using reference bit and modify bit (if available) in concert
1. (0, 0) neither recently used not modified – best page to replace
2. (0, 1) not recently used but modified – not quite as good, must write out before replacement
3. (1, 0) recently used but clean – probably will be used again soon
4. (1, 1) recently used and modified – probably will be used again soon and need to write out before replacement
![Page 18: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/18.jpg)
Allocation of Frames
Each process needs minimum number of pages Various allocation approaches
› fixed allocation › global allocation› local allocation
![Page 19: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/19.jpg)
Fixed Allocation Equal allocation – For example, if there are 100
frames and 5 processes, give each process 20 frames.
Proportional allocation – Allocate according to the size of process
mSspa
m
sS
ps
iii
i
ii
for allocation
frames ofnumber total
process of size
Example: 5964
137127
564137101271064
2
1
2
a
a
ssm
i
![Page 20: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/20.jpg)
Global versus Local Allocation
When a page fault occurs for a process and we need page replacement, there are two general approaches: › Global replacement – select a victim frame
from the set of all frames; one process can take a frame from another
› Local replacement – select a victim frame only from the frames allocated to the process. A process uses always its allocated frames
![Page 21: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/21.jpg)
Thrashing
At some time , the processor may be spend most of its time swapping pages and doing little productive work, this is known as Thrashing.
![Page 22: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/22.jpg)
Figure:
![Page 23: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/23.jpg)
Thrashing Cause
It is caused by under allocation of minimum no. of pages required by a process , forcing it to continuously page fault.
![Page 24: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/24.jpg)
Working setIt is a collection of pages, which is actively referenced by a process . It should be kept in main memory to run efficiently.
![Page 25: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/25.jpg)
![Page 26: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/26.jpg)
Working sets change during process execution . pages are added or deleted and critical changes may occur.
![Page 27: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/27.jpg)
Page Size:It is a hardware design issue . Small pages reduce the amount of internal fragmentation. Large pages reduce the size of the page table.
![Page 28: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/28.jpg)
In general small pages have better locality than large pages.
![Page 29: virtual memory Operating system](https://reader036.vdocument.in/reader036/viewer/2022062823/5873a87c1a28aba3548b562b/html5/thumbnails/29.jpg)