operating-system - 如何计算页表的页大小和条目?

标签 operating-system page-size

这句话对于操作系统意味着什么?

With a 2^32 address space and 4K ( 2^12 ) page sizes, this leave 2^20 entries in the page table. At 4 bytes per entry, this amounts to a 4 MB page table, which is too large to reasonably keep in contiguous memory. ( And to swap in and out of memory with each process switch. ) Note that with 4K pages, this would take 1024 pages just to hold the page table!

最后请解释一下他们是如何计算 1024 页的?在这方面,每个条目 4 个字节是多少? 4K页面大小是什么意思? 4K 是否意味着 4*1024 字节?他们是在考虑 4 个字节(每个字)还是 4 个字节意味着它有 4*1024 个字,每个字有一定的大小,比如 4 个字节?

最佳答案

Please explain to me how they are calculating 1024 pages at the end?

请记住,我们正在处理 2 的幂,所以

4 MB = 4,194,304 字节

4 KB = 4096 字节

4 MB/4 KB = 4,194,304 字节/4096 字节 = 1024 字节

What is 4 Bytes per entry in this regard?

您需要 32 位来引用所有 2^32 地址空间。每个字节 8 位,32 位 = 4 字节。

例如第一个地址是 0,最后一个地址是 4294967295 或 (2^32 - 1)。

Entry |   Page Memory Location
------------------------------------------
    1 |          0
    2 |       4096
    3 |       8192
  ... |        ...
 2^20 | 4294963200 ->  (2^32 - 1) - 4096

表中的每个条目都指向内存中某处的 1 页。在这个例子中,假设它从零开始。将有 2^20 个条目,它们将覆盖整个内存地址范围 (2^32)。由于每个条目是 4096 字节,因此您只需要 2^20 个条目即可覆盖所有页面。

4K means 4*1024 bytes?

是的,它指的是每页是4096字节(4*1024)。

Are they considering 4 bytes (per word), OR 4 bytes means it has 4*1024 words which each word having some size say 4 bytes?

在 32 位处理器上它可以更小,但通常一个字是 32 位或 4 字节。

添加评论

When I say a page size is 4K, then it means it has 1024 entries with 4 bytes each or 1024*4 entries with 1 byte each or what else?

页面可以包含任何内容,它是一个数据容器,在本例中为 4096 字节。 页表包含指向页面条目。正如大卫所说,由于页表存储在内存中,所以它也存储在页面中。

Someone was saying that explanation is wrong. Correct one is: With a 2^32 address space and 4K (2^12) page sizes, this leave 2^20 pages in the table. At 4 bytes per entry, this amounts to a 4 GB page table, which is too large to reasonably keep in contiguous memory. (And to swap in and out of memory with each process switch.) Note that with 4K page sizes, this would take 1024 k pages (=1M pages) just to hold the total table! Is he correct or wrong?

他错了。如果页表实际上包含来自每一页的数据,那么他是正确的。对于 4096 字节的页面和 2^20 个条目,这将等于 4,294,967,296 字节(4 GB),但条目的大小只有 4 个字节。因此,您将其与 2^20 个条目相乘以获得 4,194,304 字节 (4 MB)。

关于operating-system - 如何计算页表的页大小和条目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27709544/

相关文章:

multithreading - 为什么进程调度不叫线程调度?

java - java中如何设置打印页面的大小?

python - 如何使用Python获取PDF文件元数据 'Page Size'?

linux - 根据Process ID可以知道最近有没有访问过CPU的cache内存?

用于获取网页大小(以字节为单位)的 Ruby 代码

javascript - 如何以编程方式获取网页大小?

c - 为什么我的程序在 Ubuntu 上显示 Segmentation Fault 但在 Geeks IDE 上运行正常?

c++ - 为什么要在运行时加载模块?

operating-system - 用 Rust 制作一个可启动的 hello world 程序