理解Computer中Address space\MMU\PTE\TLB\Page table\Page out

  • address space

    wikipedia

    An address space defines a range of discrete addresses, each of which may corresond to a nerwork host, peripheral device, disk sector, a memory cell or other logical or physical entity.

  • Memory management unit (MMU)

    wikipedia

    MMU, sometime called paged memory management unit(PMMU), is a computer hardware unit having all memory references passed through itself, primarily performing the translation of virtual memory addresses to physical addresses.

    An MMU effectively performs virtual memory management, handling at the same time

    • memory protection
    • cache control
    • bus arbitration
    • bank switching
  • Page Table Entry(PTE)

    wikipedia

    In operating systems that use virtual memory, every process is given the impression that it is working with large, contiguous sections of memory. Physically, the momery of each process may be dispersed across diferent areas of physical memory, or may have been moved (paged out) to another storage, typically to a hard disk drive.

    When a process requests access to data in its memory, it is the responsibility of the operating system to map the virtual address provided by the process to the physical address of the actual memory where that data is stored.

    The page table is where the operating system stores its mappings of virtual addresses to physical addresses, with each mapping also known as a page table entry(PTE).

    PTE 就是一条映射记录。

  • Translation Lookaside Buffer(TLB)

    The CPU’s memory management unit(MMU) stores a cache of recently used mappings from the operating system’s page table. This is called the translation lookaside buffer(TLB), which is an associative cache.

    When a virtual address needs to be translated into a physical address, the TLB is searched first. If a match is found(a TLB hit ), the physical address is returned and memory access can continue. However, if there is no match(called a TBL miss), the memory management unit, or the OS TLB miss handler, will typically look up the address mapping in the page table to see whether a mapping exists(a page walk). If one exists, it is written back to the TLB(this must be done, as the hardware accesses memory through the TLB in a virtual memory system), and the faulting instruction is restarted(this may happen in parallel as well)

  • Translation failures

    The page table lookup may fail for two reasons:

    • There is no translation available for the virtual address, meaning that virtual address is invalid. It will cause a segmentation fault.

    • The page is currently not resident in physical memory. This will occur if the requested page has been moved out of physical memory to make room for another page. The page is paged out to a secondary store located on a medium such as a hard disk drive(this secondary store, or “backing store”, is often called a “swap partition” if it is a disk partition, or a swap file, “swap file” or “page file” if it is a file). When this happens the page needs to be taken from disk and put back into physical memory. A similar mechanism is used for memory-mapped file, which are mapped to virtual memory and loaded to physical memory on demand.

      这段话是理解memory-mapped file的关键所在,page指的是virtual memory上的,正常情况,page address通过page table与primary memory 的physical address一一对象,但是为了给其他虚拟内存上的page留空间,可能把还在vitual memory上的page对应的pysical address删掉了。

      which page to page out is the subject of page replacement algorithms.

  • Page table

    wikipedia

    A page table is the data structure used by a virtual memory system in a computer OS to store the mapping between virtual addresses and physical addresses. Vitual addresses are used by the program executed by the accessing process, while physical addresses are used by the hardware, or mare specifically, by the RAM subsystem.

    The simplest page table systems often maintain a frame table and a page table:

    • frame table

      The frame table holds information about which frames are mapped in

    • page table

      The page table holds the mapping between a virtual address of a page and the address of a physical frame.

  • Page table types

    1. Inverted page tables
    2. Multilevel page tables
    3. Virtualized page tables
    4. Nested page tables
  • Page replacement algotithm

    wikipedia

    In a computer OS that uses paging for virtual memory management, page replacement algotithms decide which memory pages to page out, sometimes called swap out, or wirte to disk, when a page of memory needs to be allocated.

    Page replacement happens when a requested page is not in memory(page fault) and a free page cannot be used to satisfy the allocation.

    When the page that was selected for replacement and paged out is referenced again it has to be paged in (read in from disk), and this involves waiting for I/O completion.

你可能感兴趣的:(Linux)