开发者

Implementing LRU algorithm

开发者 https://www.devze.com 2023-01-17 22:11 出处:网络
I am trying to implement the LRU algorithm, however I am really not so sure how to change the FIFO to LRU and to manipulate the page table in the

I am trying to implement the LRU algorithm, however I am really not so sure how to change the FIFO to LRU and to manipulate the page table in the

//The declared parameters are as follows:
 pt_entry pte[MAX_PAGE];        /* page table */
 int mem_size;          /* physical memory size in page frames */
 list free_list_head;       /* free list */ 
 list res_set_head;         /* resident set */
 int total_fault = 0;       /* total number of page faults */
 int total_ref = 0;         /* total number of memory references */


unsigned short find_victim()
 {
unsigned short frame;
list current;

frame = res_set_head->next->frame;  
invalidate(frame);

current = res_set_head->next;
res_set_head->next = current->next;
res_set_head->next->prev = res_set_head;
to_resident_set(current);

return frame;
 }

   //-----------------开发者_StackOverflow------------------------------------------------

 void resolve(int address)
  {
unsigned short frame_alloc;
int virt_page;
static int disp_counter = 0;

virt_page = address >> 8;
if (pte[virt_page].valid == 1)
{

    }
else
{

    frame_alloc = find_frame();
    pte[virt_page].valid = 1;
    pte[virt_page].frame = frame_alloc;
    total_fault++;
}
   }


One way to implement LRU is to change your resolve() routine to unconditionally move pte[virt_page].frame to the bottom of the resident set list, so that it will be last to be evicted when a new frame is needed.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号