操作系统实验Ucore lab3

这篇实验报告详细介绍了中山大学数据科学与计算机学院2019年操作系统实验的Ucore lab3——虚拟内存管理。实验涵盖了Page Fault异常处理、页替换算法的实现,包括FIFO算法,并探讨了在UCore中实现extended clock算法的设计方案。实验过程中,学生完成了代码编写,通过了make qemu的测试,展示了页错误处理和页置换的正确执行。
摘要由CSDN通过智能技术生成

lab3

前言

这是中山大学数据科学与计算机学院2019年操作系统实验中关于Ucore的项目以及实验报告,实验要求与Ucore手则有少量出入。
所有源代码已经上传至github。
github个人主页: https://starashzero.github.io
项目地址: https://github.com/StarashZero/Ucore-homework

【实验题目】

实验 4 虚拟内存管理

【实验目的】

  1. 了解虚拟内存的 Page Fault 异常处理实现
  2. 了解页替换算法在操作系统中的实现

【实验要求】

练习 0 :填写已有实验  
练习 1 :给未被映射的地址映射上物理页(需要编程  
练习 2 :补充完成基于 FIFO 的页面替换算法(需要编程)  

【实验方案】

练习 0
这里使用的是系统自带的meld 工具进行整合,只需要选择两个文件夹,然后进行比较,在需要修改的文件中点击 Compare, 填充代码。
在这里插入图片描述
练习 1
do_pgfault 函数是这次要填写的内容

/* do_pgfault - interrupt handler to process the page fault execption
 * @mm         : the control struct for a set of vma using the same PDT
 * @error_code : the error code recorded in trapframe->tf_err which is setted by x86 hardware
 * @addr       : the addr which causes a memory access exception, (the contents of the CR2 register)
 *
 * CALL GRAPH: trap--> trap_dispatch-->pgfault_handler-->do_pgfault
 * The processor provides ucore's do_pgfault function with two items of information to aid in diagnosing
 * the exception and recovering from it.
 *   (1) The contents of the CR2 register. The processor loads the CR2 register with the
 *       32-bit linear address that generated the exception. The do_pgfault fun can
 *       use this address to locate the corresponding page directory and page-table
 *       entries.
 *   (2) An error code on the kernel stack. The error code for a page fault has a format different from
 *       that for other exceptions. The error code tells the exception handler three things:
 *         -- The P flag   (bit 0) indicates whether the exception was due to a not-present page (0)
 *            or to either an access rights violation or the use of a reserved bit (1).
 *         -- The W/R flag (bit 1) indicates whether the memory access that caused the exception
 *            was a read (0) or write (1).
 *         -- The U/S flag (bit 2) indicates whether the processor was executing at user mode (1)
 *            or supervisor mode (0) at the time of the exception.
 */

用于处理 page fault 产生的异常,其中异常主要分为三种,页不存在、页在外存、没有权限等。
在函数中出现两个新出现的结构体 mm_struct:

// the control struct for a set of vma using the same PDT
struct mm_struct {
   
    list_entry_t mmap_list;        // linear list link which sorted by start addr of vma
    struct vma_struct *mmap_cache; // current accessed vma, used for speed purpose
    pde_t *pgdir;                  // the PDT of these vma
    int map_count;                 // the count of these vma
    void *sm_priv;                   // the private data for swap manager
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值