1,229 views
6 votes
6 votes

Consider the following piece of code which multiplies two matrices:

int a[1024][1024], b[1024][1024], c[1024][1024];
multiply()
{
   unsigned i, j, k;
   for(i = 0; i < 1024; i++)
       for(j = 0; j < 1024; j++)
           for(k = 0; k < 1024; k++)
               c[i][j] += a[i,k] * b[k,j];
}

Assume that the binary for executing this function fits in one page, and the stack also fits in one page. Assume further that an integer requires 4 bytes for storage. Compute the number of TLB misses if the page size is 4096 and the TLB has 8 entries with a replacement policy consisting of LRU.

2 Answers

0 votes
0 votes

Solution:
1024*(2+1024*1024) = 1073743872
The binary and the stack each fit in one page, thus each takes one entry in the TLB. While the function is running, it is accessing the binary page and the stack page all the time. So the two TLB entries for these two pages would reside in the TLB all the time and the data can only take the remaining 6 TLB entries.

We assume the two entries are already in TLB when the function begins to run. Then we need only consider those data pages.

Since an integer requires 4 bytes for storage and the page size is 4096 bytes, each array requires 1024 pages. Suppose each row of an array is stored in one page. Then these pages can be represented as a[0..1023], b[0..1023], c[0..1023]: Page a[0] contains the elements a[0][0..1023], page a[1] contains the elements a[1][0..1023], etc.

For a fixed value of i, say 0, the function loops over j and k, we have the following reference string:

a[0], b[0], c[0], a[0], b[1], c[0], ¡ a[0], b[1023], c[0]
¡
a[0], b[0], c[0], a[0], b[1], c[0], ¡ a[0], b[1023], c[0]

For the reference string (1024 rows in total), a[0], c[0] will contribute two TLB misses. Since a[0] and b[0] each will be accessed every four memory references, the two pages will not be replaced by the LRU algorithm. For each page in b[0..1023], it will incur one TLB miss every time it is accessed. So the number of TLB misses for the second inner loop is
2+1024*1024 = 1048578
So the total number of TLB misses is 1024*1048578 = 1073743872

0 votes
0 votes

note that 1 page contain 1024 entries, now

for loop of there are total 1027 TLB misses (for first access of page, and 1024 misses due to pages of B )

so total TLB miss = 1024 x 1024 x1027

Related questions

942
views
0 answers
1 votes
Neal Caffery asked Jan 17, 2017
942 views
Consider a memory system consists of a single external cache with an access time of 30ns and a hit rate of 0.85, and a main memory with an access time of 80ns. Now we add virtual ... ?( Marks: 0.00 ) 8ns 30ns 40ns 51ns
3.8k
views
3 answers
1 votes
Neal Caffery asked Jan 17, 2017
3,818 views
Consider a system with 2-levels of paging and a TLB with hit rate of 95% and TLB access time of 1ns. Find the effective memory access time if there's a data cache whose hit rate ... 100ns.100ns. 27ns 25ns 30ns 20ns
2.0k
views
2 answers
0 votes
Deepanshu asked Oct 1, 2018
1,956 views
Consider a computer system using 2-level paging with TLB.The logical address supported is 32 bits.The page table is divided into 512 pages each of size 1K.The ... page of the second level page table for a process?A)6KBB)4KBC)5KBD)12KB
312
views
0 answers
0 votes
gate_forum asked Jan 13, 2019
312 views
122048none