title: What does CPU do when it writes to a memory location not in the cache?
body: <p>Suppose I have a 8 byte <code>long pointer</code> to a memory location in a physical memory in my program. My program is small and can fit entirely in the cache. The program is simple. It simply maps (via mmap() call) an arbitrary memory location from physical memory in <code>/dev/mem</code>, read and write back to that location via that 8 byte long pointer. However, that location is very far away from where my program resides in physical memory and for that reason, the L1/L2 cache can't cover that address. </p>
  
  <p>According to the article Getting Physical With Memory (written by Gustavo Duarte, I can't link), a memory write only occurs when a cacheline that has that memory location is ready to be written to RAM:</p>
  
  <blockquote>
    <p>Typically kernels treat all RAM memory as write-back, which yields the
    best performance. In write-back mode the unit of memory access is the
    cache line, 64 bytes in the Core 2. If a program reads a single byte
    in memory, the processor loads the whole cache line that contains that
    byte into the L2 and L1 caches. When a program writes to memory, the
    processor only modifies the line in the cache, but does not update
    main memory. Later, when it becomes necessary to post the modified
    line to the bus, the whole cache line is written at once</p>
  </blockquote>
  
  <p>But what if targeted memory location is not in the cache (as I described above), will it be written immediately?</p>