0% found this document useful (0 votes)
31 views

Memory 4

This document discusses memory management techniques. It covers page replacement algorithms like FIFO, optimal, and LRU. It then analyzes the LRU algorithm in more detail and discusses approximations like the clock algorithm. Factors that can lead to page faults like compulsory, capacity, and policy misses are also examined. The importance of page replacement policies for improving memory access time is highlighted.

Uploaded by

nasa stick
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Memory 4

This document discusses memory management techniques. It covers page replacement algorithms like FIFO, optimal, and LRU. It then analyzes the LRU algorithm in more detail and discusses approximations like the clock algorithm. Factors that can lead to page faults like compulsory, capacity, and policy misses are also examined. The importance of page replacement policies for improving memory access time is highlighted.

Uploaded by

nasa stick
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Memory Management

Steps in Handling a Page Fault


Page Replacement
 First-In-First-Out (FIFO) Algorithm
 Page brought first should be replaced first
 Optimal Algorithm
 Replace page that will not be used for longest period of time in
future
 Least Recently Used (LRU) Algorithm
 Replace page that has not been used in the most amount of
time in past
 Reference string: 7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1
Graph of Page Faults Versus The Number of Frames
What Factors Lead to Misses?
 Compulsory Misses:
 Page accessed first time in memory.
 How to fix it?
 Prefetching (Anticipatory Paging)
– Need to predict future!.
 Capacity Misses:
 Not enough memory.
 How to fix it?
 Increase amount of DRAM 
 If multiple processes in memory: adjust percentage of memory
allocated to each one!
 Policy Misses:
 Caused when pages were in memory, but kicked out prematurely
because of the replacement policy
 How to fix it?
 Better replacement policy
Why Page Replacement Policy is Imp ?
 Memory access time = 200 nanoseconds
 Average page-fault service time = 8 milliseconds
EAT = (1 – p) x 200 + p (8 milliseconds)
= (1 – p) x 200 + p x 8,000,000
= 200 + p x 7,999,800
 If one access out of 1,000 causes a page fault,
 Then EAT = 8.2 microseconds.
 This is a slowdown by a factor of 40!!
Least Recently Used (LRU) Algorithm
 “Use past knowledge rather than future”
 Replace page that has not been used in the most amount of time
 Reference string: 7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1
 3 frames (3 pages can be in memory at a time per process)

Page Fault: 12
Least Recently Used (LRU) Algorithm
 Counter implementation
 Each page has a counter.
 Copy clock into counter when page is referenced.
 During Page Replacement
 Search for counter having smallest value
 Search through table needed
 Write to memory in counter during each page access.
 Clock Overflow must be considered.
Least Recently Used (LRU) Algorithm
 Stack implementation
 keep a stack of page numbers in a double link form
 Page referenced:
 move it to the top
 Top of the stack is always the most recently used page
 Update is expensive.
 No search for replacement
 Reference String
 4707101212712
Least Recently Used (LRU) Algorithm
LRU (Approximation) Algorithm
 Clock Algorithm (Second-Chance)
 Arrange physical pages in circle with single clock hand
 Approximate LRU
 Details:
 Hardware “use” bit per physical page:
 Hardware sets use bit on each reference
 If use bit isn’t set, means not referenced in a long time
 On page fault:
 Advance clock hand
 Check use bit: 1used recently; clear and leave alone
0selected candidate for replacement
 Will always find a page or loop forever?
 Even if all use bits set, will eventually loop around  FIFO
 This is Second-Chance, can go for n chances as well.
Enhanced Second chance Algorithm
 Improve algorithm by using reference bit and modify bit
 Take ordered pair (reference, modify)
 (0,0) neither recently use nor modified -> best page to replace
 (0,1) not recently used but modified -> not quite good, because the
page must be written to memory
 (1,0) recently used and clean -> it probably will be used again
 (1,1) recently used and modified -> it probably will be used again and
need to write back.
Free List
 Keep list of free pages ready for use for demand paging
Free-list filled in background by Clock algorithm or other technique
Dirty pages start copying back to disk when they enter this list.
 Advantage: Faster for page fault
 Can always use page (or pages) immediately on fault

Clock Hand

D
Set of all pages
in Memory
D

Free Pages
For Processes

You might also like