SlideShare ist ein Scribd-Unternehmen logo
1 von 82
8. Virtual Memory
11/15/2014 SDM SVV OS 1
Mr. S. V. Viraktamath
Dept of E&CE,
SDMCT, Dharwad
svvitc2011@gmail..com
Chapter 8: Virtual Memory
• Background
• Demand Paging
• Copy-on-Write
• Page Replacement
• Allocation of Frames
• Thrashing
• Memory-Mapped Files
• Allocating Kernel Memory
• Other Considerations
• Operating-System Examples
Objectives
• To describe the benefits of a virtual memory
system
• To explain the concepts of demand paging,
page-replacement algorithms, and allocation of
page frames
• To discuss the principle of the working-set
model
Background
• Virtual memory is a technique that allows the
execution of processes that may not be
completely in memory.
• Advantage is -programs can be larger than
physical memory.
• Virtual memory is not easy to implement
• May substantially decrease performance if it is
used carelessly.
11/15/2014 SDM SVV OS 4
Background
• 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.
• Virtual memory can be implemented via:
– Demand paging
– Demand segmentation
11/15/2014 SDM SVV OS 5
Background
• The instructions being executed must be in
physical memory.
• Examination of real programs shows us that
– Programs often have code to handle unusual error
conditions.
– Arrays, lists, and tables are often allocated more
memory than they actually need.
• Even if entire program is needed, it may not all
be needed at the same time.
11/15/2014 SDM SVV OS 6
Background
• Benefits: A program would no longer be
constrained by the amount of physical memory
that is available.
• More programs could be run at the same time -
increase in CPU utilization and throughput.
11/15/2014 SDM SVV OS 7
Virtual Memory That is Larger Than Physical Memory

