cs212: operating system lecture 6: virtual-memory management 1 computer science department
TRANSCRIPT
![Page 1: CS212: OPERATING SYSTEM Lecture 6: Virtual-Memory Management 1 Computer Science Department](https://reader030.vdocuments.us/reader030/viewer/2022032607/56649ed95503460f94be8062/html5/thumbnails/1.jpg)
CS212: OPERATING SYSTEM
Lecture 6: Virtual-Memory Management
1
Computer Science
Department
![Page 2: CS212: OPERATING SYSTEM Lecture 6: Virtual-Memory Management 1 Computer Science Department](https://reader030.vdocuments.us/reader030/viewer/2022032607/56649ed95503460f94be8062/html5/thumbnails/2.jpg)
2
Chapter 9: Virtual-Memory Management
Background Demand Paging Page Replacement Allocation of Frames Thrashing
![Page 3: CS212: OPERATING SYSTEM Lecture 6: Virtual-Memory Management 1 Computer Science Department](https://reader030.vdocuments.us/reader030/viewer/2022032607/56649ed95503460f94be8062/html5/thumbnails/3.jpg)
3
Objectives
To describe the benefits of a virtual memory system
To explain the concepts of demand paging, page-replacement algorithms, and allocation of page frames
![Page 4: CS212: OPERATING SYSTEM Lecture 6: Virtual-Memory Management 1 Computer Science Department](https://reader030.vdocuments.us/reader030/viewer/2022032607/56649ed95503460f94be8062/html5/thumbnails/4.jpg)
4
Background
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
Virtual memory can be implemented via: Demand paging Demand segmentation
![Page 5: CS212: OPERATING SYSTEM Lecture 6: Virtual-Memory Management 1 Computer Science Department](https://reader030.vdocuments.us/reader030/viewer/2022032607/56649ed95503460f94be8062/html5/thumbnails/5.jpg)
5
Virtual Memory That is Larger Than Physical Memory
![Page 6: CS212: OPERATING SYSTEM Lecture 6: Virtual-Memory Management 1 Computer Science Department](https://reader030.vdocuments.us/reader030/viewer/2022032607/56649ed95503460f94be8062/html5/thumbnails/6.jpg)
6
Virtual-address Space
![Page 7: CS212: OPERATING SYSTEM Lecture 6: Virtual-Memory Management 1 Computer Science Department](https://reader030.vdocuments.us/reader030/viewer/2022032607/56649ed95503460f94be8062/html5/thumbnails/7.jpg)
7
Shared Library Using Virtual Memory
![Page 8: CS212: OPERATING SYSTEM Lecture 6: Virtual-Memory Management 1 Computer Science Department](https://reader030.vdocuments.us/reader030/viewer/2022032607/56649ed95503460f94be8062/html5/thumbnails/8.jpg)
8
Demand Paging
Bring a page into memory only when it is needed Less I/O needed Less memory needed Faster response More users
Page is needed reference to it invalid reference abort not-in-memory bring to memory
Lazy swapper – never swaps a page into memory unless page will be needed Swapper that deals with pages is a pager
![Page 9: CS212: OPERATING SYSTEM Lecture 6: Virtual-Memory Management 1 Computer Science Department](https://reader030.vdocuments.us/reader030/viewer/2022032607/56649ed95503460f94be8062/html5/thumbnails/9.jpg)
9
Transfer of a Paged Memory to Contiguous Disk Space
![Page 10: CS212: OPERATING SYSTEM Lecture 6: Virtual-Memory Management 1 Computer Science Department](https://reader030.vdocuments.us/reader030/viewer/2022032607/56649ed95503460f94be8062/html5/thumbnails/10.jpg)
10
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:
During address translation, if valid–invalid bit in page table entry
is I page fault
vvv
v
i
ii
….
Frame # valid-invalid bit
page table
![Page 11: CS212: OPERATING SYSTEM Lecture 6: Virtual-Memory Management 1 Computer Science Department](https://reader030.vdocuments.us/reader030/viewer/2022032607/56649ed95503460f94be8062/html5/thumbnails/11.jpg)
11
Page Table When Some Pages Are Not in Main Memory
![Page 12: CS212: OPERATING SYSTEM Lecture 6: Virtual-Memory Management 1 Computer Science Department](https://reader030.vdocuments.us/reader030/viewer/2022032607/56649ed95503460f94be8062/html5/thumbnails/12.jpg)
12
Page Fault
If there is a reference to a page, first reference to that page will trap to operating system:
page fault1. Operating system looks at another table to
decide: Invalid reference abort Just not in memory
2. Get empty frame3. Swap page into frame4. Reset tables5. Set validation bit = v6. Restart the instruction that caused the page fault
![Page 13: CS212: OPERATING SYSTEM Lecture 6: Virtual-Memory Management 1 Computer Science Department](https://reader030.vdocuments.us/reader030/viewer/2022032607/56649ed95503460f94be8062/html5/thumbnails/13.jpg)
13
Steps in Handling a Page Fault
![Page 14: CS212: OPERATING SYSTEM Lecture 6: Virtual-Memory Management 1 Computer Science Department](https://reader030.vdocuments.us/reader030/viewer/2022032607/56649ed95503460f94be8062/html5/thumbnails/14.jpg)
14
Page Replacement
What happens if there is no free frame?
The solution:
Page replacement – find some page in memory, but not really in use, swap it out algorithm performance – want an algorithm which
will result in minimum number of page faults
Same page may be brought into memory several times
![Page 15: CS212: OPERATING SYSTEM Lecture 6: Virtual-Memory Management 1 Computer Science Department](https://reader030.vdocuments.us/reader030/viewer/2022032607/56649ed95503460f94be8062/html5/thumbnails/15.jpg)
15
Need For Page Replacement
![Page 16: CS212: OPERATING SYSTEM Lecture 6: Virtual-Memory Management 1 Computer Science Department](https://reader030.vdocuments.us/reader030/viewer/2022032607/56649ed95503460f94be8062/html5/thumbnails/16.jpg)
16
Basic Page Replacement
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
![Page 17: CS212: OPERATING SYSTEM Lecture 6: Virtual-Memory Management 1 Computer Science Department](https://reader030.vdocuments.us/reader030/viewer/2022032607/56649ed95503460f94be8062/html5/thumbnails/17.jpg)
17
Page Replacement
![Page 18: CS212: OPERATING SYSTEM Lecture 6: Virtual-Memory Management 1 Computer Science Department](https://reader030.vdocuments.us/reader030/viewer/2022032607/56649ed95503460f94be8062/html5/thumbnails/18.jpg)
18
Thrashing If a process does not have “enough”
frames, the page-fault rate is very high. This leads to: low CPU utilization operating system thinks that it needs to
increase the degree of multiprogramming another process added to the system
Thrashing a process is busy swapping pages in and out
A process is thrashing if it is spending more time paging than executing.