Is there a way to keep the front of an empty boost circular buffer hot in cache?

158 views Asked by At

There is a specific circular buffer I wish to keep hot in cache, however it can go unused for extended periods of time. This is causing cache misses.

I have an idle loop that can take responsibility for keeping the location hot, but I cannot see a way to do this using only the public interface without actually inserting/removing items.

Is there any action, using the public interface, that when the circular buffer is empty, will keep the insertion point hot in cache?

2

There are 2 answers

0
Maxim Egorushkin On

You may like to warm up your full fast path periodically by executing it in full and stopping as short from committing the effects of it as possible.

If you can get hold of a pointer to the front of the container you can use __builtin_prefetch on it to bring it into the cache. Alternatively, push and pop an element.

0
Zan Lynx On

You might want to look into using CAT (Cache Allocation Technology). I'm not sure where it's at, at the moment, but see https://lwn.net/Articles/694800/ for where Linux was with it July 2016.

CAT is an Intel thing to separate pieces of cache and dedicate them to different purposes. Threads assigned one piece of cache cannot evict data belonging to other pieces, although I believe they can still make use of reading it.