Os PPT - Unit 4-Part2 - RC
Os PPT - Unit 4-Part2 - RC
UNIT IV
VIRTUAL MEMORY
Dr.R.C.Suganthe
Professor
Kongu Engineering College
Virtual Memory
Background
Demand Paging
Page Replacement
Allocation of Frames
Thrashing
Background
Code needs to be in memory to execute, but
entire program rarely used
Error code, unusual routines
Entire program code not needed at same time
Consider ability to execute partially-loaded
program
Program no longer constrained by limits of physical
memory
Each program takes less memory while running -> more
programs run at the same time
Increased CPU utilization and throughput with no
increase in response time or turnaround time
Less I/O needed to load or swap programs into memory ->
each user program runs faster
Virtual memory
Virtual memory – separation of user logical
memory from physical memory
Only part of the program needs to be in memory for execution
Logical address space can therefore be much larger than physical address space
Allows address spaces to be shared by several processes
Allows for more efficient process creation
More programs running concurrently
Less I/O needed to load or swap processes
replacement
Performance – want an algorithm which will result
Note
2 page transfers for each page fault – increasing EAT
Page Replacement
Page and Frame Replacement Algorithms
Stack implementation
Keep a stack of page numbers in a double
link form:
Page referenced: move it to the top
Always recently used pages available at
the top of the stack and least recently used
available at the bottom of the stack
But each update more expensive
No search for replacement , page at the
bottom of the stack is the victim page for
replacement
LRU Approximation Algorithms
LRU needs special hardware and still slow
Reference bit
With each page associate a bit, initially = 0
When page is referenced bit set to 1
Replace any page with reference bit = 0 (if one exists)
We do not know the order, however
Second-chance algorithm
Generally FIFO, plus hardware-provided reference bit
Clock replacement
If page to be replaced has
Reference bit = 0 -> replace it
reference bit = 1 then:
set reference bit 0, leave page in memory
replace next page, subject to same rules
Second-chance Algorithm
Enhanced Second-Chance
Algorithm
Improve algorithm by using reference bit and modify bit (if available) in
concert
Take ordered pair (reference, modify):
(0, 0) neither recently used not modified – best page to replace
(0, 1) not recently used but modified – not quite as good, must write out
before replacement
(1, 0) recently used but clean – probably will be used again soon
(1, 1) recently used and modified – probably will be used again soon and
29
Course Outcome
On completion of the course, the students will be able
to
CO1 : outline operating system structure, services
and system calls
CO2 : demonstrate various process scheduling
algorithms and describe multithreading models
CO3 : apply different methods for process
synchronization and for handling deadlocks
CO4 : illustrate memory management
strategies and demonstrate various page
replacement algorithms
CO5 : summarize the features of file systems and
apply various disk scheduling algorithms
30
Thank you…..
31
Allocation of Frames
Each process needs minimum number of
frames
Maximum available is total frames in the
system
Two major allocation schemes
fixed allocation
priority allocation
Many variations
Fixed Allocation
Equal allocation – For example, if there are 100 frames (after
allocating frames for the OS) and 5 processes, give each
process 20 frames
Keep some as free frame buffer pool