Operating System Concepts and Techniques Lecture 11
Post on 21-Jan-2016
34 Views
Preview:
DESCRIPTION
Transcript
Operating System Concepts and
Techniques Lecture 11
Memory Management-4
M. Naghibzadeh
ReferenceM. Naghibzadeh, Operating System Concepts and Techniques, First ed., iUniverse Inc., 2011.
To order: www.iUniverse.com, www.barnesandnoble.com, or www.amazon.com
Optimal page replacement policyAlthough not practical, there is an optimal algorithm
Removes the page which will be referred to in the farthest future
2
Page trace 2 3 4 1 5 2 3 5 4 2 1
Page frame 1 2 2 23 22 21 2 23 2 2 2i 1
Page frame 2 3 34 33 32 3 3i 5 5 5i 5
Page frame 3 46 17 53 4 42 4 4 4i 4
Hit? - - - - - + + - + + -
Optimal with a main memory of three frames, H=4, M=7, h=4/11, and m=7/11
Multilevel Page-TableSo far page table was exempted from
page removalWith large page tables memory
efficiency reducesWe have to have a way of knowing
which part (page) of page table is in main memory and which is not
Two level page table serves this purposeWill discuss details in Windows case
study
3
Cache memory management
Cache is a read/write Random access memory similar to main memory but faster
It sits between CPU and main memoryIt is a temporary place for some main
memory locations
4
CPU (registers)
Cache memory
Main memory
Secondary storage
Can be write through or non-write through
Cache memory management…
Most main memory management policies can be adopted to cache
However, there are special policies tooInformation transfer to cache is in block unit, a block
is much smaller than a pageLet’s assume we have 1Mega bytes of cache, block
size of 128 bytesMain memory can be divided into blocks of size 128
bytesAn address in main memory can be shown as
5
Row number Column number Offset 12 bits 13 bits 7 bits
Cache managementWith this policy, only one block of each column of main memory is
in cache
6
0 . . . 213 -1 10
1
2
.
.
.
212-1
2
Are inputs equal?
Yes, address in cache
No, address not in cache
Register array
Physical address
Main memory
Cache memory
The structure to check whether a physical address is in cache or not
Effective access time Suppose cache success rate is 0.9
Therefore, in only 10% of the times an actual access to main memory will take place.
If cache access time is say 20 nanoseconds and main memory access time is 50 nanoseconds, on
the average, it will take 0.9*20 + 0.1*(x + 50) nanoseconds to access what we need
x is the time that takes to fine out what we need to access is in the cache or not.
For x=5 nanosecons effective main memory access time will become 0.9*20 + 0.1*(5 + 50) =
23.5 nanoseconds; much better than 50 nanoseconds
7
Windows case studyTwo-level page tablePage size of 4K bytesAn address looks like
It uses dynamic working set, with default value at the beginning
It uses per process page removalPage removal algorithm is FIFO
It prefetches pages of main memory
8
31 30 … 22 21 20 … 12 11 10 … 2 1 0 Partial Page table Page number Offset
Address translation in Windows
9
Partial page table number Page number Offset
Page frame number Offset
Logical address
Physical address
The partial page table corresponding to left most 10 bits of the logical address
Present?
Yes
No
Interrupt
.
.
.
.
.
.
YesNo
Interrupt
Present?
.
.
.
.
.
.
Directory
Unix case studyOne-level page table
Page size of usually 1K bytesAn address looks like
It uses dynamic working set, with default value at the beginning
It uses global page removalPage removal algorithm is a modified
version of clock
10
31 30 … 22 21 20 … 12 11 10 … 2 1 0 Page number Offset
Unix page removal algorithm
UNIX likes to have a certain minimum number of free page frames all the times, minfree (or
low water level)If it becomes lower, page daemon agent will try
to free page frames until the number of page frames reaches lotsfree (or high water level)
Think of filling up a water tank when the water level is low
It uses a modified version of the clock algorithm to decide which pages to remove
more than one page is removed every time page daemon agent is activated
11
Unix page removal algorithm..
If many frames are scanned by page daemon, but the number of free frames have not
reached lotsfree the process swapper complements the page removal process
Process swapper will swap out some processesThese processes will be swapped back when
the situation improvesWith this view, take one more look at Unix
state transition diagram
12
SummaryCache memory is part of all computers, MM would be incomplete without talking about
cache and the way it is managedIt improves effective memory access time
depending on cache hit ratioTwo case studies were discussed
UNIX uses special concepts such as process swapping, lotsfree and minfree
Windows, on the other hand, uses two-level page table memory management which
allows virtual memory for page tables
13
14
Find outA page replacement policy which always gives
the highest page faultsThe total size of directory and partial page
tables for a 4giga bytes program in WindowsEffective memory access in Windows MM with
two-level page table and cache memory for address traslation
In UNIX, what are the rationales for stopping the page daemon agent when “enough” frames are
scanned but not enough pages are freedThe criteria for selecting a process to swap out
in Unix and vice versa
15
Any questions?
top related