繁体   English   中英

内存-分页和TLB

[英]Memory - Paging and TLB

我对以下任务有疑问。

考虑一个MMU支持两级页表的IA-32系统。 第二级包含1024个页面表条目,它们映射到4 KB页面框架。 每个页表条目(两个级别)的大小均为4个字节。 系统仅支持4 KB页面大小。
我们要从字节0开始从虚拟内存中顺序读取连续的8 MB。我们一次读取一个字(4个字节)
我们有一个8条目数据TLB。 读取上面指定的8 MB内存需要多少内存访问?

如果TLB有4个条目而不是8个条目,这会有什么不同?

因此,我们按顺序阅读。 这意味着8MB / 4B = 2M的内存访问。 我们有一个两级页面表。 因此,在没有TLB的情况下,2M + 2 * 2M = 6M的内存访问。

但是我不知道如何计算包括TLB在内的内存访问。

有人可以向我解释吗? 那会很有帮助。

由于访问模式是流式访问,因此每个TLB条目将用于整个页面每四个字节的一次访问,并且永远不会重复使用。 这意味着每个TLB条目将被重用1023次,因此每页将避免1023个查找(2046个内存访问)。 (由于不存在使用不同翻译的重叠,只有完全本地化的重用,所以单个条目数据TLB的性能甚至与2048个条目的TLB相同。)

考虑以下关于两次直接映射数据TLB发生的情况的说明(认识到对于TLB,虚拟地址的最低有效12位(页面内的偏移)被忽略了,而虚拟地址的一位为用于索引到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缓存将在第一次迭代后完全预热,并且所有后续页表查找仅需要一个内存参考。])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM