为什么要使用分层页表? [英] Why using hierarchical page tables?

查看:503
本文介绍了为什么要使用分层页表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Linux内核,并阅读《 Linux内核》 这本书.

I'm learning the Linux kernel and reading the book The Linux Kernel.

有人可以解释为什么我们不能只使用直接在逻辑和物理内存之间映射的表而不是树状的多级结构吗?

Can anybody explain why can't we just use the table which maps directly between logical and physical memory instead of the tree-like multilevel structure?

已添加:

所需的条目总数是固定的,因此我认为存储一个复杂的结构要比简单的结构浪费更多的空间.

The total number of entries needed is fixed, so I assume that it's more space wasting to store a complicated structure than a simple one.

推荐答案

当我们进入64位地址空间时,您将欣赏多级页表的空间优化.

You will appreciate the space optimization of multi-level page tables when we go into the 64-bit address space.

假设您有一台64位计算机(这意味着 64位虚拟地址空间),其中有 4KB页 4GB 物理内存.如果我们建议您使用单个级别的页表,则每个进程的每个虚拟页应包含一个条目.

Assume you have a 64-bit computer ( which means 64 bit virtual address space ), which has 4KB pages and 4 GB of physical memory. If we have a single level page table as you suggest, then it should contain one entry per virtual page per process.

每个虚拟页面一个条目– 2 64 可寻址字节/2 12 每页字节= 2 52 页表条目

One entry per virtual page – 264 addressable bytes / 212 bytes per page = 252 page table entries

一个页表项包含:访问控制位(类似于当前页,RW等位)+物理页号

One page table entry contains: Access control bits ( Bits like Page present, RW etc ) + Physical page number

4 GB的物理内存= 2 32 字节.

4 GB of Physical Memory = 232 bytes.

2 32 字节的内存/2 12 字节=每页 2 20 个物理页

232 bytes of memory/212 bytes per page = 220 physical pages

物理页码需要20位.

因此,每个页表条目大约为 4个字节. (20位物理页数约为3个字节,访问控制贡献1个字节)

So each page table entry is approx 4 bytes. ( 20 bits physical page number is approx 3 bytes and access control contributes 1 byte )

现在,页表大小= 2 52 页表项* 4字节= 2 54 字节( 16 PB strong>)!

Now, Page table Size = 252 page table entries * 4 bytes = 254 bytes ( 16 petabytes ) !

每个进程16 PB 是非常大的内存.

现在,如果我们也分页页面表,即,如果我们使用多级页面表,我们可以神奇地将所需的内存减少到低至单个页面.即仅4 KB .

Now, if we page the pagetable too, ie if we use multi level page tables we can magically bring down the memory required to as low a single page. ie just 4 KB.

现在,我们将计算将页面表压缩为4 KB所需的级别. 4 KB页面/每页4个字节的表条目= 1024个条目. 需要10位地址空间.,即 52/10 最高为6.即, 6个级别的页表可以将页表大小减小到4KB.

Now, we shall calculate how many levels are required to squeeze the page table into just 4 KB. 4 KB page / 4 bytes per page table entry = 1024 entries. 10 bits of address space required. i.e 52/10 ceiled is 6. ie 6 levels of page table can bring down the page table size to just 4KB.

6级访问绝对较慢.但是我想说明多级页表节省的空间.

6 level accesses are definitely slower. But I wanted to illustrate the space savings out of multi level page tables.

这篇关于为什么要使用分层页表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