我对以下任务有疑问。
考虑一个IA-32系统,其中MMU支持两级页表。第二
level包含1024个页表条目,映射到4 KB页面帧。每个页面表
条目(两个级别)的大小为4个字节。系统仅支持4 KB页面大小。
我们想从虚拟内存中顺序读取连续的8 MB,从字节0开始。我们一次读取一个字(4个字节)
我们有一个8项数据TLB。需要多少内存访问
读取上面指定的8 MB内存?
如果TLB有4个条目而不是8个条目,它会有所不同吗?
所以,我们按顺序阅读。这意味着8MB / 4B = 2M内存访问。我们有一个两级页表。因此,2M + 2 * 2M =没有TLB的6M内存访问。
但我不知道如何计算内存访问,包括TLB。
有人可以解释一下吗?这将非常有帮助。
答案 0 :(得分:0)
由于访问模式是流访问,因此每个TLB条目将用于对整个页面的每四个字节的一次访问,并且永远不会重复使用。这意味着每个TLB条目将被重复使用1023次,因此每页将避免1023个查找(2046个内存访问)。 (由于使用不同的翻译没有重叠,只有完全本地化的重用,单个条目数据TLB与2048条目的TLB具有相同的性能。)
考虑以下对双入口直接映射数据TLB所发生情况的描述(认识到虚拟地址的最低有效12位 - 页面内的偏移 - 被TLB忽略,并且一位虚拟地址用于索引TLB):
load 0x0100_0000; // TLB entry 0 tag != 0x0800 (page # 0x0_1000) [miss]
// 2 memory accesses to fill TLB entry 0
load 0x0100_0004; // TLB entry 0 tag == 0x0800 [hit]
load 0x0100_0008; // TLB entry 0 tag == 0x0800 [hit]
... // 1020 TLB hits in TLB entry 0
load 0x0100_0ffc; // TLB entry 0 tag == 0x0800 [hit]; last word in page
load 0x0100_1000; // TLB entry 1 tag != 0x0800 (page # 0x0_1001) [miss]
// 2 memory accesses to fill TLB entry 1
load 0x0100_1004; // TLB entry 1 tag == 0x0800 [hit]
load 0x0100_1008; // TLB entry 1 tag == 0x0800 [hit]
... // 1020 TLB hits in TLB entry 1
load 0x0100_1ffc; // TLB entry 1 tag == 0x0800 [hit]; last word in page
load 0x0100_2000; // TLB entry 0 tag (0x0800) != 0x0801 (page # 0x0_1002) [miss]
// 2 memory accesses to fill TLB entry 0
load 0x0100_2004; // TLB entry 0 tag == 0x0801 [hit]
load 0x0100_2008; // TLB entry 0 tag == 0x0801 [hit]
... // 1020 TLB hits in TLB entry 0
load 0x0100_2ffc; // TLB entry 0 tag == 0x0801 [hit]; last word in page
load 0x0100_3000; // TLB entry 1 tag (0x0800) != 0x0801 (page # 0x0_1003) [miss)
// 2 memory accesses to fill TLB entry 1
load 0x0100_3004; // TLB entry 1 tag == 0x0801 [hit]
load 0x0100_3008; // TLB entry 1 tag == 0x0801 [hit]
... // 1020 TLB hits in TLB entry 1
load 0x0100_3ffc; // TLB entry 1 tag == 0x0801 [hit]; last word in page
... // repeat the above 510 times
// then the last 4 pages of the 8 MiB stream
load 0x017f_c000; // TLB entry 0 tag (0x0bfd) != 0x0bfe (page # 0x0_17fc) [miss]
// 2 memory accesses to fill TLB entry 0
load 0x017f_c004; // TLB entry 0 tag == 0x0bfe [hit]
load 0x017f_c008; // TLB entry 0 tag == 0x0bfe [hit]
... // 1020 TLB hits in TLB entry 0
load 0x017f_cffc; // TLB entry 0 tag == 0x0bfe [hit]; last word in page
load 0x017f_d000; // TLB entry 1 tag (0x0bfd) != 0x0bfe (page # 0x0_17fd) [miss]
// 2 memory accesses to fill TLB entry 1
load 0x017f_d004; // TLB entry 1 tag == 0x0bfe [hit]
load 0x017f_d008; // TLB entry 1 tag == 0x0bfe [hit]
... // 1020 TLB hits in TLB entry 1
load 0x017f_dffc; // TLB entry 1 tag == 0x0bfe [hit]; last word in page
load 0x017f_e000; // TLB entry 0 tag (0x0bfe) != 0x0bff (page # 0x0_17fe) [miss]
// 2 memory accesses to fill TLB entry 0
load 0x017f_e004; // TLB entry 0 tag == 0x0bff [hit]
load 0x017f_e008; // TLB entry 0 tag == 0x0bff [hit]
... // 1020 TLB hits in TLB entry 0
load 0x017f_effc; // TLB entry 0 tag == 0x0bff [hit]; last word in page
load 0x017f_f000; // TLB entry 1 tag (0x0bfe) != 0x0bff (page # 0x0_17ff) [miss]
// 2 memory accesses to fill TLB entry 1
load 0x017f_f004; // TLB entry 1 tag == 0x0bff [hit]
load 0x017f_f008; // TLB entry 1 tag == 0x0bff [hit]
... // 1020 TLB hits in TLB entry 1
load 0x017f_fffc; // TLB entry 1 tag == 0x0bff [hit]; last word in page
每个页面按顺序引用1024次(每个四字节元素一次),然后再也不会引用。
(现在考虑一个带有四个TLB条目和两个条目缓存页面目录条目的设计[每个条目都有指向页面表条目页面的指针]。每个缓存的PDE将重复用于1023页面查找,减少它们每个内存访问一次。[如果8 MiB流媒体访问作为内部循环重复并且是4 MiB对齐,则在第一次迭代后,双条目PDE缓存将完全预热,并且所有后续页面表格查找仅为需要一个内存引用。])