Docsity

Paging and Two-Level Page Tables in Operating Systems, Study notes of Operating Systems

Partial preview of the text

Download Paging and Two-Level Page Tables in Operating Systems and more Study notes Operating Systems in PDF only on Docsity!

COMP 310:

Operating Systems

Lecture 16:

Paging

October 11, 2004

Christine Alvarado

Today’s Topics

 Begin Memory Management

 Paging

 TLBs  Advanced paging techniques

More Paging Overview

 Optimizations

 Managing Page Tables (space)  Efficient translations (time)  Demand paged VM (space)

 Recap address translation

 Advanced Functionality: when VM is larger than PM

 Sharing memory  Copy on Write  Mapped Files Page Tables Are Too Big

 Earlier we said 32 bit address space with 4K

pages = 4MB Page Table!

 How can we reduce this overhead?

Map only what is being used Dynamically extend page table Doesn’t work if address space is sparse Two-level Page Tables

How does this use less memory?

 If we are using all the PTs…

 If we only need SOME of the PTs…

 Where do we store page tables (whose

address space?)

 Physical memory?

 Virtual memory?

Efficient Translations  What is the cost of doing a memory lookup using original PT scheme?  How about using two-level PTs?  How can we fix this problem? (Access should be as fast as accessing PM) Translation Lookaside Buffer (TLB) Cache translations in hardware TLBs

 Translation lookaside buffer

 Translate virtual page # into PTE (not phys addr)  Can be done in single machine cycle (no memory access)

 TLBs implemented in hardware

 Fully associative cache (entries looked up in parallel)  Cache tags are VPNs  Cache values are PTEs  With PTE+offset, what do you have?

 TLBs must be smaller than page tables, so why

does this work?

Summary

 Advantages of TLB

 What can go wrong?

Paged Virtual Memory

 Creating VM that is larger than PM

 Why should we do this?

 How can we do this?

 Move pages of virtual memory between PM and disk  Initially, allocate virtual memory from PM  Then, when PM is full, move some PM pages to “swap space” on disk.  This movement is done by OS—TRANSPARENT TO APPLICATION

Virtual Memory Illustrated Virtual memory Physical Memory Disk Page Fault  When a process accesses a page that has been evicted, a PAGE FAULT occurs  (How can we keep track of which pages have been evicted?) 3 1 2

VM PT

PM

Back to Paging…

 Paging Policies:

 How do we decide when and what page to evict

from memory?

 Cost of paging is HIGH, but with a good policy, it

is worth it.

Cost of paging

 Effecting access time is:

effective access time = (1 – p ) * ma + p * page fault time What is the effective access time if p = 0.01, ma = 100ns, pft = 25ms? How can we ensure a degradation of less than 10%? 0.99 * 100 + 0.0125,000,000 = 99 + 2,500, 110 > 100 + 25,000,000p 10 > 25000,000*p p < 0.

Locality

 All paging policies depend on locality

 Processes access pages in localized patterns

 What kinds of locality are there?

 Temporal locality

 Locations accessed recently likely to be accessed again.

 Spatial locality

 Locations near each other accessed together Demand Paging

 This is what we have talked about. How did

it work again?

Page Replacement

 When a page fault occurs, a new page must

be loaded into memory.

 When memory is full (or rather, when a

process’s allowed portion of memory is full),

a page in memory must be REPLACED.

 The page replacement algorithm determines

which page to replace.

 We will look at several.

Page replacement: Goals

 Reduce fault rate by selecting the “Best”

page to replace

 What is the best page in theory?

 How can we come close to this?

The one that will never be used again (Or used in the longest amount of time)

Belady’s Algorithm

 Optimal page replacement algorithm

 Evict the page that won’t be used for the longest

time in the future.

 Example:

7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1

 Problem?

 Why use it?

Next time

 More page replacement Algorithms

 Read:

 Project 1 DUE WEDNESDAY!