• Virtual memory makes the task of
programming much easier.
• The programmer no longer needs to worry
about the amount of physical memory
available.
• Virtual memory is commonly implemented by
demand paging.
• Demand segmentation can also be used to
provide virtual memory.
11/15/2014 SDM SVV OS 9
Demand Paging
• Bring a page into memory only when it is needed
– Less I/O needed
– Less memory needed
– Faster response
– More users
• Page is needed  reference to it
– invalid reference  abort
– not-in-memory  bring to memory
• Lazy swapper – never swaps a page into memory
unless page will be needed
– Swapper that deals with pages is a pager
Transfer of a paged memory to contiguous disk space.
11/15/2014 SDM SVV OS 11
Valid-Invalid Bit
• With each page table entry a valid–invalid bit
is associated
(v  in-memory, i  not-in-memory)
• Initially valid–invalid bit is set to i on all
entries
• Example of a page table snapshot:
11/15/2014 SDM SVV OS 12
Valid-Invalid Bit
• During address translation, if valid–invalid bit
in page table entry is I  page fault
11/15/2014 SDM SVV OS 13
v
v
v
v
i
i
i
….
Frame # valid-invalid bit
page table
11/15/2014 SDM SVV OS 14
The procedure for handling this page fault is straightforward
11/15/2014 SDM SVV OS 15
Steps for handling the page fault
• We check an internal table – request is valid/
invalid.
• If invalid terminate the process, If valid not in
memory.
• Find the free frame.
• Read the desired page.
• Modify the table.
• Restart the instruction.
11/15/2014 SDM SVV OS 16
• In the extreme case we could start executing a
process with no pages in memory
• First instruction of the process immediately
faults for the page.
• This scheme is pure demand paging
• The hardware to support demand paging
– Page Table
– Secondary memory
11/15/2014 SDM SVV OS 17
• If a page fault occurs while –fetching-operand,
fetch and decode again.
• Ex. C=A+B; all are memory locations.
• Page fault when storing in C!
11/15/2014 SDM SVV OS 18
Performance of Demand Paging
• Page Fault Rate 0  p  1.0
– if p = 0 no page faults
– if p = 1, every reference is a fault
• Effective Access Time (EAT)
EAT = (1 – p) x memory access
+ p (page fault overhead
+ swap page out
+ swap page in
+ restart overhead)
What happens if there is no free frame?
• Page replacement – find some page in
memory, but not really in use, swap it out
– algorithms
– performance – want an algorithm which will result
in minimum number of page faults
• Same page may be brought into memory
several times.
11/15/2014 SDM SVV OS 20
A page fault causes the following sequence to occur
1.Trap to the operating system.
2. Save the user registers and process state.
3. Determine that the interrupt was a page fault.
4. Check that the page reference was legal and
determine the location of the page on the disk.
11/15/2014 SDM SVV OS 21
5. Issue a read from the disk to a free frame:
a. Wait in a queue for this device until the read
request is serviced.
b. Wait for the device seek and/or latency time.
c. Begin the transfer of the page to a free frame.
6. While waiting, allocate the CPU to some other
user (CPU scheduling; optional).
7. Interrupt from the disk (I/O completed).
11/15/2014 SDM SVV OS 22
8. Save the registers and process state for the
other user (if step 6 is executed).
9. Determine that the interrupt was from the disk.
10. Correct the page table and other tables to
show that the desired page is now in memory.
11. Wait for the CPU to be allocated to this
process again.
12. Restore the user registers, process state, and
new page table, then resume the interrupted
instruction.
11/15/2014 SDM SVV OS 23
Page Replacement
• Use modify (dirty) bit to reduce overhead of
page transfers – only modified pages are
written to disk
• Page replacement completes separation
between logical memory and physical memory
– large virtual memory can be provided on a
smaller physical memory
11/15/2014 SDM SVV OS 24
Need For Page Replacement
11/15/2014 SDM SVV OS 25
Basic Page Replacement
1. Find the location of the desired page on disk
2. Find a free frame:
- If there is a free frame, use it
- If there is no free frame, use a page
replacement algorithm to select a victim frame.
3. Bring the desired page into the (newly) free
frame; update the page and frame tables
4. Restart the process
11/15/2014 SDM SVV OS 26
Page Replacement
11/15/2014 SDM SVV OS 27
• We must solve two major problems to
implement demand paging: develop
– a frame-allocation algorithm
– a page-replacement algorithm.
• Many algorithm - How do we select a
particular?
• We want the one with the lowest page-fault
rate.
11/15/2014 SDM SVV OS 28
• Algorithm evaluation done using the string of
mem references and computing No of page
faults.
• The string of memory references is called a
reference string.
– 0100, 0232, 0101, 0612, 0103, 0104, 0101, 0611,
0102, 0103, 0104, 0101, 0610, 0102, 0103, 0104,
0101, 0609, 0102, 0105
• 100 bytes per page, is reduced to the following
reference string
11/15/2014 SDM SVV OS 29
• Memory locations
– 0100, 0432, 0101, 0612, 0102,0103, 0104, 0101,
0611, 0102, 0103, 0104, 0101, 0610, 0102, 0103,
0104, 0101, 0609, 0102, 0105
• First page 0 – 00 to 99; page1 is from 100 to
199…..
• Page numbers are
-141 6 1 1 1 6 1 1 1 1 6 1 1 1 1 6 1 1
• Reference String  1 4 1 6 1 6 1 6 1 6 1
11/15/2014 SDM SVV OS 30
Page Replacement Algorithms
• Want lowest page-fault rate. (Like CPU scheduling lowest
waiting time…)
• Evaluate algorithm by running it on a
particular string of memory references
(reference string) and computing the number
of page faults on that string.
• The reference string considered is (Frames1:5)
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
11/15/2014 SDM SVV OS 31
Graph of Page Faults Versus The Number of Frames
11/15/2014 SDM SVV OS 32
First-In-First-Out (FIFO) Algorithm
• Simplest page replacement algorithm
• Each page associated with time –brought into
mem
• Replace the oldest page
• Not necessary to record the time, Ex.Que,
• Create -FIFO queue
• Replace the page at the head of the queue,
insert page at the tail of the queue.
11/15/2014 SDM SVV OS 33
First-In-First-Out (FIFO) Algorithm
• Reference string: 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
• 3 frames
– (3 pages can be in memory at a time per process)
•  see
11/15/2014 SDM SVV OS 34
First-In-First-Out (FIFO) Algorithm
• FIFO is easy to understand and program
• Performance is not always good
11/15/2014 SDM SVV OS 35
• Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
• Find the number of page faults for the no of
frames – 1,2,3,4,5,6
11/15/2014 SDM SVV OS 36
FIFO Illustrating Belady’s Anomaly
FIFO Illustrating Belady’s Anomaly
11/15/2014 SDM SVV OS 38
• No of page faults for four frames is more than
the no of page faults for three frames.
• This most unexpected result is known as
Belady’s anomaly.
Optimal Algorithm
• Replace page that will not be used for longest period of
time
• 4 frames example see
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
How do you know this?
• Used for measuring how well your algorithm performs
1
2
3
6 page faults
4
1 1
2
1
2
3
1
2
3
5
5
2
3
4
Optimal Page Replacement
see
Least Recently Used (LRU) Algorithm
• Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2,
3, 4, 5
 see
1, 2, 3, 4,1, 2, 5, 1, 2, 3, 4, 5
1
2
3
4
1
2
5
4
2 is most recently used page, next 1 , least is 31
2
5
4
Least Recently Used (LRU) Algorithm
• Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2,
3, 4, 5
 see
