in CO and Architecture retagged by
537 views
1 vote
1 vote

Suppose in a system we store data using arrays, we have $2$ arrays A1 and A2.  Array A1 contains $256$ elements of size $4$ bytes each. The first element is stored at physical address $4096$. Another array A2 contains $512$ elements of size $4$ bytes each,  stored from physical address location $8192$.

Assume that only arrays A1 and A2 can be cached in an initially empty, physically addressed, physically tagged, direct mapped cache whose size is $2$ KB with $8$ byte block size. Now we run below loop in the system:

for( p=0; p<256; p++)
{
A[p] = A[p] + B[2*p]
}

If the cache use write back policy, the number of bytes that will be written to memory during execution of the loop is :

  1. $256$
  2. $1$
  3. $0$
  4. $2048$
in CO and Architecture retagged by
by
537 views

1 Answer

1 vote
1 vote
Best answer
Here Write Back policy is used , in write back the information is written only to the block in the cache. The modified cache block is written to main memory only when it is replaced.

Only Cache is updated so no bytes is written in memory during execution of the loop which gives answer 0 .
selected

4 Comments

@Bikram @Arjun What would the answer be if it was write-through cache? 256 right?

0
0

@Bikram Cache size is 2KB, hence it can not store all the array elements as they require 3KB (256*4+512*4) so there will be few misses(those can be for array A or B) while accessing the blocks and when those misses will occur that blocks will be written back to main memory (write back policy) which we cause x*8 bytes (say x misses occured) will be written back to main memory.please correct me if i am wrong.

 

0
0

Cache has 256 blocks, Array A has 128 blocks, Array B has 256 blocks. For the given loop, we are accessing every block of A and B exactly once, now as all blocks of A + B cannot be stored in the cache, exactly 128 blocks of B will need replacement, and hence there will be write-back in memory. 

The question has some error. I think if the loop statement was 

A[p] = A[p] + B[p]

then the answer would be 0.

0
0
Answer:

Related questions