Consider a machine with a -way set associative data cache of size Kbytes and block size bytes. The cache is managed using bit virtual addresses and the page size is Kbytes. A program to be run on this machine begins as follows:
double ARR[1024][1024];
int i, j;
/*Initialize array ARR to 0.0 */
for(i = 0; i < 1024; i++)
for(j = 0; j < 1024; j++)
ARR[i][j] = 0.0;
The size of double is bytes. Array is located in memory starting at the beginning of virtual page and stored in row major order. The cache is initially empty and no pre-fetching is done. The only data memory references made by the program are those to array .
The cache hit ratio for this initialization loop is:
View worked solution
Answer: C
To find the cache hit ratio for the initialization loop, we analyze the memory access pattern of the array elements.
1. Cache and Element Parameters
- Block size:
- Element size (double):
- Elements per block: Since each block is and each
doubleis , each cache block can hold exactly:
2. Array Alignment and Access Pattern
- The array
ARRstarts at the beginning of a virtual page (0xFF000), which is page-aligned ( boundary). Since is a multiple of the block size (), the array is perfectly aligned with the cache blocks. - The loop accesses the array sequentially in row-major order:
3. Hit/Miss Analysis
Let's trace the sequential accesses for the first few elements:
- Access
ARR[0][0]: This is a Miss. The cache block containing bothARR[0][0]andARR[0][1]is fetched into the cache. - Access
ARR[0][1]: This is a Hit, as it resides in the same block that was just loaded. - Access
ARR[0][2]: This is a Miss. The cache block containingARR[0][2]andARR[0][3]is fetched. - Access
ARR[0][3]: This is a Hit.
Since the access is strictly sequential, the second element in each block is always accessed immediately after the first. There are no intervening accesses to cause conflict or capacity evictions before the second element is read.
Thus, for every consecutive accesses, there is exactly miss and hit.
Free practice · Your answers on this page are not saved.
