Virtual Memory & Paging Algorithms
description
Transcript of Virtual Memory & Paging Algorithms
![Page 1: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/1.jpg)
Virtual Memory & Paging Algorithms
Chapter 4
Tuesday, March 26, 2007
![Page 2: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/2.jpg)
Today’s Schedule Memory Management - Chapter 4
Managing Page Tables Multi-Level Page Tables Inverted Page Tables
Page Replacement Algorithms NRU FIFO Second Chance Clock
![Page 3: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/3.jpg)
Objectives
You will be able to describe: Trade-offs in page table implementation for
speed and space TLB Multi-level page tables Inverted page tables
The difference between page replacement policies first-in first-out not-recently-used page clock and second chance
![Page 4: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/4.jpg)
Paging Overview
![Page 5: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/5.jpg)
Paging Hardware With TLB
A TLB to speed up paging
![Page 6: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/6.jpg)
TLBs – Translation Lookaside Buffers
An Item is missing in the TLB entry? Why?
![Page 7: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/7.jpg)
Page Table Entry
Typical page table entry
![Page 8: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/8.jpg)
Address Translation Scheme Address generated by CPU is divided into:
Page number (p) – used as an index into a page table which contains base address of each page in physical memory
Page offset (d) – combined with base address to define the physical memory address that is sent to the memory unit
For given logical address space 2m and page size 2n
page number page offset
p d
m - n n
![Page 9: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/9.jpg)
How Big is a Page Table?
For 32-bit Address Space?? For 64-bit Address Space??
![Page 10: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/10.jpg)
Multi-Level Page Tables
32 bit address with 2 page table fields Two-level page tables – save space!
Second-level page tables
Top-level page table
![Page 11: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/11.jpg)
Inverted Page Table One entry for each real page of memory Entry consists of the virtual address of the page
stored in that real memory location, with information about the process that owns that page
Decreases memory needed to store each page table, but increases time needed to search the table when a page reference occurs
Use hash table to limit the search to one — or at most a few — page-table entries
![Page 12: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/12.jpg)
Inverted Page Tables
Comparison of a traditional page table with an inverted page table
![Page 13: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/13.jpg)
Allocating Free Frames
Before allocation After allocation
![Page 14: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/14.jpg)
Page Replacement Algorithms Page fault forces choice
which page must be removedmake room for incoming page
Modified page must first be savedunmodified just overwritten
Better not to choose an often used pagewill probably need to be brought back in
soon
![Page 15: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/15.jpg)
Optimal Page Replacement Algorithm
Replace page needed at the farthest point in futureOptimal but unrealizable
Estimate by … logging page use on previous runs of processalthough this is impractical
![Page 16: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/16.jpg)
Not Recently Used Page Replacement
Each page has Reference bit, Modified bit bits are set when page is referenced,
modified Pages are classified
Class 0 - not referenced, not modified Class 1 - not referenced, modified Class 2 - referenced, not modified Class 3 - referenced, modified
NRU removes page at random from lowest numbered non empty class
![Page 17: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/17.jpg)
FIFO Page Replacement Algorithm Maintain a linked list of all pages
in order they came into memory
Page at beginning of list replaced
Disadvantagepage in memory the longest may be often used
![Page 18: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/18.jpg)
Ex. FIFO Page Replacement
Working of a FIFO algorithm for a job with four pages (A, B, C, D) as it’s processed by a system with only two available page frames
![Page 19: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/19.jpg)
Second Chance Page Replacement
Operation of a second chance pages sorted in FIFO order Page list if fault occurs at time 20, A has R bit set
(numbers above pages are loading times)
![Page 20: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/20.jpg)
The Clock Page Replacement Algorithm
![Page 21: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/21.jpg)
Summary Trade-offs in page table implementation for
speed and space TLB in H/W Multi-level page tables Inverted page tables
The difference between page replacement policies first-in first-out not-recently-used page clock & second chance
![Page 22: Virtual Memory & Paging Algorithms](https://reader035.fdocuments.net/reader035/viewer/2022062314/56814643550346895db34e03/html5/thumbnails/22.jpg)
Thursday, March 29
Assignment #7 Due Monday, April 2 Continue reading,
Chapter 4 – Memory Management Sec 4.4.8 Working SetSec 4.4.10 Summary of Page
ReplacementSec 4.5.1 Modeling Page Repl.Sec 4.8 Segmentation (pg 249-253)