简体   繁体   English

内存-分页和TLB

[英]Memory - Paging and TLB

I have question to the following task. 我对以下任务有疑问。

Consider an IA-32 system where the MMU supports a two level page table. 考虑一个MMU支持两级页表的IA-32系统。 The second level contains 1024 page table entries mapping to 4 KB page frames. 第二级包含1024个页面表条目,它们映射到4 KB页面框架。 Each page table entry (both levels) has a size of 4 bytes. 每个页表条目(两个级别)的大小均为4个字节。 The system only supports 4 KB page size. 系统仅支持4 KB页面大小。
We want to sequentially read consecutive 8 MB from virtual memory, starting with byte 0. We read one word at a time (4 bytes) 我们要从字节0开始从虚拟内存中顺序读取连续的8 MB。我们一次读取一个字(4个字节)
We have an 8 entry data TLB. 我们有一个8条目数据TLB。 How many memory accesses are needed to read the 8 MB of memory specified above? 读取上面指定的8 MB内存需要多少内存访问?

Does it make a difference, if the TLB has 4 entries instead of 8? 如果TLB有4个条目而不是8个条目,这会有什么不同?

So, we read sequentially. 因此,我们按顺序阅读。 This means 8MB/4B = 2M memory accesses. 这意味着8MB / 4B = 2M的内存访问。 We have a two level page table. 我们有一个两级页面表。 Therefore, 2M + 2*2M = 6M memory accesses without TLB. 因此,在没有TLB的情况下,2M + 2 * 2M = 6M的内存访问。

But I don't know how to calculate the memory accesses including a TLB. 但是我不知道如何计算包括TLB在内的内存访问。

Could anyone explain me that? 有人可以向我解释吗? That would be very helpful. 那会很有帮助。

Since the access pattern is a streaming access, each TLB entry will be used for one access to each four bytes for the entire page and never re-used. 由于访问模式是流式访问,因此每个TLB条目将用于整个页面每四个字节的一次访问,并且永远不会重复使用。 This means that each TLB entry will be reused 1023 times, so 1023 look-ups (2046 memory accesses) would be avoided per page. 这意味着每个TLB条目将被重用1023次,因此每页将避免1023个查找(2046个内存访问)。 (Since there is no overlap of use of different translations and only perfectly localized reuse, a single entry data TLB would have equivalent performance to even a 2048-entry TLB.) (由于不存在使用不同翻译的重叠,只有完全本地化的重用,所以单个条目数据TLB的性能甚至与2048个条目的TLB相同。)

Consider the following description of what is happening for a two-entry direct-mapped data TLB (recognizing that the least significant 12 bits of the virtual address—the offset within the page—are ignored for the TLB and one bit of the virtual address is used to index into the 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

Each page is referenced 1024 times (once for each four byte element) in sequence and then is never referenced again. 每个页面依次被引用1024次(每个四个字节元素一次),然后不再被引用。

(Now consider a design with four TLB entries and two entries caching page directory entries [each of which has the pointer to the page of page table entries]. Each cached PDE will be reused for 1023 page look-ups, reducing them to one memory access each. [If the 8 MiB streaming access was repeated as an inner loop and was 4 MiB aligned, a two-entry PDE cache would be fully warmed up after the first iteration and all subsequent page table look-ups would only require one memory reference.]) (现在考虑一种设计,其中包含四个TLB条目和两个条目来缓存页面目录条目[每个条目都具有指向页面表条目页面的指针]。每个缓存的PDE将重用于1023页查找,从而将它们减少为一个内存[如果将8个MiB流访问作为一个内部循环重复进行,并且与4个MiB对齐,则两次迭代的PDE缓存将在第一次迭代后完全预热,并且所有后续页表查找仅需要一个内存参考。])

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

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