computer-science - 计算虚拟内存页表和转换后备缓冲区

标签 computer-science virtual-memory computer-architecture

我正在回答一些与虚拟内存相关的问题,并希望得到一些帮助来澄清或确认我对这些东西是如何完成的理解。

问题如下:

Given a byte-addressable system with 32 bit words, a virtual address space of 4 gigabytes, a physical address space of 1 gigabyte, and a page size of 4 kilobytes. There is an assumption that page table entries are rounded up to 4 bytes.

a) What is the size of the page table in bytes?

b) Now assume that a 4-way set-associative translation lookaside buffer is implemented, with a total of 256 address translations. Calculate the size of its tag and index fields.



我的回答如下:

A:

The size of the page table is equal to the number of entries in the page table multiplied by the size of the entries.

The number of entries in the page table is equal to the memory size divided by the page size: 2^32/2^12=2^20.

The size of the entries is equal to the word size minus the bits used for the number of entries in the page table: 32-20=12.

Hence, the page table size is: (2^20) * 12 bits = 12582912 bits = 1572864 bytes



然而,我发现this (在“页表大小”标题下),使用基本相同的数字。

Page Table Size = ((virtual address space size)/(page size)) * (page table entry size) = (4 GB/4 KB) * 4 B = 4 MB



哪个答案是正确的?

接下来,乙:

I am unsure of how to calculate part B. I believe that the Tag is calculated by adding the number of blocks, plus the offset, plus the index. This is a 4 way set associative, so there are 4 blocks in each set. The index is 8 bits because the base index size is 10 bits and is decreased by 2, also because it is a 4 way set associative. However, I am unaware of how to calculate the offset, which is needed to help calculate the tag.



任何帮助将非常感激。

最佳答案

对于 a 部分,您犯了两个错误。首先,该问题明确指出“页表条目四舍五入为 4 个字节”。其次,PTE 包含根据页面对齐的地址确定物理地址所需的位。在所描述的系统中,物理地址只有 30 位 (1 GiB)。由于该系统使用 4KiB 页面,因此 PTE 中物理地址的最低有效 12 位将全部为零,因此可以是隐式的。所以只需要物理地址 18 位(30-12)。

除了需要四舍五入到 2 个字节的幂之外,大多数 PTE 还包括附加数据,例如有效位、修改位、访问位以及用户和管理员模式的权限位;所以即使有 512 MiB 的物理地址空间和 8 KiB 页(需要 16 位来表示物理地址),也不能使用 2 字节 PTE。

(需要注意的是,没有 32 位处理器会使用平面页表。对于 32 位地址,通常使用分层或线性页表。这些会为完全占用引入一点额外的空间开销,并且可能需要多次内存访问才能找到翻译,但在部分占用和密集分配的常见情况下,它们使用的内存要少得多。这尤其重要,因为大多数处理器是为多个地址空间操作系统设计的,其中每个进程都有自己的页表。使用几乎一半的物理内存页表中的 [400 MiB] 仅支持 100 个进程是毫无吸引力的,这是可以理解的。)

对于 b 部分,您是正确的,4 路集合关联意味着每个集合中有 4 个块,因此根据条目数从索引所需的位数中减去 2 位。然而,log2(256) 是 8 而不是 10,所以只有 6 位用于索引 TLB。

在数据缓存中,标签大小等于地址位的数量减去索引位的数量,再减去偏移位的数量(在缓存块内)。

对于 TLB,虚拟地址与页面大小对齐(页面中的最低有效位未翻译)。对于 4 KiB 页,这意味着 12 个最低有效位被忽略。使用 32 位虚拟地址,剩下 20 位。

其中 6 位用于索引已经确定,所以剩下 14 位。

对于非集群 TLB,每个标签都与一个翻译相关联。这相当于 1 个字节的数据缓存块大小(即 0 个偏移位)。因此,标签(不包括任何地址空间 ID)将为 14 位。

(在集群 TLB [类似于扇区缓存块]中,为每个“条目”提供了两个或多个翻译——条目变得不太清楚,因为它可能指代翻译条目或标签和多个翻译的组合与该标签相关联。[我怀疑您很欣赏这种复杂性,而不是这些问题的一部分。])

关于computer-science - 计算虚拟内存页表和转换后备缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19777840/

相关文章:

algorithm - O(3^n) 仍然写成 O(2^n) 吗?

c - 直接访问进程内存

memory-management - 有人可以向我解释有关分页(虚拟内存)的图表吗?

linux - 如何在内核和用户空间之间使用 mmap&proc 共享内存

c - 为什么这个简单的循环在 Go 中比在 C 中更快?

binary - 计算机如何存储小数点值?

memory-management - 架构式 TLB 与架构式页表

algorithm - 从选项列表中查找相互兼容的选项

Java - 斐波那契数列

computer-science - 分布式系统中的逻辑顺序和全序示例