17
Virtual Memory Review CSE 121 Spring 2003 Keith Marzullo

Virtual Memory Review CSE 121 Spring 2003 Keith Marzullo

  • View
    218

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Virtual Memory Review CSE 121 Spring 2003 Keith Marzullo

Virtual Memory Review

CSE 121Spring 2003

Keith Marzullo

Page 2: Virtual Memory Review CSE 121 Spring 2003 Keith Marzullo

CSE 121 Spring 2003 Review of Concurrency 2

Virtual Memory API

• Most utilization of memory is automatic° Program and data allocation.° Stack management.

• Some are not° malloc or new routines.° memory mapped files.° shared memory segments.

Page 3: Virtual Memory Review CSE 121 Spring 2003 Keith Marzullo

CSE 121 Spring 2003 Review of Concurrency 3

Virtual memory

NMAP physical addressvirtual address

Page 4: Virtual Memory Review CSE 121 Spring 2003 Keith Marzullo

CSE 121 Spring 2003 Review of Concurrency 4

Segmentation

segment offset

base address length access

base address length access

base address length access

base address length access

base address length access

base address length access

physical address

if (offset > length) segment fault

Page 5: Virtual Memory Review CSE 121 Spring 2003 Keith Marzullo

CSE 121 Spring 2003 Review of Concurrency 5

Paging

offset physical address

if (!valid) page fault

page

page frame ref accessdirty

page frame ref accessdirty

page frame ref accessdirty

page frame ref accessdirty

valid

valid

valid

valid

Page 6: Virtual Memory Review CSE 121 Spring 2003 Keith Marzullo

CSE 121 Spring 2003 Review of Concurrency 6

IA-32 architecture (simplified)

Linear Address Space Linear Address

Dir Table Offset

CodeData

Stack

Task-StateSegment (TSS)

Code, Data orStack Segment

Global DescriptorTable (GDT)

Segment Sel.

TSS Seg. Sel.

CR3

Physical Address

Linear Address

Segment SelectorLinear Addr.

Page Directory Page Table Page

Page Dir. Entry Page Tbl. EntryPhysical Addr.

Page 7: Virtual Memory Review CSE 121 Spring 2003 Keith Marzullo

CSE 121 Spring 2003 Review of Concurrency 7

SUN UltraSPARC III (simplified)

Page 8: Virtual Memory Review CSE 121 Spring 2003 Keith Marzullo

CSE 121 Spring 2003 Review of Concurrency 8

Demand Paging

When a page fault occurs:° Find a free page frame.

• If none, then choose a page to evict.

° Read page from backing store into this frame.° Assign page to this page frame.° Resume process.

… which page should be evicted?

Page 9: Virtual Memory Review CSE 121 Spring 2003 Keith Marzullo

CSE 121 Spring 2003 Review of Concurrency 9

Page replacement policies

• FIFOEasy to implement, but poor performance.

• Optimal: evict page that will be next referenced farthest in the future.Need ability to predict the future.

• LRU: using the past to predict the future.Too high overhead.

• Clock: LRU approximation.

Page 10: Virtual Memory Review CSE 121 Spring 2003 Keith Marzullo

CSE 121 Spring 2003 Review of Concurrency 10

CLOCKAdvance CLOCK

hand

Test and clear use-bit

Schedule page for cleaning

Replace page

Use-bit

Dirty-bit

set

set

clear

clear

Page 11: Virtual Memory Review CSE 121 Spring 2003 Keith Marzullo

CSE 121 Spring 2003 Review of Concurrency 11

Miss ratio for different policies

0.00001

0.00010

0.00100

1 21 41 61 81 101 121 141 161 181 201 221 241 261 281 301 321 341

number page f rames

mis

s r

atio Miss(OPT)

Miss(LRU)

Miss(CLOCK)

Miss(FIFO)

Miss(RAND)

Page 12: Virtual Memory Review CSE 121 Spring 2003 Keith Marzullo

CSE 121 Spring 2003 Review of Concurrency 12

FIFO miss ratio (detail)

0.00010

0.00012

0.00014

0.00016

0.00018

0.00020

0.00022

0.00024

145 155 165 175

Miss(FIFO)

Page 13: Virtual Memory Review CSE 121 Spring 2003 Keith Marzullo

CSE 121 Spring 2003 Review of Concurrency 13

Working set

The only reason that virtual memory works at all in practice is because of the amount of locality there is in address references.° The page fault penalty is 105

° If page faulted on only 1 out of ten references, then the program would run 10,000 times slower.

Page 14: Virtual Memory Review CSE 121 Spring 2003 Keith Marzullo

CSE 121 Spring 2003 Review of Concurrency 14

Working set, II• Define the working set of a process's reference

string at time t for a window to be the pages tt...t.

= 1; 2; 3; 4; 5; 4; 5; 4; 5; 4; 5working set size

1

2

3

4

5

1 2 3 4 5 6 7 8 9 10 11

time

size

tau = 2

tau = 4

Page 15: Virtual Memory Review CSE 121 Spring 2003 Keith Marzullo

CSE 121 Spring 2003 Review of Concurrency 15

Working set, III

Page 16: Virtual Memory Review CSE 121 Spring 2003 Keith Marzullo

CSE 121 Spring 2003 Review of Concurrency 16

Working set policy, I

A process can run only if its working set is resident.

Example:° UNIX can (temporarily) remove a process from

the ready set if the page fault rate is too high.• Choose a process that has been sleeping a long time.

• If none, then choose the longest resident of the four largest processes.

Page 17: Virtual Memory Review CSE 121 Spring 2003 Keith Marzullo

CSE 121 Spring 2003 Review of Concurrency 17

Working set policy, II

One can modify CLOCK to approximate a working set policy.° Let PT be the current process time.° Each frame f is examined as usual.

• If the use bit set, then LR[f] = PT.

• If the use bit isn't set, then f is replaceable if PTLR[f] > .