Virtual Memory Management - Aet.calu.edu

streambabyΛογισμικό & κατασκευή λογ/κού

14 Δεκ 2013 (πριν από 3 χρόνια και 7 μήνες)

90 εμφανίσεις

Virtual Memory Management
CSC400 Operating Systems 1
CSC400 - Operating Systems
10: Virtual Memory
Management
10: Virtual Memory
Management
by J. Sumey
CSC400 - Virtual Memory Management 2
Introduction

virtual memory management: concerned with
the actual management operations of a virtual
memory system

fetch strategies: when to move a page from
secondary to main memory
• demand fetch: when a process makes a reference
• anticipatory fetch: loads additional pages the
system "thinks" a process will need ahead of time

replacement strategies: which page to "kick
out" when memory is full
Virtual Memory Management
CSC400 Operating Systems 2
CSC400 - Virtual Memory Management 3
Locality

locality of reference:
• execution behavior of a process wherein it only
references a small subset of all its pages during
various stages of its execution; thus, not all pages
of a process need to be loaded into physical
memory at all times of its execution
• i.e. processes tend to have a "favorite" subset of its
pages

what causes this?
• temporal locality: loops, function calls, variables
• spatial locality: sequential execution, array
traversals
CSC400 - Virtual Memory Management 4
Fetch Strategy: Demand Paging

operation:
• when process starts, OS loads only the page
containing the 1
st
instruction
• OS loads additional pages only after process
references them

features:
• simple policy, easy to implement
• only loads pages actually needed
•"one-at-a-time" page accumulation causes many
waits during page loads
Virtual Memory Management
CSC400 Operating Systems 3
CSC400 - Virtual Memory Management 5
Fetch Strategy: Anticipatory Paging

operation:
• OS attempts to predict which pages a process will
need and preload them when memory is available
– thus minimizing future page faults

features:
• difficult to predict future process behavior
• with additional disk I/O overhead, overall
performance could actually degrade
• sometimes used as an enhancement to demand
paging (i.e. like cache on hard drives)
CSC400 - Virtual Memory Management 6
Page Replacement Algorithms

deals with selection of a page (or segment) to
replace when a page fault occurs and all
current system memory is occupied

algorithms:
• First-In, First-Out (FIFO)
• Least Recently Used (LRU)
• Not Recently Used (NRU)
• Second-Chance/ Clock Replacement

considerations:
• page usage history; referenced / modified
Virtual Memory Management
CSC400 Operating Systems 4
CSC400 - Virtual Memory Management 7
but first - PTE Enhancements

in order to support VM management, page
table entries will need additional info:
• page frame address
• present/absent bit
• referenced bit – used to indicate activity within its
page frame, helps OS in managing memory
• modified (dirty) bit – was the page modified since
being loaded?
• cache disable / swap disable – what about physical
addresses that lead to I/O registers or PTEs?
• protection – how is page frame used: read, write,
execute?
CSC400 - Virtual Memory Management 8
Optimal Page Replacement Algorithm

defined as the algorithm that would yield
lowest number of future page faults
• process would always have needed pages loaded
into main memory

not actually possible because it would require
knowledge of future page usage
(clairvoyance)
Virtual Memory Management
CSC400 Operating Systems 5
CSC400 - Virtual Memory Management 9
Optimal Policy Example

given 3 page frames and a process that
access 5 page frames as follows:
2 3 2 1 5 2 4 5 3 2 5 2

optimal policy produces 3 page faults after
frame allocation has been filled
CSC400 - Virtual Memory Management 10
FIFO Page Replacement

chooses oldest page as the one to replace

page usage is maintained by age; choose
oldest page (Head) to replace & add new
page at Tail

pro: fairly low overhead

con: can easily pick important (heavily used)
pages; thus is not commonly used
• however, is the basis of other, popular algorithms
Virtual Memory Management
CSC400 Operating Systems 6
CSC400 - Virtual Memory Management 11
FIFO Policy Example

FIFO does not consider page use frequency
• results in 6 page faults
CSC400 - Virtual Memory Management 12
LRU Page Replacement

chooses page that has been unused for
longest period of time
• heuristic: a process's past behavior is a good
indication of its future behavior

pro: performs better than FIFO

con: increased overhead
• hardware timer & additional page table field to
store reference "timestamp"; or
• linked-list maintained in reference time-stamp
order (oldest at end)
Virtual Memory Management
CSC400 Operating Systems 7
CSC400 - Virtual Memory Management 13
LRU Policy Example

LRU performs nearly as well as optimal
• results in 4 page faults here
CSC400 - Virtual Memory Management 14
NRU Page Replacement

chooses page that has not been unused recently

small overhead, popular

based on referenced (R) & modified (M) bits of PTE
and "classes"
• 0: not ref'd, not modified
• 1: not ref'd, modified
• 2: referenced, not modified
• 3: referenced & modified

NRU chooses a random page from the lowest non-
empty class to be replaced

class 1 occurs because OS uses a clock interrupt to
periodically clear the R bits
Virtual Memory Management
CSC400 Operating Systems 8
CSC400 - Virtual Memory Management 15
Second Chance / Clock Replacement

second chance
• variation of FIFO where R bit of oldest page is also
considered; if 0 choose it - if 1 clear it, move to
end of list then continue search
• thus, will tend to keep active pages in memory

clock replacement
• improvement on second chance by implementing a
circular list & rotating around it with 2nd chance
algorithm
CSC400 - Virtual Memory Management 16
Comparison of Page Replacement Policies

results are based on the execution of 0.25 x 10
6
references in a
FORTRAN program, using a page size of 256 words

goal: to be to the right of the knee of the curve (with a small
page fault rate) while at the same time keeping a small frame
allocation (to the left of the knee of the curve)
Virtual Memory Management
CSC400 Operating Systems 9
CSC400 - Virtual Memory Management 17
Denning's Working Set Model

working set model
• a paging system strategy of tracking the working set of each
process and prepaging
the set before allowing the process to run

working set
• the set of favored pages currently in use by a process
• pages not referenced for n system clock ticks dropped from the WS
• consider if the entire working set fits into physical memory vs.if it
needs to be paged

thrashing
• result of page faults occurring well over 50% because a process's
working set exceeds its available memory

wsclock
• an improvement on the clock algorithm; besides finding the next
page whose R bit is 0, the page is also checked for membership in
the WS and spared if so
CSC400 - Virtual Memory Management 18
Unix/Solaris VM Management
Virtual Memory Management
CSC400 Operating Systems 10
CSC400 - Virtual Memory Management 19
Windows VM Management

32-bit
• page sizes from 4KB to 64KB
• 4 GB space divided into user (2GB) and system
(2GB) halves [previously shown]

64-bit
• increases user space from 2GB to 8TB (2
43
)