zoukankan      html  css  js  c++  java
  • [OS][MIT 6.828] Lab 2: Memory Management

    Lab link: https://pdos.csail.mit.edu/6.828/2018/labs/lab2/

    Introduction

    Memory management has two components:

    1. a physical memory allocator for the kernel, so that the kernel can allocate memory and later free it.
    2. virtual memory, which maps the virtual addresses used by kernel and user software to addresses in physical memory. The x86 hardware's memory management unit (MMU) performs the mapping when instructions use memory, consulting a set of page tables.

    Some critical variables in JOS:

    struct PageInfo *pages;             // whole physical memory
    struct PageInfo *page_free_list;    // free physical memory
    pde_t           *kern_pgdir;        // whole virtual memory space
    

    1 PageInfo struct represents 1 physical page, 1 pte represents 1 page.
    given 1 va, you can determine whether it has been mapped by looking at whether the corresponding pte present or not.

    Part 1: Physical Page Management

    The operating system keep track of which parts of physical RAM are free and which are currently in use. JOS manages the PC's physical memory with page granularity.

    This part implememts the physical page allocator. It keeps track of which pages are free with a linked list of struct PageInfo objects, each corresponding to a physical page.

    // If n>0, allocates enough pages of CONTIGUOUS physical memory to hold 'n' bytes.
    // This simple physical memory allocator is used only while JOS is setting up its virtual memory system.  page_alloc() is the real allocator. So this function is 
    // static.
    // This function may ONLY be used during initialization, before the **page_free_list** list has been set up.
    static void * boot_alloc(uint32_t n)
    
    // Initialize page structure and memory free list. After this is done, boot_alloc() will NEVER be used again.
    void page_init(void)
    
    // Allocates a physical page. Does NOT increment the reference count of the page.
    struct PageInfo * page_alloc(int alloc_flags)
    
    // Return a page to the free list.
    void page_free(struct PageInfo *pp)
    

    Part 2: Virtual Memory

    Address translation scheme:

    // returns a pointer to the PTE for linear address 'va'.
    pte_t * pgdir_walk(pde_t *pgdir, const void *va, int create)
    
    // Map [va, va+size) of virtual address space to physical [pa, pa+size) in the page table rooted at pgdir.
    static void boot_map_region(pde_t *pgdir, uintptr_t va, size_t size, physaddr_t pa, int perm)
    
    // Unmaps the physical page at virtual address 'va'.
    void page_remove(pde_t *pgdir, void *va)
    
    // Map the physical page 'pp' at virtual address 'va'.
    int page_insert(pde_t *pgdir, struct PageInfo *pp, void *va, int perm)
    
    // Reserve size bytes in the MMIO region and map [pa,pa+size) at this location. Used in lab 4.
    void * mmio_map_region(physaddr_t pa, size_t size)
    

    Part 3: Kernel Address Space

  • 相关阅读:
    数学是最好的语言
    人类的语言--自然语言--》逻辑语言
    为什么大脑喜欢看图?
    思考是调用大脑存储的上下文对输入信息进行处理的过程
    Redis的相关问题总结
    TP5 关联模型使用(嵌套关联、动态排序以及隐藏字段)
    array_column 函数, 以及在PHP5.5之下的替代方法
    thinkphp在app接口开发过程中的通讯安全认证
    PHP开发APP接口实现--基本篇
    分布式与集群的区别是什么?
  • 原文地址:https://www.cnblogs.com/-zyq/p/13417424.html
Copyright © 2011-2022 走看看