The First In First Out (FIFO)
page replacement policy
- The FIFO
page replacement policy:
- Replace (= take out) the
program page that
was brought in the
earliest
|
- Implementing the
FIFO
page replacement
policy:
Assume without lost of generality that the memory frames used
are numbered as 0 .. M-1:
Memory frames:
+-----------+
0 | |
+-----------+
1 | |
+-----------+
2 | |
+-----------+
.........
+-----------+
M-1 | |
+-----------+
|
|
The First In First Out (FIFO)
page replacement policy
- The FIFO
page replacement policy:
- Replace (= take out) the
program page that
was brought in the
earliest
|
- Implementing the
FIFO
page replacement
policy:
Use an index to point to the target page that will be replaced
when a page fault occurs:
Memory frames:
+-----------+
(replace this page) next --> 0 | |
+-----------+
1 | |
+-----------+
2 | |
+-----------+
.........
+-----------+
M-1 | |
+-----------+
|
|
The First In First Out (FIFO)
page replacement policy
- The FIFO
page replacement policy:
- Replace (= take out) the
program page that
was brought in the
earliest
|
- Implementing the
FIFO
page replacement
policy:
Each time a page is replaced, increase the index by 1:
I.e.: next = (next + 1)%M
Memory frames:
+-----------+
0 | replaced |
+-----------+
(replace this page) next --> 1 | |
+-----------+
2 | |
+-----------+
.........
+-----------+
M-1 | |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
|
- Suppose the
running program is
assigned to use
3
memory frames
Without loss of generality, we use the frame 0, 1, 2
to study the performance of the FIFO policy
Memory frames:
+-----------+
0 | |
+-----------+
1 | |
+-----------+
2 | |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Initialization:
All frames are empty
Memory frames:
+-----------+
next --> 0 | |
+-----------+
1 | |
+-----------+
2 | |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Requested page =
0 --->
page fault
Read page 0 from disk and place in memory frame 0
Memory frames:
+-----------+
next --> 0 | |
+-----------+
1 | |
+-----------+
2 | |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Result:
# page faults = 1
Memory frames:
+-----------+
0 | 0 |
+-----------+
next --> 1 | |
+-----------+
2 | |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Requested page =
4 --->
page fault
Read page 4 from disk and place in memory frame 1
Memory frames:
+-----------+
0 | 0 |
+-----------+
next --> 1 | |
+-----------+
2 | |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Result:
# page faults = 2
Memory frames:
+-----------+
0 | 0 |
+-----------+
1 | 4 |
+-----------+
next --> 2 | |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Requested page =
1 --->
page fault
Read page 1 from disk and place in memory frame 2
Memory frames:
+-----------+
0 | 0 |
+-----------+
1 | 4 |
+-----------+
next --> 2 | |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Result:
# page faults = 3
Memory frames:
+-----------+
next --> 0 | 0 |
+-----------+
1 | 4 |
+-----------+
2 | 1 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Requested page =
4 --->
page HIT !!
# page faults = 3
Memory frames:
+-----------+
next --> 0 | 0 |
+-----------+
1 | 4 |
+-----------+
2 | 1 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Requested page =
2 --->
page fault
Read page 2 from disk and place in memory frame 0
Memory frames:
+-----------+
next --> 0 | 0 |
+-----------+
1 | 4 |
+-----------+
2 | 1 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Result:
# page faults = 4
Memory frames:
+-----------+
0 | 2 |
+-----------+
next --> 1 | 4 |
+-----------+
2 | 1 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Requested page =
4 --->
page HIT
# page faults = 4
Memory frames:
+-----------+
0 | 2 |
+-----------+
next --> 1 | 4 |
+-----------+
2 | 1 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Requested page =
3 --->
page fault
Read page 3 from disk and place in memory frame 1
Memory frames:
+-----------+
0 | 2 |
+-----------+
next --> 1 | 4 |
+-----------+
2 | 1 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Result:
# page faults = 5
Memory frames:
+-----------+
0 | 2 |
+-----------+
1 | 3 |
+-----------+
next --> 2 | 1 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Requested page =
4 --->
page fault
Read page 4 from disk and place in memory frame 2
Memory frames:
+-----------+
0 | 2 |
+-----------+
1 | 3 |
+-----------+
next --> 2 | 1 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Result:
# page faults = 6
Memory frames:
+-----------+
next --> 0 | 2 |
+-----------+
1 | 3 |
+-----------+
2 | 4 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Requested page =
2 --->
page HIT
# page faults = 6
Memory frames:
+-----------+
next --> 0 | 2 |
+-----------+
1 | 3 |
+-----------+
2 | 4 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Requested page =
4 --->
page HIT
# page faults = 6
Memory frames:
+-----------+
next --> 0 | 2 |
+-----------+
1 | 3 |
+-----------+
2 | 4 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Requested page =
0 --->
page fault
Read page 0 from disk and place in memory frame 0
Memory frames:
+-----------+
next --> 0 | 2 |
+-----------+
1 | 3 |
+-----------+
2 | 4 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Result:
# page faults = 7
Memory frames:
+-----------+
0 | 0 |
+-----------+
next --> 1 | 3 |
+-----------+
2 | 4 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Requested page =
4 --->
page HIT
# page faults = 7
Memory frames:
+-----------+
0 | 0 |
+-----------+
next --> 1 | 3 |
+-----------+
2 | 4 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Requested page =
1 --->
page fault
Read page 1 from disk and place in memory frame 1
Memory frames:
+-----------+
0 | 0 |
+-----------+
next --> 1 | 3 |
+-----------+
2 | 4 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Result:
# page faults = 8
Memory frames:
+-----------+
0 | 0 |
+-----------+
1 | 1 |
+-----------+
next --> 2 | 4 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Requested page =
4 --->
page HIT
# page faults = 8
Memory frames:
+-----------+
0 | 0 |
+-----------+
1 | 1 |
+-----------+
next --> 2 | 4 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Requested page =
2 --->
page fault
Read page 2 from disk and place in memory frame 2
Memory frames:
+-----------+
0 | 0 |
+-----------+
1 | 1 |
+-----------+
next --> 2 | 4 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Result:
# page faults = 9
Memory frames:
+-----------+
next --> 0 | 0 |
+-----------+
1 | 1 |
+-----------+
2 | 2 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Requested page =
4 --->
page fault
Read page 4 from disk and place in memory frame 0
Memory frames:
+-----------+
next --> 0 | 0 |
+-----------+
1 | 1 |
+-----------+
2 | 2 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Result:
# page faults = 10
Memory frames:
+-----------+
0 | 4 |
+-----------+
next --> 1 | 1 |
+-----------+
2 | 2 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Requested page =
3 --->
page fault
Read page 3 from disk and place in memory frame 1
Memory frames:
+-----------+
0 | 4 |
+-----------+
next --> 1 | 1 |
+-----------+
2 | 2 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Result:
# page faults = 11
Memory frames:
+-----------+
0 | 4 |
+-----------+
1 | 3 |
+-----------+
next --> 2 | 2 |
+-----------+
|
|
Example of
the First In First Out (FIFO)
page replacement policy
- Summary of
the page requests
made by the running program:
-
0 4 1 4 2 4 3 4
2 4 0 4 1 4 2 4
3 4
⇑
|
- Requested page =
4 --->
page HIT
# page faults = 11
Memory frames:
+-----------+
0 | 4 |
+-----------+
1 | 3 |
+-----------+
next --> 2 | 2 |
+-----------+
|
|
Total # page faults =
11
❮
❯