1, 2, 3, 4,1, 2, 5, 1, 2, 3, 4, 5
5
2
4
3
1
2
3
4
1
2
5
4
1
2
5
3
1
2
4
3
Least Recently Used (LRU) Algorithm
• Reference string: 1, 2, 3, 4, 1, 2,
• 5, 1, 2, 3, 4, 5
• Counter implementation
– Every page entry has a counter; every time page is
referenced through this entry, copy the clock into
the counter
– When a page needs to be changed, look at the
counters to determine which are to change
5
2
4
3
1
2
3
4
1
2
5
4
1
2
5
3
1
2
4
3
LRU Page Replacement
• Ex 21 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
– 3 Frames
– FIFO=16
– LRU=15
– OPT=11
• Ex3 10 11 104 170 73 309 185 245 246 434
458 364 Page size-100; 00 to 99
– 2 Frames
– FIFO=6
– LRU=5
– OPT=7
11/15/2014 SDM SVV OS 45
• Ex.4 10 11 104 170 73 309 185 245 246 434
458 364
• Page size 50; 4frames
– FIFO=9
– LRU=9
– OPT=9
• 1 2 3 4 5 3 4 1 6 7 6 3 4 1 7 – 4 frames 11 8 12
• 1 2 4 1 2 5 1 2 3 4 5 -3 frames 4 frames
– 7 9 10 AND 12 12 9
11/15/2014 SDM SVV OS 46
• Last Ex. 1 2 3 4 5 3 4 1 6 7 6 3 4 1 7 4 frames
– FOL 11 8 12
11/15/2014 SDM SVV OS 47
• LRU is considered to be good.
• Major problem is how to implement LRU
replacement.
• Two implementations are feasible:
– Counters
– Stack
• Counters
– we associate with each page-table entry a time-of-
use field
11/15/2014 SDM SVV OS 48
• In this way, we always have the “time” of the
last reference to each page. We replace the
page with the smallest time value.
• Overflow of the clock must be considered.
Stack:
• keep a stack of page numbers.
• Whenever a page is referenced, it is removed
from the stack and put on the top.
11/15/2014 SDM SVV OS 49
• The top of the stack is always the most recently
used page and the bottom is the LRU page
11/15/2014 SDM SVV OS 50
• Neither optimal replacement nor LRU
replacement suffers from Belady's anomaly.
• There is a class of page-replacement
algorithms, called stack algorithms, that can
never exhibit Belady's anomaly.
11/15/2014 SDM SVV OS 51
LRU Approximation Page Replacement
• Reference bit
–With each page associate a bit, initially = 0
–When page is referenced bit set to 1
–Replace the one which is 0
• We do not know the order
11/15/2014 SDM SVV OS 52
LRU Approximation Page Replacement
• Additional-Reference-Bits Algorithm
– We can keep an 8-bit byte for each page in a table
in memory
– Shifts the reference bit, shifting the other bits
right-1 bit, discarding the low-order bit.
• 11000100 has been used more recently than
has one with 01110111
11/15/2014 SDM SVV OS 53
LRU Approximation Page Replacement
• Second chance
–If page to be replaced (in clock order) has
reference bit = 1 then:
• set reference bit 0
• leave page in memory
• replace next page (in clock order), subject
to same rules
11/15/2014 SDM SVV OS 54
Second-Chance (clock) Page-Replacement Algorithm
Counting Algorithms
• Keep a counter of the number of references that
have been made to each page.
• LFU Algorithm: replaces page with smallest
count
• MFU Algorithm: based on the argument that the
page with the smallest count was probably just
brought in and has yet to be used
Allocation of frames
• How do we allocate fixed amount of free
frames to processes?
• If only one process –simple; If Demand paging
with multiprogramming?
• Minimum No of frames?
– Ex C=A+B ; worst case No of pages needed
• The mini no of frames defined by the
architecture.
• The max no of frames defined by the amount
of physical memory
11/15/2014 SDM SVV OS 57
Allocation Algorithm
11/15/2014 SDM SVV OS 58
Allocation Algorithm
• Easy way-m-frames; n processes  allocate
each process m/n frames.
• Ex 93 frames 5 processes then each process
will get 18 frames (3 frames free)
• 3 frames used as free frame buffer pool.
• Total frames are 64; only two process are
there.
• Student program may take 1 frame remaining
are waste.
11/15/2014 SDM SVV OS 59
• Solution is Proportional Allocation.
• Allocate frames to each process according to its
size.
• Allocation Algorithm
– Global
– Local
• Local replacement requires that each process
select from only its own set of allocated frames.
• Global replacement allows a process to select a
frame of other process.
11/15/2014 SDM SVV OS 60
• Higher priority process may take frame of
lower priority process.
• Local-the number of frames allocated to a
process does not change.
• Global- The number of frames of a process
may increase
– Pblm- a process cannot control its own page-fault
rate.
11/15/2014 SDM SVV OS 61
Thrashing
• If a process does not have “enough” pages, the
page-fault rate is very high. This leads to:
– low CPU utilization
– operating system thinks that it needs to increase
the degree of multiprogramming
– another process added to the system
• Thrashing  a process is busy swapping pages
in and out
11/15/2014 SDM SVV OS 62
11/15/2014 SDM SVV OS 63
End of Topic
11/15/2014 SDM SVV OS 64
CAT 2 Scheme VII sem
1 a) What do you mean by Deadlock? List and
explain the necessary conditions for the deadlock
to occur.
Ans: Deadlock 1 Mark;
• A process requests resources; if the resources are
not available at that time, the process enters a wait
state. Waiting processes may never again change
state, because the resources they have requested
are held by other waiting processes. This situation
is called a deadlock.
Conditions and Explanation – 4Marks. MHNC
11/15/2014 SDM SVV OS 65
• Mutual exclusion: At least one resource must
be held in a non-sharable mode
• Hold and wait: A process must be holding at
least one resource and waiting to acquire
additional resources that are currently being
held by other processes.
• No preemption: Resources cannot be
preempted -released only voluntarily.
• Circular wait: A set {Po, PI, ..., P,) of waiting
processes must exist such
11/15/2014 SDM SVV OS 66
1b) Explain paging concept for a 32 –byte
memory with 4-bytes pages.
11/15/2014 SDM SVV OS 67
2a) What do you mean by Internal and External
fragmentation? Suggest the methods to reduce the
fragmentation. 2+2+1 Marks
• Ans: External Fragmentation – total memory
space exists to satisfy a request, but it is not
contiguous.
• Internal Fragmentation – allocated memory
may be slightly larger than requested memory;
this size difference is memory internal to a
partition, but not being used.
• Reduce external fragmentation by compaction
11/15/2014 SDM SVV OS 68
b) Explain the following i) Dynamic loading ii) Overlays
Ans: i) So far-the size of a process is limited to the size of
physical memory. To obtain better memory-space utilization -
can use dynamic loading. A routine is not loaded until it is
called.
Main pgm loaded in main mem -routines are kept on disk.
Advantage of dynamic loading - unused routine is never loaded.
ii) Keep in memory only those instructions and data that are
needed at any given time.
Needed when process is larger than amount of memory allocated
to it.
Implemented by user, no special support needed from operating
system, programming design of overlay structure is complex.
11/15/2014 SDM SVV OS 69
11/15/2014 SDM SVV OS 70
• What do you mean by critical section
problem? Explain with example. Write and
explain the Bakery algorithm.
• Ans: Critical section problem – 2, With
example -3; Bakery Algorithm – 5 marks
11/15/2014 SDM SVV OS 71
11/15/2014 SDM SVV OS 72
Mistakes
• In Deadlock – critical section problem
• Bakery algorithm – safe sequence
• Process are allocated to
• 50% Bakery and 50% Bankers
11/15/2014 SDM SVV OS 73
11/15/2014 SDM SVV OS 74
11/15/2014 SDM SVV OS 75
11/15/2014 SDM SVV OS 76
11/15/2014 SDM SVV OS 77
11/15/2014 SDM SVV OS 78
11/15/2014 SDM SVV OS 79
11/15/2014 SDM SVV OS 80
11/15/2014 SDM SVV OS 81
11/15/2014 SDM SVV OS 82

