Christin
Christin

Reputation: 21

How to implement OPT Page Replacement algorithm in C?

Hello I am trying to implement the OPT Page Replacement algorithm:

Currenly I have created a linked list for all the future memory access references.

And my initial idea was to compare each reference in my linked list and mark down the distance for its next appearence as an attribute. When actually running the program and a page fault happens, I will look through every page in my page table and evict the page that has the longest distance.

However, I find my idea quite complicated and inefficient to implement. Is there a simplier way to implement this algorithm? Thanks.

Upvotes: 1

Views: 975

Answers (1)

David Eisenstat
David Eisenstat

Reputation: 65488

The swaps made are the same for these two executions: (1) OPT on the original sequence of requests (2) LRU on the sequence of requests in reverse order. You can implement LRU via the doubly-linked-list strategy outlined in the linked Wikipedia article.

Upvotes: 0

Related Questions