Although I have read about movntdqa instructions regarding this but have figured out a clean way to express a memory range uncacheable or read data so as to not pollute the cache.
I want to do this from gcc. My main goal is to swap to random locations in an large array. Hoping to accelerate this operation by avoiding caching since there is very little data resue.
Although I have read about movntdqa instructions regarding this but have figured out a
Share
I think what you’re describing is Memory Type Range Registers. You can control these under Linux (if available and you’re user 0) using
/proc/mttr/ioctl(2)see here for an example. As it works on a physical address range I think you’re going to have a hard time using it in a reasonable way.A better way is to look at the compiler intrinsics GCC provides and find one or more, that expresses your intent. Have a look at Ulrich Drepper’s series on “What every programmer should know about memory”, in particular part 5 which deals with bypassing the cache. It looks like
_mm_prefetch(ptr, _MM_HINT_NTA)might be appropriate for your needs.As always when it comes to performance – measure, measure, measure. Drepper’s series has excellent parts detailing how this can be done (part 7) as well as code examples and other strategies to try when speeding up the memory performance of your code.