94 /*
95 * Size of Kernel address space. This is the number of page table pages
96 * (4MB each) to use for the kernel. 256 pages == 1 Gigabyte.
97 * This **MUST** be a multiple of 4 (eg: 252, 256, 260, etc).
98 */
99 #ifndef KVA_PAGES
100 #ifdef PAE
101 #define KVA_PAGES 512
102 #else
103 #define KVA_PAGES 256
104 #endif
105 #endif
106
107 /*
108 * Pte related macros
109 */
110 #define VADDR(pdi, pti) ((vm_offset_t)(((pdi)<<PDRSHIFT)|((pti)<<PAGE_SHIFT)))
111
112 /* Initial number of kernel page tables. */
113 #ifndef NKPT
114 #ifdef PAE
115 /* 152 page tables needed to map 16G (76B "struct vm_page", 2M page tables). */
116 #define NKPT 240
117 #else
118 /* 18 page tables needed to map 4G (72B "struct vm_page", 4M page tables). */
119 #define NKPT 30
120 #endif
121 #endif
122
123 #ifndef NKPDE
124 #ifdef SMP
125 #define NKPDE (KVA_PAGES - 1) /* number of page tables/pde's */
126 #else
127 #define NKPDE (KVA_PAGES) /* number of page tables/pde's */
128 #endif
129 #endif
130
131 /*
132 * The *PTDI values control the layout of virtual memory
133 *
134 * XXX This works for now, but I am not real happy with it, I'll fix it
135 * right after I fix locore.s and the magic 28K hole
136 *
137 * SMP_PRIVPAGES: The per-cpu address space is 0xff80000 -> 0xffbfffff
138 */
139 #ifdef SMP
140 #define MPPTDI (NPDEPTD-1) /* per cpu ptd entry */
141 #define KPTDI (MPPTDI-NKPDE) /* start of kernel virtual pde's */
142 #else
143 #define KPTDI (NPDEPTD-NKPDE)/* start of kernel virtual pde's */
144 #endif /* SMP */
145 #define PTDPTDI (KPTDI-NPGPTD) /* ptd entry that points to ptd! */
KVA_PAGES是内核地址空间所占的页表页面总数,此处定义为256,因此内核地址空间的大小
为1G字节。
VADDR是根据页表目录索引和页表索引得到对应页面的起始虚拟地址,其中pdi是页表目录索引,
即地址在第22到31比特中的偏移,pti是页表索引,即地址在第12到21比特中的偏移。
NKPT是内核在vm系统工作之前所需的页表页面的数目。对于非PAE的i386而言,其中有18个
页面是用来存放指向vm_page结构体的页表的。因为4G空间共有1M个页面,因此需要1M个
vm_page结构体来组织,每个vm_page结构体的大小是72字节,一共需要72M的空间,
即18432个页面,每个页表页面上可存储1024个页表项,因此,对应于18432个页面的页表项
共需18个页面来存储。此处定义的30个页面中的剩余12个页面是对内核在此过程中的其它
内存需求所需页表空间的估计量。全局变量nkpt初始化为NKPT,之后将随着内核地址空间的
增长而递增。
NKPDE是内核所占的页表目录项的总数,对于非smp,NKPDE就是KVA_PAGES,即内核占用的页表
页面总数,对于smp,则比KVA_PAGES少1,相当于保留了4M的空间。
MPPTDI是smp环境中用于每个cpu的页表目录项的索引,它是1024个页表目录项中的最后一个,
表示的是地址空间中最顶端的4M空间(0xffc00000-0xffffffff),因此此处将其定义为1023。
KPTDI是第一个内核页表目录项的索引,对于smp环境,内核页表目录项的总数NKPDE是255,
而其顶端紧邻NPPTDI,因此KPTDI就是1023减去255,即768。
PTDPTDI是指向页表目录自身所属页表页面的页表目录项的索引,页表目录的页表页面紧邻在
