Professional Documents
Culture Documents
Lecture 10 New
Lecture 10 New
Virtual Memory
Virtual Memory
• Background
• Demand Paging
• Performance of Demand Paging
• Page Replacement
• Page Replacement Algorithms
• Allocation of Frames
• Thrashing
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.
– Allows address spaces to be shared by several processes.
– Allows for more efficient process creation.
• Restart instruction
– block move
– algorithm
– performance – want an algorithm which will result in
minimum number of page faults.
- Copy-on-Write
- Memory-Mapped Files
Copy-on-Write
• Page Table
– Has the ability to mark an entry invalid through a
valid-invalid bit or special value of protection bits.
• Secondary memory
– Holds those pages that are not present in main
memory.
– Usually a high speed disk.
– Known as swap device, and the section of disk used
for this purpose is known as swap space or backing
store.
Page Replacement
• Prevent over-allocation of memory by modifying page-
fault service routine to include page replacement.
3. Read the desired page into the (newly) free frame. Update
the page and frame tables.
1 1 4 5
2 2 1 3 9 page faults
• 4 frames 3 3 2 4
1 1 5 4
4 4 3
FIFO Illustrating Belady’s Anamoly
Optimal Algorithm
• Replace the page that will not be used for longest period
of time.
Least Recently Used (LRU) Algorithm
• Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
1 5
2
3 5 4
4 3
• 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.
LRU Page Replacement
LRU Algorithm (Cont.)
• Additional-Reference-bits Algorithm
• Second-chance Algorithm
– Pick a page based on FIFO.
– Need reference bit.
– Clock replacement.
– 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.
Second-Chance (clock) Page-Replacement
Algorithm
Counting Algorithms
• When there are far too many processes (i. e., memory is
over committed), the resident set of each process is
smaller. This leads to higher page fault frequency,
causing the system to exhibit a behavior known as
thrashing.