Browse Source

完成实验3

实现第二次机会页面置换算法
x86-32
423A35C7 7 months ago
parent
commit
e312fbdbd6
1 changed files with 25 additions and 7 deletions
  1. +25
    -7
      labcodes_answer/lab3_result/kern/mm/swap_fifo.c

+ 25
- 7
labcodes_answer/lab3_result/kern/mm/swap_fifo.c View File

@ -69,7 +69,25 @@ _fifo_swap_out_victim(struct mm_struct *mm, struct Page ** ptr_page, int in_tick
//(1) unlink the earliest arrival page in front of pra_list_head qeueue
//(2) set the addr of addr of this page to ptr_page
/* Select the tail */
list_entry_t *le = head->prev;
// 访
list_entry_t *current = head->prev;
list_entry_t *le = NULL;
for (; current != head; current = current->prev) {
pte_t *ptep = get_pte(mm->pgdir, le2vma(current, vm_start), 0);
cprintf("@@@ %d %x :a page\n", *ptep & PTE_A, current);
if (*ptep & PTE_A) { // 访1
*ptep &= !PTE_A; // 访
list_del(current); //
list_add(head, current); //
cprintf("### %d %x :clear access\n", *ptep & PTE_A, current);
} else {
le = current;
break;
}
}
if (le == NULL) {
le = head->prev; //
}
assert(head!=le);
struct Page *p = le2page(le, pra_page_link);
list_del(le);
@ -97,26 +115,26 @@ _fifo_check_swap(void) {
assert(pgfault_num==5);
cprintf("write Virt Page b in fifo_check_swap\n");
*(unsigned char *)0x2000 = 0x0b;
assert(pgfault_num==5);
assert(pgfault_num==6); // FIFO不同了
cprintf("write Virt Page a in fifo_check_swap\n");
*(unsigned char *)0x1000 = 0x0a;
assert(pgfault_num==6);
cprintf("write Virt Page b in fifo_check_swap\n");
*(unsigned char *)0x2000 = 0x0b;
assert(pgfault_num==7);
assert(pgfault_num==6);
cprintf("write Virt Page c in fifo_check_swap\n");
*(unsigned char *)0x3000 = 0x0c;
assert(pgfault_num==8);
assert(pgfault_num==7);
cprintf("write Virt Page d in fifo_check_swap\n");
*(unsigned char *)0x4000 = 0x0d;
assert(pgfault_num==9);
assert(pgfault_num==8);
cprintf("write Virt Page e in fifo_check_swap\n");
*(unsigned char *)0x5000 = 0x0e;
assert(pgfault_num==10);
assert(pgfault_num==8);
cprintf("write Virt Page a in fifo_check_swap\n");
assert(*(unsigned char *)0x1000 == 0x0a);
*(unsigned char *)0x1000 = 0x0a;
assert(pgfault_num==11);
assert(pgfault_num==9);
return 0;
}

Loading…
Cancel
Save