CSE451 Introduction To Operating Systems Winter 2012: Paging
CSE451 Introduction To Operating Systems Winter 2012: Paging
CSE451 Introduction To Operating Systems Winter 2012: Paging
Systems
Winter 2012
Paging
Mark Zbikowski
Gary Kimura
offset
physical memory
page table
physical address
page frame #
page frame #
offset
page
frame 0
page
frame 1
page
frame 2
page
frame 3
virtual page #
page
frame Y
V R M
prot
20
page frame number
the referenced bit says whether the page has been accessed
it is set when a page has been read or written to
Page faults
What happens when a process references a virtual address in a
page that has been evicted?
when the page was evicted, the OS set the PTE as invalid and noted the
disk location of the page in a data structure (that looks like a page table
but holds disk addresses)
when a process tries to access the page, the invalid PTE will cause an
exception (page fault) to be thrown
OK, its actually an interrupt!
Demand paging
Pages are only brought into main memory when they are
referenced
only the code/data that is needed (demanded!) by a process needs
to be loaded
Whats needed changes over time, of course
Page replacement
When you read in a page, where does it go?
if there are free page frames, grab one
what data structure might support this?
spatial locality
locations near recently references locations are likely to be referenced
soon (think about why)
the best page to evict is one that will never be touched again
duh
10
11
#2: FIFO
FIFO is obvious, and simple to implement
when you page in something, put it on the tail of a list
evict page at the head of the list
12
Implementation
to be perfect, must grab a timestamp on every memory reference, put it in
the PTE, order or search based on the timestamps
way too $$$ in memory bandwidth, algorithm execution time, you name it
13
Approximating LRU
Many approximations, all use the PTE reference bit
keep a counter for each page
at some regular interval, for each page, do:
if ref bit = 0, increment the counter (hasnt been used)
if ref bit = 1, zero the counter
(has been used)
regardless, zero ref bit
the counter will contain the # of intervals since the last reference
to the page
page with largest counter is least recently used
14
15
global
the victim is chosen from among all page frames, regardless of
owner
processes page frame allocation can vary dynamically
16
Hybrid algorithms
local replacement
an explicit mechanism for adding or removing page frames
17
Why?
Why?
Where would you
like to operate?
Definition:
WS(t,w) = {pages P such that P was referenced in the time interval (t, t-w)}
t: time
w: working set window (measured in page refs)
a page is in the working set (WS) only if it was referenced in the last w
references
obviously the working set (the particular pages) varies over the life of the
program
so does the working set size (the number of pages in the WS)
19
20
21
22
Thrashing
Thrashing is when the system spends most of its
time servicing page faults, little time doing useful
work
could be that there is enough memory but a lousy
replacement algorithm (one incompatible with program
behavior)
could be that memory is over-committed
too many active processes
23
Why?
Why?
Why?
26
Summary
Virtual memory
Page faults
Demand paging
dont try to anticipate
Page replacement
local, global, hybrid
Locality
temporal, spatial
Working set
Thrashing
27
28
29