Weitere ähnliche Inhalte

Was ist angesagt?

40 demand paging
40 demand paging40 demand paging
40 demand paging
myrajendra
 
41 page replacement fifo
41 page replacement fifo41 page replacement fifo
41 page replacement fifo
myrajendra
 

Was ist angesagt? (20)

Ch09
Ch09Ch09
Ch09
 
40 demand paging
40 demand paging40 demand paging
40 demand paging
 
Virtual Memory Management
Virtual Memory ManagementVirtual Memory Management
Virtual Memory Management
 
OSCh10
OSCh10OSCh10
OSCh10
 
41 page replacement fifo
41 page replacement fifo41 page replacement fifo
41 page replacement fifo
 
Virtual Memory
Virtual MemoryVirtual Memory
Virtual Memory
 
Demand paging
Demand pagingDemand paging
Demand paging
 
Unit 5
Unit 5Unit 5
Unit 5
 
Virtual Memory Management
Virtual Memory ManagementVirtual Memory Management
Virtual Memory Management
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Virtual Memory - Part1
Virtual Memory - Part1Virtual Memory - Part1
Virtual Memory - Part1
 
basics of virtual memory
basics of virtual memorybasics of virtual memory
basics of virtual memory
 
Virtual memory ppt
Virtual memory pptVirtual memory ppt
Virtual memory ppt
 
Virtual memory
Virtual memory Virtual memory
Virtual memory
 
Virtual memory and page replacement algorithm
Virtual memory and page replacement algorithmVirtual memory and page replacement algorithm
Virtual memory and page replacement algorithm
 
Mem mgt
Mem mgtMem mgt
Mem mgt
 
virtual memory
virtual memoryvirtual memory
virtual memory
 
virtual memory
virtual memoryvirtual memory
virtual memory
 
Unit 2chapter 2 memory mgmt complete
Unit 2chapter 2  memory mgmt completeUnit 2chapter 2  memory mgmt complete
Unit 2chapter 2 memory mgmt complete
 

Andere mochten auch (6)

Page replacement
Page replacementPage replacement
Page replacement
 
Page Replacement Algorithms
Page Replacement AlgorithmsPage Replacement Algorithms
Page Replacement Algorithms
 
Page Replacement
Page ReplacementPage Replacement
Page Replacement
 
Page replacement
Page replacementPage replacement
Page replacement
 
