title: How does CLFLUSH work for an address that is not in cache yet?
body: <p>We are trying to use the Intel CLFLUSH instruction to flush the cache content of a process in Linux at the userspace. </p>
  
  <p>We create a very simple C program that first access a large array and then call the CLFLUSH to flush the virtual address space of the whole array. We measure the latency it takes for CLFLUSH to flush the whole array. The size of the array in the program is an input and we vary the input from 1MB to 40MB with a step of 2MB.</p>
  
  <p>In our understanding, the CLFLUSH should flush the content <em>in the cache</em>. So we expect to see the latency of flushing the whole array first increase linearly in terms of the size of the array, and then the latency should stop increasing after the array size is larger than 20MB, which is the size of the LLC of our program. </p>
  
  <p>However, the experiment result is quite surprising, as shown in the figure. The latency does not stop increasing after the array size is larger than 20MB. </p>
  
  <p>We are wondering if the CLFLUSH could potentially bring in the address before CLFLUSH flushes the address out of the cache, if the address is not in the cache yet? 
  We also tried to search in the Intel software developer manual, and didn't find any explanation of what CLFLUSH will do if an address is not in the cache. </p>
  
  <p><a href="https://i.stack.imgur.com/tlnQB.png" rel="noreferrer"><img src="https://i.stack.imgur.com/tlnQB.png" alt="enter image description here"></a></p>
  
  <p>Below is the data we used to draw the figure. The first column is the size of the array in KB, and the second column is the latency of flushing the whole array in seconds.</p>
  
  <p>Any suggestion/advice is more than appreciated. </p>
  
  <p><strong>[Modified]</strong></p>
  
  <p>The previous code is unnecessary. CLFLUSH can be done in userspace much easier, although it has the similar performance. So I deleted the messy code to avoid confusion.</p>
  
  <pre><code>SCENARIO=Read Only
  1024,.00158601000000000000
  3072,.00299244000000000000
  5120,.00464945000000000000
  7168,.00630479000000000000
  9216,.00796194000000000000
  11264,.00961576000000000000
  13312,.01126760000000000000
  15360,.01300500000000000000
  17408,.01480760000000000000
  19456,.01696180000000000000
  21504,.01968410000000000000
  23552,.02300760000000000000
  25600,.02634970000000000000
  27648,.02990350000000000000
  29696,.03403090000000000000
  31744,.03749210000000000000
  33792,.04092470000000000000
  35840,.04438390000000000000
  37888,.04780050000000000000
  39936,.05163220000000000000
  
  SCENARIO=Read and Write
  1024,.00200558000000000000
  3072,.00488687000000000000
  5120,.00775943000000000000
  7168,.01064760000000000000
  9216,.01352920000000000000
  11264,.01641430000000000000
  13312,.01929260000000000000
  15360,.02217750000000000000
  17408,.02516330000000000000
  19456,.02837180000000000000
  21504,.03183180000000000000
  23552,.03509240000000000000
  25600,.03845220000000000000
  27648,.04178440000000000000
  29696,.04519920000000000000
  31744,.04858340000000000000
  33792,.05197220000000000000
  35840,.05526950000000000000
  37888,.05865630000000000000
  39936,.06202170000000000000
  </code></pre>