2010-09-27 161 views
1

我想實現LRU算法,但我真的不是很確定如何將FIFO改變LRU和操縱頁表來實現LRU是實現LRU算法

//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; 
} 

    //----------------------------------------------------------------- 

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++; 
} 
    } 

回答

1

的一種方式將您的resolve()例程更改爲無條件地將​​移動到常駐套餐列表的底部,以便在需要新框架時最後將其驅逐。