Chapter 9 - Virtual Memory
Chapter 9 - Virtual MemoryChapter 9 - Virtual Memory
Chapter 9 - Virtual Memory
 
Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithms
 

Ähnlich wie O ssvv82014

Lecture 8- Virtual Memory Final.pptx
Lecture 8- Virtual Memory Final.pptxLecture 8- Virtual Memory Final.pptx
Lecture 8- Virtual Memory Final.pptx
Amanuelmergia
 
Virtual Memory sjkdhikejv vsdkjnksnv vkjhfvk
Virtual Memory sjkdhikejv vsdkjnksnv vkjhfvkVirtual Memory sjkdhikejv vsdkjnksnv vkjhfvk
Virtual Memory sjkdhikejv vsdkjnksnv vkjhfvk
HKShab
 
Memory management
Memory managementMemory management
Memory management
Rasi123
 

Ähnlich wie O ssvv82014 (20)

Virtual Memory.pdf
Virtual Memory.pdfVirtual Memory.pdf
Virtual Memory.pdf
 
Virtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdfVirtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdf
 
Lecture 8- Virtual Memory Final.pptx
Lecture 8- Virtual Memory Final.pptxLecture 8- Virtual Memory Final.pptx
Lecture 8- Virtual Memory Final.pptx
 
Virtual Memory Management Part - I.pdf
Virtual Memory Management Part - I.pdfVirtual Memory Management Part - I.pdf
Virtual Memory Management Part - I.pdf
 
Virtual Memory sjkdhikejv vsdkjnksnv vkjhfvk
Virtual Memory sjkdhikejv vsdkjnksnv vkjhfvkVirtual Memory sjkdhikejv vsdkjnksnv vkjhfvk
Virtual Memory sjkdhikejv vsdkjnksnv vkjhfvk
 
Mca ii os u-4 memory management
Mca  ii  os u-4 memory managementMca  ii  os u-4 memory management
Mca ii os u-4 memory management
 
CH09.pdf
CH09.pdfCH09.pdf
CH09.pdf
 
Operating system 38 page replacement
Operating system 38 page replacementOperating system 38 page replacement
Operating system 38 page replacement
 
O ssvv72014
O ssvv72014O ssvv72014
O ssvv72014
 
ch9_virMem.pdf
ch9_virMem.pdfch9_virMem.pdf
ch9_virMem.pdf
 
Lect 27 28_29_30_virtual_memory
Lect 27 28_29_30_virtual_memoryLect 27 28_29_30_virtual_memory
Lect 27 28_29_30_virtual_memory
 
Computer architecture virtual memory
Computer architecture virtual memoryComputer architecture virtual memory
Computer architecture virtual memory
 
16. PagingImplementIssused.pptx
16. PagingImplementIssused.pptx16. PagingImplementIssused.pptx
16. PagingImplementIssused.pptx
 
Segmentation and paging
Segmentation and paging Segmentation and paging
Segmentation and paging
 
Chapter 10 Operating Systems silberschatz
Chapter 10 Operating Systems silberschatzChapter 10 Operating Systems silberschatz
Chapter 10 Operating Systems silberschatz
 
Operating System
Operating SystemOperating System
Operating System
 
Chapter 11 from Operating system by silberschartz
Chapter 11 from Operating system by silberschartzChapter 11 from Operating system by silberschartz
Chapter 11 from Operating system by silberschartz
 
Memory Management
 Memory Management Memory Management
Memory Management
 
بيي
بييبيي
بيي
 
Memory management
Memory managementMemory management
Memory management
 

Kürzlich hochgeladen

Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 

Kürzlich hochgeladen (20)

Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 

