ucore lab3

## OS course ucore_lab3 test report

Exercise Zero: fill in existing experiments

  This experiment ½-dependent assays. Please put the code you do the experiment 1/2 fill this experiment code has a corresponding part of the "LAB1", "LAB2" comments.

下面三个, 复制过去就ok
pmm.c default_pmm.c trap.c

Exercise 1: address not mapped to the mapping of the physical page (requires programming)

  Completion do_pgfault (mm / vmm.c) function, the address is not mapped to the physical page map. Set access permissions page where the reference when you need VMA, and needs attention to the need to control the operation of memory page table structure specified when mapping the physical page, not the kernel page table. Note: Enter the code LAB2 EXERCISE 1 place. Execution make qemu after, if tested check_pgfault function, there will be "check_pgfault () succeeded!", This means the basic right to practice 1.

do_pgfault(){
    ptep = get_pte(mm->pgdir, addr, 1); // 根据引发缺页异常的地址 去找到 地址所对应的 PTE 如果找不到 则创建一页表
    if (*ptep == 0) { // PTE 所指向的 物理页表地址 若不存在 则分配一物理页并将逻辑地址和物理地址作映射 (就是让 PTE 指向 物理页帧)
        if (pgdir_alloc_page(mm->pgdir, addr, perm) == NULL) {
            goto failed;
        }
    } else { // 如果 PTE 存在 说明此时 P 位为 0 该页被换出到外存中 需要将其换入内存
        if(swap_init_ok) { // 是否可以换入页面
            struct Page *page = NULL;
            ret = swap_in(mm, addr, &page); // 根据 PTE 找到 换出那页所在的硬盘地址 并将其从外存中换入
            if (ret != 0) {
                cprintf("swap_in in do_pgfault failed\n");
                goto failed;
            }
            page_insert(mm->pgdir, page, addr, perm); // 建立虚拟地址和物理地址之间的对应关系(更新 PTE 因为 已经被换入到内存中了)
            swap_map_swappable(mm, addr, page, 0); // 使这一页可以置换
            page->pra_vaddr = addr; // 设置 这一页的虚拟地址
        }
}

  Please briefly describe your design implementation process in the test report. Please answer the following questions:

  Please describe the part of the page directory entry (Pag Director Entry) and page table (Page Table Entry) in the realization of the potential usefulness ucore page replacement algorithm.
  If ucore page fault service routine memory access during execution, there was page access exception, what hardware do what you ask?

Refer lab2

Exercise 2: Supplementary complete replacement algorithm (requires programming) based on FIFO page

  The complete vmm.c do_pgfault function, and completes map_swappable and swap_out_vistim functions implemented swap_fifo.c FIFO algorithm. By testing for the swap. Note: Enter the code at LAB2 EXERCISE 2. Execution make qemu after, if tested check_swap function, there will be "check_swap () succeeded!", This means the 2 basic exercises correctly.

  Please briefly describe your design implementation process in the test report.

FIFO 置换算法 因此 每次换出的都应该是 最先进来的 页
static int _fifo_map_swappable(struct mm_struct *mm, uintptr_t addr, struct Page *page, int swap_in) {
    list_entry_t *head=(list_entry_t*) mm->sm_priv;
    list_entry_t *entry=&(page->pra_page_link);
 
    assert(entry != NULL && head != NULL);

    list_add(head, entry); // 就是将这一页加入到链表头中(最近访问过的放前面) 使其可以被置换算法使用到
    return 0;
}
static int _fifo_swap_out_victim(struct mm_struct *mm, struct Page ** ptr_page, int in_tick) {
    list_entry_t *head=(list_entry_t*) mm->sm_priv;
    assert(head != NULL);
    assert(in_tick==0);

    list_entry_t *le = head->prev; // 换出最先进来的页 (因为每次访问一个页 都是插入到头节点的后面 因此 头节点的前面就是最先访问的页)
    struct Page* page = le2page(le, pra_page_link); // 和之前一样 通过 le 这个链表节点的地址 减去 pra_page_link 在 Page 结构体中的 Offset 得到 Page 的地址
    list_del(le); // 删掉这个节点
    *ptr_page = page; // 将这一页地址存到 ptr_page 中 给 调用本函数的函数使用
    return 0;
}

  Please answer the following questions in the test report:

  If you want to achieve "extended clock page replacement algorithm" on ucore Please send your design, swap_manager the existing framework is sufficient to support the implementation of this algorithm in ucore? If yes, please give your design. If not, please give your new extension and expansion of the base of this design. And the need to answer the following questions

  • What are the characteristics of the page needs to be swapped out is?
  • In ucore how to determine the page with such features?
  • When to be swapped in and out of operation?
支持
首选 页表项的 Dirty Bit 为 0 的页 且 Access Bit 为 0 的页 其次是 访问了但没修改的页 最次是 访问了修改了的页
!(*ptep & PTE_A) && !(*ptep & PTE_D)  没被访问过 也没被修改过
(*ptep & PTE_A) && !(*ptep & PTE_D) 被访问过 但没被修改过
!(*ptep & PTE_A) && (*ptep & PTE_D) 没被访问过 但被修改过
换入是在缺页异常的时候 换出是在物理页帧满的时候

参考:
[1]https://yuerer.com/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F-uCore-Lab-3/

Guess you like

Origin www.cnblogs.com/fans-fan/p/11922780.html