07/10/2020 1
discover yourself
inspire posterity
CHAPTER 4
Optimal Page Replacement Algorithm
1. The optimal page replacement algorithm is an algorithm
when a page needs to be swapped in. The Operating
System swaps out the page whose next use will occur
farthest in the future.
2. Replace page that will not be used for longest period of
time
3. For example, a page that is not going to be used for the
next 6 seconds will be swapped out over a page that is
going to be used within the next 0.4 seconds.
discover yourself
discover yourself
inspire posterity
EXAMPLE-1
The first three references cause faults that fill the three empty frames.
The reference to page 2 replaces page 7, because 7 will not be used until
reference 18, whereas page 0 will be used at 5, and page 1 at 14.
The reference to page 3 replaces page 1, as page 1 will be the last of the
three pages in memory to be referenced again.
With only nine page faults, optimal replacement is much better than a FIFO
algorithm, which resulted in fifteen faults.
discover yourself
discover yourself
inspire posterity
EXAMPLE-2
discover yourself
inspire posterity
EXAMPLE-3
Apply OPTIMAL ALGORITHM
No. of Frames = 3
discover yourself
inspire posterity
EXAMPLE-3 SOLUTION
Apply OPTIMAL ALGO
No. of Frames = 3
0 2 4 6 2 0 9 5 3 8 1 7 1 7
discover yourself
inspire posterity
EXERCISE-1
•
Unfortunately, the optimal page-replacement is difficult
to implement, because it requires future knowledge of
the reference string
discover yourself
Least-Recently-used (LRU) algorithm
•
LRU replacement associates with each page the time
of that page’s last use
•
When a page must be replaced, LRU chooses the page
that has not been used for the longest period of time
discover yourself
discover yourself
inspire posterity
Notice that the first 5 faults are the same as those for optimal
replacement.
When the reference to page 4 occurs, however, LRU replacement sees
that, of the three frames in memory, page 2 was used least recently.
Thus, the LRU algorithm replaces page 2, not knowing that page 2 is
about to be used.
When it then faults for page 2, the LRU algorithm replaces page 3, since it
is now the least recently used of the three pages in memory.
Despite these problems, LRU replacement with 12 faults is much better than
FIFO replacement with 15.
discover yourself
inspire posterity
discover yourself
inspire posterity
Least-Recently-used (LRU) algorithm
discover yourself
inspire posterity
Comparison of OPT with LRU
•
Example: A process of 5 pages
discover yourself
Comparison of FIFO with LRU
•
LRU recognizes that pages 2 and 5 are referenced
more frequently than others but FIFO does not.
A. Frank - P. Weisberg
discover yourself
10/07/202
0 17
Not/Least Frequently Used
The not frequently used (NFU) page replacement algorithm
requires a counter, and every page has one counter of its own
which is initially set to 0. At each clock interval, all pages that
have been referenced within that interval will have their
counter incremented by 1. In effect, the counters keep track of
how frequently a page has been used. Thus, the page with the
lowest counter can be swapped out when necessary.
discover yourself
10/07/202
0 18
discover yourself
inspire posterity
3 7 6 4 6 2 1 9 2 8
Not/Least Frequently Used
10/07/202
0 19
discover yourself
inspire posterity
10/07/202
0 20
discover yourself
inspire posterity
7 0 1 2 0 3 0 4 2 3 0 3 2 1 2
Not/Least Frequently Used
10/07/202
0 21
discover yourself
inspire posterity
10/07/2020 22
Segmentation
(HOME READING)
A process is divided into number of segments that need not
be of equal size. When a process is brought in, all of its
segments are loaded into available regions of memory and
a segment table is set up.
discover yourself
10/07/2020 23
PAGING
1. Main memory is divided into small fixed-size chunks called frames.
2. Program is broken down into small chunks called pages, handled by memory management or compiler.
3. no external fragmentation.
4. OS must maintain a page table for each process showing which frame each process occupy.
5. OS must maintain a free frame list.
6. All the pages of a process must be in main memory for process to run.
Segmentation
1. Main memory not partitioned
2. Program is broken down into segments specified by programmer to the compiler. 3. external fragmentation.
4. OS must maintain a segment table for each process showing which frame each process occupy.
5. OS must maintain a free frame list.
6. All the pages of a process must be in main memory for process to run.