arm架构在linux系统上的mmu页表

只用了arm架构下4种页表中的两种:Sections、Small pages
Section——只有1级页表,物理页帧是1M;
Small pages——有2级页表,物理页帧是4k;
以2级页表的情况为例。

linux认为第1级页表里一个表项是8字节,其实里面包含了2个硬件意义上的第1级页表表项(4字节);
linux认为的第2级页表是4k,里面每1k为单位是1个独立的页表,前2个是给linux用的,后2个是给arm硬件mmu用的;

来自 arch/arm/include/asm/pgtable-2level.h 的解释
/*
 * Hardware-wise, we have a two level page table structure, where the first
 * level has 4096 entries, and the second level has 256 entries.  Each entry
 * is one 32-bit word.  Most of the bits in the second level entry are used
 * by hardware, and there aren't any "accessed" and "dirty" bits.
 *
 * Linux on the other hand has a three level page table structure, which can
 * be wrapped to fit a two level page table structure easily - using the PGD
 * and PTE only.  However, Linux also expects one "PTE" table per page, and
 * at least a "dirty" bit.
 *
 * Therefore, we tweak the implementation slightly - we tell Linux that we
 * have 2048 entries in the first level, each of which is 8 bytes (iow, two
 * hardware pointers to the second level.)  The second level contains two
 * hardware PTE tables arranged contiguously, preceded by Linux versions
 * which contain the state information Linux needs.  We, therefore, end up
 * with 512 entries in the "PTE" level.
 *
 * This leads to the page tables having the following layout:
 *
 *    pgd             pte
 * |        |
 * +--------+
 * |        |       +------------+ +0
 * +- - - - +       | Linux pt 0 |
 * |        |       +------------+ +1024
 * +--------+ +0    | Linux pt 1 |
 * |        |-----> +------------+ +2048
 * +- - - - + +4    |  h/w pt 0  |
 * |        |-----> +------------+ +3072
 * +--------+ +8    |  h/w pt 1  |
 * |        |       +------------+ +4096
 *

你可能感兴趣的:(笔记,linux)