Lecture (Chapter 10)
Lecture (Chapter 10)
Lecture (Chapter 10)
Firoz Mahmud
Assistant Professor
Dept. of Computer Science & Engineering
Rajshahi University of Engineering & Technology
Background
Demand Paging
Copy-on-Write
Page Replacement
Allocation of Frames
Thrashing
Memory-Mapped Files
Allocating Kernel Memory
Other Considerations
Operating-System Examples
To describe the benefits of a virtual memory
system.
i
i
page table
During address translation, if valid–invalid bit in page table entry
is I page fault
If there is a reference to a page, first reference to that page will
trap to operating system:
page fault
1. Operating system looks at another table to decide:
Invalid reference abort
Just not in memory
2. Get empty frame
3. Swap page into frame
4. Reset tables
5. Set validation bit = v
6. Restart the instruction that caused the page fault
Restart instruction
block move
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
The simplest page-replacement algorithm.
When a page must be replaced, the oldest page
is chosen.
We can create a FIFO queue to hold all pages in
memory.
We replace the page at the head of the queue.
When a page is brought into memory, we insert
it at the tail of the queue.
Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
3 frames (3 pages can be in memory at a time per process)
1 1 4 5
2 2 1 3 9 page faults
3 3 2 4
4 frames
1 1 5 4
2 2 1 5 10 page faults
3 3 2
4 4 3
1 4
2 6 page faults
3
1 1 1 1 5
2 2 2 2 2
3 5 5 4 4
4 4 3 3 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
Stack implementation – keep a stack of
page numbers in a double link form:
Page referenced:
move it to the top
requires 6 pointers to be changed
No search for 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 (if one exists)
We do not know the order, however
Second chance
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
Keep a counter of the number of references that
have been made to each page