Upload
dorjan
View
25
Download
0
Embed Size (px)
DESCRIPTION
Virtual Memory. Objectives. Avoid copy/restore entire address space Avoid unusable holes in memory Increase program RAM past physical limits Allocation based on virtual memory policy Freedom from user requirements Extended abstraction for users Strategies - PowerPoint PPT Presentation
Citation preview
© 2004, D. J. Foreman 1
Virtual Memory
© 2004, D. J. Foreman 2
ObjectivesAvoid copy/restore entire address spaceAvoid unusable holes in memoryIncrease program RAM past physical limitsAllocation based on virtual memory policy
■ Freedom from user requirements■ Extended abstraction for users
Strategies■ Paging - fixed sized blocks called pages■ Segmentation - variable sized segments
© 2004, D. J. Foreman 3
Address Translation MappingDone at runtimeOnly the part being used is loaded
■ Actually a small initial page-set > 1 page■ Page size determined by the O/S
Instruction execution proceeds until an "addressing" or "missing data" fault■ O/S gets control■ Loads missing page■ Re-start the instruction with new data address
© 2004, D. J. Foreman 4
Mapping -2Formally: βt : vaddress paddress {Ω}
■ Βt is a time-varying map
■ t is the process's virtual time Virtual memory manager implements the
mapping. ANY mechanism is valid if it follows the definition.
βt(i) will be either:■ Real address of virtual address i■ Ω
© 2004, D. J. Foreman 5
ConceptsEntire virtual address space on diskSmall set of virtual addresses bound to
real addresses at any instantVirtual addresses are scatteredPage size depends on hardwarePage size usually = frame size
■ Counter-example (OS/VS2 (2k) on VM (4k))# page frames computed from physical
memory constraints
© 2004, D. J. Foreman 6
Computations Page size=2h & Page frame size=2h
■ Usually constrained by hardware protection
Number of system pages: n = 2g
Number of process pages/frames: m = 2j For a process:
■ Number virtual addresses: G= 2g2h = 2g+h
■ Number physical addresses: H=2j+h
FYI:■ For Pentiums: g = 20 h=12 (page size=4K)■ So G = 4 GB (max program size, including O/S)
© 2004, D. J. Foreman 7
Processing ΩIf function returns Ω
■ Find location i on disk■ Bring it into main memory■ Re-translate i■ Re-start the instruction
Significant overhead■ O/S context switch■ Table search■ I/O for missing address
© 2004, D. J. Foreman 8
Segmentation & PagingSegmentation
■ Programs divided into segments■ Location references are <seg#, offset>■ I/O (Swap) whole segments (variable sized)■ Programmer can control swapping■ External fragmentation can occur
Paging■ I/O (page) fixed-size blocks■ Location references are linear■ No programmer control of paging
© 2004, D. J. Foreman 9
Description of Translationn = pages in virtual spacem =allocated framesi is a virtual address 0<=i<=G G= 2g+h
k=a physical memory address =U*2h + V 0<=V<2h
c page size=2h
Page number = (i/c) U is the page frame numberV=line number (offset in page) = i mod c
© 2004, D. J. Foreman 10
PoliciesFetch - when to load a pageReplace - victim selection (when full)Position (placement) - (when not full)
# allocated frames is constant
Page reference stream - numbers of the pages a P references in order of reference
© 2004, D. J. Foreman 11
Paging Algorithm
1. Page fault occurs
2. Process with missing page is interrupted
3. Memory manager locates missing page
4. Page frame is unloaded (replacement policy)
5. Page is loaded into vacated page frame
6. Page table is updated
7. Process is restarted
© 2004, D. J. Foreman 12
Demand Paging AlgorithmsRandom - many 'missing page' faults“perfect” - for comparisons onlyLeast Recently Used - if recently used, will
be again, so dump the LRU pageLeast Frequently Used - dump the most
useless page - influenced by locality, slow to react
LRU, LFU are both Stack algorithms
© 2004, D. J. Foreman 13
Page Mgmt Structures
Page # Disp
A D K Frame #
Virtual address
PTE
A - AssignedD - DirtyK - Prot. Key
© 2004, D. J. Foreman 14
Page Table LookupPg# Disp
flags Frame#
Process page-table ptr
(a register)
Frame# Disp
Page Table1 entry per Page
Pg#
© 2004, D. J. Foreman 15
Inverted Page TablesUseful for locating in-machine pagesExtract virtual page # (VPN) from addressHash the VPN to an indexSearch the table for this indexEach entry has VPN, frame# (PPN)Efficient for small memoriesCollisions must be resolved
Note: uses page#, not address
© 2004, D. J. Foreman 16
Inverted Page Tables -2Regular page table
■ Uses virtual page # directly■ Entry per page
Inverted table ■ Uses virtual page # as hash input■ Sparse lookup table■ Finds frame if in memory■ Followed by disk address lookup if needed■ Entry per frame
© 2004, D. J. Foreman 17
Inverted Page Tables
HashedPg#
PID link
Frame# or link
1 entry per Frame
Pg# Disp
Hashing Function
Frame# Disp
Process page-table ptr
(a register)
© 2004, D. J. Foreman 18
Translation Lookaside Buffer
VPN Full PTE
TLB - h/w-cachedsimultaneous (associative) lookup
VPN Frame #
S/W lookup tableline by line lookup
frame offset
If no TLB 'hit'
Page# Offset
hit no hit