7

As I understand, _mm_clflush() / _mm_clflushopt() invalidates a cache line while saving it to memory if it has been changed. Is there a way to simply abandon a cache line, without saving to memory any changes made to it?

A use case is before freeing memory: I don't need cache lines or their values anymore.

Serge Rogatch
  • 13,865
  • 7
  • 86
  • 158
  • 3
    On a multiprocessor system with snooping there is no way to tell if some other processor already has the changed data, so that would make memory inconsistent with the cache state of the other processor. – stark Aug 31 '17 at 18:23
  • There is no intrinsic for INVD, which is only usable from ring 0. – ephemient Aug 31 '17 at 18:57
  • @stark, by the moment I want to abandon the cache line, it is known that no other processor needs any data from it. Still, a solution evicting the cache line from non-shared cache (L1 or L1+L2) is also welcome. – Serge Rogatch Aug 31 '17 at 19:15
  • AFAIK, x86 provides no way to do this even if you were running in kernel mode. `INVD` invalidates the *entire* cache (without write-back), so it's obviously not useable in normal circumstances for performance reasons. Maybe with AVX512, some CPUs will optimize the case where a single vector store overwrites an entire cache-line. Probably the best you can do in real life is `prefetchw` if you're going to write it soon, otherwise just don't do anything and let the normal cache LRU eviction take care of it. – Peter Cordes Sep 01 '17 at 07:06

0 Answers0