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

  • 相关阅读:
    JAVA数据结构--ArrayList动态数组
    LeetCode记录之35——Search Insert Position
    LeetCode记录之28——Implement strStr()
    LeetCode记录之27——Remove Element
    LeetCode记录之26——Remove Duplicates from Sorted Array
    LeetCode记录之21——Merge Two Sorted Lists
    LeetCode记录之20——Valid Parentheses
    LeetCode记录之14——Longest Common Prefix
    JMeter学习笔记01-安装环境
    Python3学习笔记35-编程练习题
  • 原文地址:https://www.cnblogs.com/-zyq/p/13417424.html
Copyright © 2011-2022 走看看