A main memory can retain up to 4 pages. Which page will be the first one to get a page fault if LRU algorithm is used on the following pages that is in order?
1,2,3,1,2,4,1,2,3
This is a test question which I thought there is no answer to. The main memory can have 4 pages retained, and since there are pages 1,2,3,4, there shouldn't be a page fault occurring.
The answer is 4th page but I don't understand why.
The only way that seems to make sense is if the numbers in that sequence are the in-memory page numbers rather than the pages being retrieved from disk.
In other words, they are the page numbers that have been selected for loading a page into. This is (at least tacitly) supported by the phrase "if LRU algorithm is used on the following pages that is in order".
An LRU algorithm is used to select which page to toss out and re-use so, if it's selected page 1, then that would cause the page to be swapped out for replacement.
So the fourth page in this sense is:
1,2,3,1
^
|
+-- this one.
And, because the first in-memory page is already in use, a page fault occurs to bring in the new page to it.
I can't think of any other scenario that even comes close to matching that answer.