为什么 16 位地址和 12 位偏移量会产生 4KB 页面大小?
我正在读《现代操作系统》这本书。我对“页面大小”感到困惑。
作者在书中说道,
传入的16位虚拟地址是 分成4位页码和 12 位偏移量。 4位为 页码,我们可以有 16 页,并且 用 12 位作为偏移量,我们可以 寻址一个内的所有 4096 个字节 页。
为什么是 4096 字节?使用 12 位,我们可以在一个页面内寻址 4096 个条目,这是正确的。但是,一个条目是一个地址(在本例中,地址大小 = 16 位)。所以我认为我们可以寻址 4096(entry) * 16(bit) = 4096(entry) * 2(byte) = 8KB,但是为什么书上说我们可以寻址 4096(bytes)?
提前致谢! :)
I'm reading the "Modern Operating System" book. And I'm confused about the "Page Size".
In the book, the author says,
The incoming 16-bit virtual address is
split into a 4-bit page number and
12-bit offset. With 4 bits for the
page number, we can have 16 pages, and
with 12 bits for the offset, we can
address all 4096 bytes within a
page.
Why 4096 bytes? With 12 bits, we can address 4096 entries within a page, correct. But, one entry is an address (in this case, address size = 16 bits). So I think we can address 4096(entry) * 16(bit) = 4096(entry) * 2(byte) = 8KB, but why the book says that we can address 4096 (bytes) ?
Thanks in advance! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是假设字节寻址内存(过去 30 年制造的几乎每台机器都使用),因此每个地址引用一个字节,而不是条目或地址或任何其他更大的值。要保存 16 位值,您需要两个连续的地址(两个字节)。
30 多年前,曾经有过按字寻址的机器,其工作方式就像您猜测的那样。但此类机器在处理面向字节的数据(例如 ASCII 字符)时遇到了困难,因此已经失宠。如今,诸如字节可寻址性、8 位字节和二进制补码整数之类的东西几乎只是假设的。
This is assuming byte-addressed memory (which almost every machine made in the past 30 years uses), so each address refers to a byte, not an entry or address or any other larger value. To hold a 16-bit value, you'll need two consecutive addresses (two bytes).
More than 30 years ago, there used to be machines which were word addressed, which worked like you surmise. But such machines had a tough time dealing with byte-oriented data (such as ASCII characters), and so have fallen out of favor. Nowadays, things like byte addressability, 8-bit bytes and twos-complement integers are pretty much just assumed.
12 位是页内的偏移量。偏移量以字节为单位,而不是地址。 2^12 是 4096。
The 12 bits are an offset within a page. The offset is in bytes, not addresses. 2^12 is 4096.
因为使用 12 位,我们可以寻址
2^12=4096
个槽。每个槽代表一个字节寻址存储器中大小为 1 字节的地址。因此总大小为4096*1=4096 字节 = 4KB。
Because with 12 bit, we can address
2^12=4096
slots. Each slot represents an address which size is 1 byte in byte-addressable memory. Hence the total size is4096*1=4096 bytes = 4KB.
你计算的是页大小,即内存中页表中的一个页面的大小。由于我们使用 12 位作为偏移量,因此物理内存中的每一帧为 2^12=4096K。但是,页表中的每个页在内存中占用 2^12 个条目 x 2 个字节 = 8K。
What you are calculating is the page size, i.e. the size of a page in the page table in the memory. As we use 12 bits for the offset, each frame in the physical memory is 2^12=4096K. However, each page in the page table occupies 2^12 entries x 2 bytes = 8K in the memory.
好吧,你有 16 位虚拟地址,让我们看看它是什么意思。这意味着你有 2**16 =65536 字节。
4 位页码,表示有 16 页,即 2^4=16
现在您将页面命名为 page1、page2...page16。
现在剩下 12 位,让我们看看 12 位可以代表多少个地址 2**12=4096 字节
65536 字节也可以通过将其分为 16 个页,每个页包含 4096 个字节来实现,即 4096*16=65536
okay so you have 16 bit virtual address let see what does it mean .It means you have 2**16 =65536 bytes.
4 bit page number that means there are 16 pages as 2^4=16
Now You Name The Pages As page1,page2...page16.
Now We are left with 12bits let us see how many address can 12 bits represent 2**12=4096 bytes
65536 bytes could also be achieved by dividing it into 16 pages containing 4096 bytes each as 4096*16=65536