Reputation: 353
I'm doing some theoretical examples with different page replacement algorithms, in order to get a better understanding for when I actually write the code. I'm kind of confused about this example.
Given below is a physical memory with 4 tiles (4 sections?). The following pages are visited one after the other:
R = 1, 2, 3, 2, 4, 5, 3, 6, 1, 4, 2, 3, 1, 4
Run the optimal page replacement algorithm on R with 4 tiles.
I know that when a page needs to be swapped in, the operating system swaps out the page whose next use will occur farthest in the future. In practice I'll have:
Time 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Page 1 2 3 2 4 5 3 6 1 4 2 3 1 4
Tile 1 1 1 1
Tile 2 2 2
Tile 3 3
Tile 4
I'm not sure what happens at time 4 because we get page 2
, but thats already present in the memory. Normally, if it was another number like 6
, then it would go in Tile 4
but I'm lost in this case.
Upvotes: 0
Views: 329
Reputation: 2587
At time t=4
, page 2 is already present, so there is no need to do anything. You can just skip it and move to the next time interval.
If there was a another number like 6
, if there is a free slot available, you move it there, or else find the page that won't be used for the longest duration in the future and swap it.
Upvotes: 1