问题
As part of my operating systems homework, I was asked to compare the number of page faults produced by first-in-first-out and least-recently-used page-replacement strategies for a given sequence of page accesses. Perplexingly, it appears that FIFO produced fewer page faults than LRU. Is this possible, or have I made a mistake?
回答1:
Yes, it's possible for FIFO to beat LRU. The smallest example I can think of,
Cache size: 2 pages.
Access pattern: A, B, A, C
After that, the LRU cache contains "A, C", whereas the FIFO cache contains "B, C". They have each missed 3 times so far. So if the next page access is "B", then FIFO beats LRU. If it's "A", LRU beats FIFO. If it's anything else, they remain tied.
回答2:
It's kind of difficult to give you a hint without giving you the answer. Why don't you try setting the question for yourself ? Put yourself in the mind of your teacher, a twisted dark place, and try setting the question in such a way as will make your (fellow) students think deeply about this.
来源:https://stackoverflow.com/questions/9569768/is-it-possible-for-a-fifo-page-replacement-strategy-to-outperform-lru