I want to monitor and allocate LLC space usage using Intel RDT. I wrote a program which will cause 100% cache miss as I expect. My machine's LLC size is 30.25 MB, and cache line size is 64 bytes. So I access a matrix column by column like so:
int matrix[524288][16]; //4 byte * 524288 * 16 = 32M byte
void bad_access();
int main() {
int i = 0;
cout << sizeof(int) << endl;
while (i < 5000) {
bad_access();
i++;
}
return 0;
}
void bad_access() {
int sum = 0;
for (int j = 0; j < 16; j++) {
for (int i = 0; i < 524288; i++) {
sum += matrix[i][j];
}
}
}
I assumed that the program above would use all LLC space, but when I checked it with Intel RDT, I found that it only used less than 16 MB. I wondered how that happened.