0

Question:

Consider the following page reference string: 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6.

How many page faults would occur for the optimal page replacement algorithms, assuming five frames? Remember all frames are initially empty, so your first unique pages will all cost one fault each.

I am not quite sure what would happen:

1 -> 1 
2 -> 1, 2
3 -> 1, 2, 3
4 -> 1, 2, 3, 4, 
2 -> What happens here??
1
...etc (with the rest of the reference string)
CWHsu
  • 87
  • 7
  • https://en.wikipedia.org/wiki/Page_replacement_algorithm#The_theoretically_optimal_page_replacement_algorithm – sudo bangbang Apr 09 '16 at 21:03
  • Just a friendly tip, you may want to read over this page: [The How-To-Ask Guide](https://stackoverflow.com/help/how-to-ask) so you can always be sure that your questions are easily answerable and as clear as possible. Be sure to include any efforts you've made to fix the problem you're having, and what happened when you attempted those fixes. Also don't forget to your show code and any error messages! – Matt C Apr 10 '16 at 01:24
  • Also, we know what homework questions look like! We are always more than happy to help with homework, but we also know what a good effort looks like, and we want to see effort! – Matt C Apr 10 '16 at 01:25
  • Also, at least include all of the homework. The question states: `"for the following replacement algorithms"`, but you failed to include those algorithms. – Matt C Apr 10 '16 at 01:26

1 Answers1

1

There will be 7 page faults in total.

1 -> 1 
2 -> 1, 2
3 -> 1, 2, 3
4 -> 1, 2, 3, 4 
2 -> 1, 2, 3, 4    (This is a hit 2 is already in the memory)
1 -> 1, 2, 3, 4
5 -> 1, 2, 3, 4, 5 (This is a miss but we have 5 frames.)
6 -> 1, 2, 3, 6, 5 (4 will be replaced as it is not required in future)
...
sudo bangbang
  • 27,127
  • 11
  • 75
  • 77
  • Hi thanks for the reply! So the 5th frame stays empty till a different element of reference string came up? – CWHsu Apr 09 '16 at 22:57
  • @FearghusSmith: Yes, unless there is a miss, the algorithm won't bother about pages to frames. If this answers your question, please accept the answer. – sudo bangbang Apr 10 '16 at 04:21