如何使用倒置页表节省空间? [英] How do I save space with inverted page tables?

查看:296
本文介绍了如何使用倒置页表节省空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果使用倒排页表将虚拟地址映射到物理地址,为什么我们要节省内存?例如,如果我们有两个都有4个页面的进程,那么在两个不同的表中将有8个条目,它们指向从虚拟地址到物理地址:

Why do we save memory if we use inverted page tables to map virtual addresses to physical ones? If we have for example two processes which both have 4 pages we would have 8 entries in two different tables pointing from virtual to physical address:

Process 1:
[0] = 1
[1] = 5
[2] = 63
[3] = 0

Process 2:
[20] = 14
[21] = 55
[22] = 11
[25] = 9

如果我们要使用倒排页表,我们将只有一个大表以另一种方式指向它.但它们的大小相等.

If we would use inverted page tables we would only have one big table pointing it the other way around. But in size they equal.

2) Inverted page table

[0] = <p1 | 3>
[1] = <p1 | 0>
[5] = <p1 | 1>
[9] = <p2 | 25>
[11]= <p2 | 22>
[14]= <p2 | 20>
[55]= <p2 | 21>
[63]= <p1 | 2>

推荐答案

第一种情况下的页表是每个进程的数据结构.每个进程都有一个指向自己的页表的指针,这调度进程时,指针会被加载到%CR3寄存器中,并且在与其他寄存器进行上下文切换时也会被保存.

The page table in the first case is a per process data structure.Every process has a pointer to its own page table ,this pointer gets loaded in the %CR3 register when the process is scheduled.Also it is saved when is it context switched along with other registers.

但是反向哈希表是全局数据结构.使用此技术的操作系统将使用某种锁定机制在给定的时间点仅访问1个进程.(想象2个进程同时访问全局数据的2个核上).

But an inverted hash table is a global data structure.The OS which uses this technique will use some locking mechanism to give access to only 1 process at a given point of time.(imagine 2 process on 2 cores accessing a global data simultaneously).

假设每个进程的内存为4GB,页面大小为4096,在第一种情况下,每个进程的大小为4GB/4096(页面表中的条目数*每个页面表项的大小),所有这些都会占用空间,创建/派生的每个进程.用于将虚拟映射到物理的总内存是所有进程的页表大小的总和.这是一种更简单的方法,因为在每个上下文切换中,您只需更改一个指针,没有什么复杂的事情.

Assuming 4GB of per process ram and 4096 page size, In the first case each process has 4GB/4096 , (no of entries in its page table * size of each page table entry) and all this will eat up space, for every process that is created/forked.The total memory used for mapping virtual to physical is sum total of page table size of all process.This is simpler approach since on every context switch you will only change a pointer ,nothing complex.

在第二种情况下,您将有一个只有4GB/4096条目的表,因此可以节省空间,但是内存管理变得复杂,因为这是全局数据,所以您必须在每个条目中添加更多信息,以说明当前所有者(如您所示)等MMU/OS必须注意同步.

In the second case you will have a single table with only 4GB/4096 entries,so space is saved,but the memory management becomes complicated, since this a global data , you will have to add more information in each entry telling how the current owner is (as you have shown)etc.The MMU/OS has to take care synchronization.

但是您提供的示例并不准确,在具有每个进程页面表的真实系统上,可以访问整个地址,在这种情况下,进程p1具有4个页面,而p2具有不同的页面集.实际上,这两个进程都可以访问映射到不同物理框架的相同虚拟地址,因此您的每个表必须每个都有8个条目.

But the example you have given is not accurate , on a real system with per process page table the entire address can accessed, in your case process p1 has 4 pages and p2 has different set of pages. In reality both process can access same virtual address , mapped to different physical frame.So each table in your must have had 8 entries each.

这篇关于如何使用倒置页表节省空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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