O ssvv82014

  • 1. 8. Virtual Memory 11/15/2014 SDM SVV OS 1 Mr. S. V. Viraktamath Dept of E&CE, SDMCT, Dharwad svvitc2011@gmail..com
  • 2. Chapter 8: Virtual Memory • Background • Demand Paging • Copy-on-Write • Page Replacement • Allocation of Frames • Thrashing • Memory-Mapped Files • Allocating Kernel Memory • Other Considerations • Operating-System Examples
  • 3. Objectives • To describe the benefits of a virtual memory system • To explain the concepts of demand paging, page-replacement algorithms, and allocation of page frames • To discuss the principle of the working-set model
  • 4. Background • Virtual memory is a technique that allows the execution of processes that may not be completely in memory. • Advantage is -programs can be larger than physical memory. • Virtual memory is not easy to implement • May substantially decrease performance if it is used carelessly. 11/15/2014 SDM SVV OS 4
  • 5. Background • 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. • Virtual memory can be implemented via: – Demand paging – Demand segmentation 11/15/2014 SDM SVV OS 5
  • 6. Background • The instructions being executed must be in physical memory. • Examination of real programs shows us that – Programs often have code to handle unusual error conditions. – Arrays, lists, and tables are often allocated more memory than they actually need. • Even if entire program is needed, it may not all be needed at the same time. 11/15/2014 SDM SVV OS 6
  • 7. Background • Benefits: A program would no longer be constrained by the amount of physical memory that is available. • More programs could be run at the same time - increase in CPU utilization and throughput. 11/15/2014 SDM SVV OS 7
  • 8. Virtual Memory That is Larger Than Physical Memory 
  • 9. • Virtual memory makes the task of programming much easier. • The programmer no longer needs to worry about the amount of physical memory available. • Virtual memory is commonly implemented by demand paging. • Demand segmentation can also be used to provide virtual memory. 11/15/2014 SDM SVV OS 9
  • 10. Demand Paging • Bring a page into memory only when it is needed – Less I/O needed – Less memory needed – Faster response – More users • Page is needed  reference to it – invalid reference  abort – not-in-memory  bring to memory • Lazy swapper – never swaps a page into memory unless page will be needed – Swapper that deals with pages is a pager
  • 11. Transfer of a paged memory to contiguous disk space. 11/15/2014 SDM SVV OS 11
  • 12. Valid-Invalid Bit • With each page table entry a valid–invalid bit is associated (v  in-memory, i  not-in-memory) • Initially valid–invalid bit is set to i on all entries • Example of a page table snapshot: 11/15/2014 SDM SVV OS 12
  • 13. Valid-Invalid Bit • During address translation, if valid–invalid bit in page table entry is I  page fault 11/15/2014 SDM SVV OS 13 v v v v i i i …. Frame # valid-invalid bit page table
  • 15. The procedure for handling this page fault is straightforward 11/15/2014 SDM SVV OS 15
  • 16. Steps for handling the page fault • We check an internal table – request is valid/ invalid. • If invalid terminate the process, If valid not in memory. • Find the free frame. • Read the desired page. • Modify the table. • Restart the instruction. 11/15/2014 SDM SVV OS 16
  • 17. • In the extreme case we could start executing a process with no pages in memory • First instruction of the process immediately faults for the page. • This scheme is pure demand paging • The hardware to support demand paging – Page Table – Secondary memory 11/15/2014 SDM SVV OS 17
  • 18. • If a page fault occurs while –fetching-operand, fetch and decode again. • Ex. C=A+B; all are memory locations. • Page fault when storing in C! 11/15/2014 SDM SVV OS 18
  • 19. Performance of Demand Paging • Page Fault Rate 0  p  1.0 – if p = 0 no page faults – if p = 1, every reference is a fault • Effective Access Time (EAT) EAT = (1 – p) x memory access + p (page fault overhead + swap page out + swap page in + restart overhead)
  • 20. What happens if there is no free frame? • Page replacement – find some page in memory, but not really in use, swap it out – algorithms – performance – want an algorithm which will result in minimum number of page faults • Same page may be brought into memory several times. 11/15/2014 SDM SVV OS 20
  • 21. A page fault causes the following sequence to occur 1.Trap to the operating system. 2. Save the user registers and process state. 3. Determine that the interrupt was a page fault. 4. Check that the page reference was legal and determine the location of the page on the disk. 11/15/2014 SDM SVV OS 21
  • 22. 5. Issue a read from the disk to a free frame: a. Wait in a queue for this device until the read request is serviced. b. Wait for the device seek and/or latency time. c. Begin the transfer of the page to a free frame. 6. While waiting, allocate the CPU to some other user (CPU scheduling; optional). 7. Interrupt from the disk (I/O completed). 11/15/2014 SDM SVV OS 22
  • 23. 8. Save the registers and process state for the other user (if step 6 is executed). 9. Determine that the interrupt was from the disk. 10. Correct the page table and other tables to show that the desired page is now in memory. 11. Wait for the CPU to be allocated to this process again. 12. Restore the user registers, process state, and new page table, then resume the interrupted instruction. 11/15/2014 SDM SVV OS 23
  • 24. Page Replacement • Use modify (dirty) bit to reduce overhead of page transfers – only modified pages are written to disk • Page replacement completes separation between logical memory and physical memory – large virtual memory can be provided on a smaller physical memory 11/15/2014 SDM SVV OS 24
  • 25. Need For Page Replacement 11/15/2014 SDM SVV OS 25
  • 26. Basic Page Replacement 1. Find the location of the desired page on disk 2. Find a free frame: - If there is a free frame, use it - If there is no free frame, use a page replacement algorithm to select a victim frame. 3. Bring the desired page into the (newly) free frame; update the page and frame tables 4. Restart the process 11/15/2014 SDM SVV OS 26
  • 28. • We must solve two major problems to implement demand paging: develop – a frame-allocation algorithm – a page-replacement algorithm. • Many algorithm - How do we select a particular? • We want the one with the lowest page-fault rate. 11/15/2014 SDM SVV OS 28
  • 29. • Algorithm evaluation done using the string of mem references and computing No of page faults. • The string of memory references is called a reference string. – 0100, 0232, 0101, 0612, 0103, 0104, 0101, 0611, 0102, 0103, 0104, 0101, 0610, 0102, 0103, 0104, 0101, 0609, 0102, 0105 • 100 bytes per page, is reduced to the following reference string 11/15/2014 SDM SVV OS 29
  • 30. • Memory locations – 0100, 0432, 0101, 0612, 0102,0103, 0104, 0101, 0611, 0102, 0103, 0104, 0101, 0610, 0102, 0103, 0104, 0101, 0609, 0102, 0105 • First page 0 – 00 to 99; page1 is from 100 to 199….. • Page numbers are -141 6 1 1 1 6 1 1 1 1 6 1 1 1 1 6 1 1 • Reference String  1 4 1 6 1 6 1 6 1 6 1 11/15/2014 SDM SVV OS 30
  • 31. Page Replacement Algorithms • Want lowest page-fault rate. (Like CPU scheduling lowest waiting time…) • Evaluate algorithm by running it on a particular string of memory references (reference string) and computing the number of page faults on that string. • The reference string considered is (Frames1:5) 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 11/15/2014 SDM SVV OS 31
  • 32. Graph of Page Faults Versus The Number of Frames 11/15/2014 SDM SVV OS 32
  • 33. First-In-First-Out (FIFO) Algorithm • Simplest page replacement algorithm • Each page associated with time –brought into mem • Replace the oldest page • Not necessary to record the time, Ex.Que, • Create -FIFO queue • Replace the page at the head of the queue, insert page at the tail of the queue. 11/15/2014 SDM SVV OS 33
  • 34. First-In-First-Out (FIFO) Algorithm • Reference string: 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 • 3 frames – (3 pages can be in memory at a time per process) •  see 11/15/2014 SDM SVV OS 34
  • 35. First-In-First-Out (FIFO) Algorithm • FIFO is easy to understand and program • Performance is not always good 11/15/2014 SDM SVV OS 35
  • 36. • Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 • Find the number of page faults for the no of frames – 1,2,3,4,5,6 11/15/2014 SDM SVV OS 36
  • 38. FIFO Illustrating Belady’s Anomaly 11/15/2014 SDM SVV OS 38 • No of page faults for four frames is more than the no of page faults for three frames. • This most unexpected result is known as Belady’s anomaly.
  • 39. Optimal Algorithm • Replace page that will not be used for longest period of time • 4 frames example see 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 How do you know this? • Used for measuring how well your algorithm performs 1 2 3 6 page faults 4 1 1 2 1 2 3 1 2 3 5 5 2 3 4
  • 41. Least Recently Used (LRU) Algorithm • Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5  see 1, 2, 3, 4,1, 2, 5, 1, 2, 3, 4, 5 1 2 3 4 1 2 5 4 2 is most recently used page, next 1 , least is 31 2 5 4
  • 42. Least Recently Used (LRU) Algorithm • Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5  see 1, 2, 3, 4,1, 2, 5, 1, 2, 3, 4, 5 5 2 4 3 1 2 3 4 1 2 5 4 1 2 5 3 1 2 4 3
  • 43. Least Recently Used (LRU) Algorithm • Reference string: 1, 2, 3, 4, 1, 2, • 5, 1, 2, 3, 4, 5 • Counter implementation – Every page entry has a counter; every time page is referenced through this entry, copy the clock into the counter – When a page needs to be changed, look at the counters to determine which are to change 5 2 4 3 1 2 3 4 1 2 5 4 1 2 5 3 1 2 4 3
  • 45. • Ex 21 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6 – 3 Frames – FIFO=16 – LRU=15 – OPT=11 • Ex3 10 11 104 170 73 309 185 245 246 434 458 364 Page size-100; 00 to 99 – 2 Frames – FIFO=6 – LRU=5 – OPT=7 11/15/2014 SDM SVV OS 45
  • 46. • Ex.4 10 11 104 170 73 309 185 245 246 434 458 364 • Page size 50; 4frames – FIFO=9 – LRU=9 – OPT=9 • 1 2 3 4 5 3 4 1 6 7 6 3 4 1 7 – 4 frames 11 8 12 • 1 2 4 1 2 5 1 2 3 4 5 -3 frames 4 frames – 7 9 10 AND 12 12 9 11/15/2014 SDM SVV OS 46
  • 47. • Last Ex. 1 2 3 4 5 3 4 1 6 7 6 3 4 1 7 4 frames – FOL 11 8 12 11/15/2014 SDM SVV OS 47
  • 48. • LRU is considered to be good. • Major problem is how to implement LRU replacement. • Two implementations are feasible: – Counters – Stack • Counters – we associate with each page-table entry a time-of- use field 11/15/2014 SDM SVV OS 48
  • 49. • In this way, we always have the “time” of the last reference to each page. We replace the page with the smallest time value. • Overflow of the clock must be considered. Stack: • keep a stack of page numbers. • Whenever a page is referenced, it is removed from the stack and put on the top. 11/15/2014 SDM SVV OS 49
  • 50. • The top of the stack is always the most recently used page and the bottom is the LRU page 11/15/2014 SDM SVV OS 50
  • 51. • Neither optimal replacement nor LRU replacement suffers from Belady's anomaly. • There is a class of page-replacement algorithms, called stack algorithms, that can never exhibit Belady's anomaly. 11/15/2014 SDM SVV OS 51
  • 52. LRU Approximation Page Replacement • Reference bit –With each page associate a bit, initially = 0 –When page is referenced bit set to 1 –Replace the one which is 0 • We do not know the order 11/15/2014 SDM SVV OS 52
  • 53. LRU Approximation Page Replacement • Additional-Reference-Bits Algorithm – We can keep an 8-bit byte for each page in a table in memory – Shifts the reference bit, shifting the other bits right-1 bit, discarding the low-order bit. • 11000100 has been used more recently than has one with 01110111 11/15/2014 SDM SVV OS 53
  • 54. LRU Approximation Page Replacement • Second chance –If page to be replaced (in clock order) has reference bit = 1 then: • set reference bit 0 • leave page in memory • replace next page (in clock order), subject to same rules 11/15/2014 SDM SVV OS 54
  • 56. Counting Algorithms • Keep a counter of the number of references that have been made to each page. • LFU Algorithm: replaces page with smallest count • MFU Algorithm: based on the argument that the page with the smallest count was probably just brought in and has yet to be used
  • 57. Allocation of frames • How do we allocate fixed amount of free frames to processes? • If only one process –simple; If Demand paging with multiprogramming? • Minimum No of frames? – Ex C=A+B ; worst case No of pages needed • The mini no of frames defined by the architecture. • The max no of frames defined by the amount of physical memory 11/15/2014 SDM SVV OS 57
  • 59. Allocation Algorithm • Easy way-m-frames; n processes  allocate each process m/n frames. • Ex 93 frames 5 processes then each process will get 18 frames (3 frames free) • 3 frames used as free frame buffer pool. • Total frames are 64; only two process are there. • Student program may take 1 frame remaining are waste. 11/15/2014 SDM SVV OS 59
  • 60. • Solution is Proportional Allocation. • Allocate frames to each process according to its size. • Allocation Algorithm – Global – Local • Local replacement requires that each process select from only its own set of allocated frames. • Global replacement allows a process to select a frame of other process. 11/15/2014 SDM SVV OS 60
  • 61. • Higher priority process may take frame of lower priority process. • Local-the number of frames allocated to a process does not change. • Global- The number of frames of a process may increase – Pblm- a process cannot control its own page-fault rate. 11/15/2014 SDM SVV OS 61
  • 62. Thrashing • If a process does not have “enough” pages, the page-fault rate is very high. This leads to: – low CPU utilization – operating system thinks that it needs to increase the degree of multiprogramming – another process added to the system • Thrashing  a process is busy swapping pages in and out 11/15/2014 SDM SVV OS 62
  • 64. End of Topic 11/15/2014 SDM SVV OS 64
  • 65. CAT 2 Scheme VII sem 1 a) What do you mean by Deadlock? List and explain the necessary conditions for the deadlock to occur. Ans: Deadlock 1 Mark; • A process requests resources; if the resources are not available at that time, the process enters a wait state. Waiting processes may never again change state, because the resources they have requested are held by other waiting processes. This situation is called a deadlock. Conditions and Explanation – 4Marks. MHNC 11/15/2014 SDM SVV OS 65
  • 66. • Mutual exclusion: At least one resource must be held in a non-sharable mode • Hold and wait: A process must be holding at least one resource and waiting to acquire additional resources that are currently being held by other processes. • No preemption: Resources cannot be preempted -released only voluntarily. • Circular wait: A set {Po, PI, ..., P,) of waiting processes must exist such 11/15/2014 SDM SVV OS 66
  • 67. 1b) Explain paging concept for a 32 –byte memory with 4-bytes pages. 11/15/2014 SDM SVV OS 67
  • 68. 2a) What do you mean by Internal and External fragmentation? Suggest the methods to reduce the fragmentation. 2+2+1 Marks • Ans: External Fragmentation – total memory space exists to satisfy a request, but it is not contiguous. • Internal Fragmentation – allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used. • Reduce external fragmentation by compaction 11/15/2014 SDM SVV OS 68
  • 69. b) Explain the following i) Dynamic loading ii) Overlays Ans: i) So far-the size of a process is limited to the size of physical memory. To obtain better memory-space utilization - can use dynamic loading. A routine is not loaded until it is called. Main pgm loaded in main mem -routines are kept on disk. Advantage of dynamic loading - unused routine is never loaded. ii) Keep in memory only those instructions and data that are needed at any given time. Needed when process is larger than amount of memory allocated to it. Implemented by user, no special support needed from operating system, programming design of overlay structure is complex. 11/15/2014 SDM SVV OS 69
  • 71. • What do you mean by critical section problem? Explain with example. Write and explain the Bakery algorithm. • Ans: Critical section problem – 2, With example -3; Bakery Algorithm – 5 marks 11/15/2014 SDM SVV OS 71
  • 73. Mistakes • In Deadlock – critical section problem • Bakery algorithm – safe sequence • Process are allocated to • 50% Bakery and 50% Bankers 11/15/2014 SDM SVV OS 73