Allocate static memory to the processor cache in c / C ++: is this possible?

Is it possible to explicitly create static objects in the CPU cache to make sure that these objects always remain in the cache, so it will not be possible to achieve the maximum return on a full load in RAM or god forbid-hdd virtual memory?

I am particularly interested in targeting the large general L3 cache code, not intended for targeting L1, L2, instructions or any other cache, only the largest memory cube in memory.

And just to clarify the differences from the other threads that I was looking for before publishing this, I am not interested in privatizing the entire cache, just a small number of classes.

+6
source share
2 answers

Not. The cache is not addressed, so you cannot select objects in it.

It seems that you wanted to ask: by allocating space in virtual memory, can I guarantee that I always get caching?

This is a more complex question, and the answer is partially.

You can definitely avoid sending to disk using your OS’s memory management API (e.g. mlock() ) to mark the region as not printable. Or select from the "misunderstood pool" to start.

I do not believe that a similar API for connecting memory to the processor cache. Even if you can reserve a processor cache for this block, you cannot avoid cache misses. If another kernel is written to the memory, ownership will be transferred, and you will have a missed cache and the associated bus transfer (possibly to main memory, possibly to the cache of another kernel).

As Matthew mentions in his comment, you can also force skipping the cache in parallel with other useful work in the pipeline so that the data is in the cache when you need it.

+12
source

You can start another thread that iterates over the data and transfers it to the L3 cache.

+1
source

Source: https://habr.com/ru/post/905929/


All Articles