As the titles suggests, is there any code or program that can have a cache miss rate of 100% or is it even possible for the cache to always never find data in the cache and the cpu has always has to access the main memory for the data, an example of such would be nice.(Asking with respect to a small research that i want to carry out) Thanks
-
1What do you mean by "more than 100%"? That is not mathematically possible. – Marco Bonelli Oct 19 '19 at 15:18
-
@MarcoBonelli well according to the formula to calculate the miss rate it is possible, when we are accessing the main memory more than the cache than a miss rate of 100% is possible. Am trying to see if this is practically possible – Weez Khan Oct 19 '19 at 15:21
-
@WeezKhan: Yes, a miss rate of 100% is possible, but not a miss rate of "more than 100%", as you stated in the title of your question. – Andreas Wenzel Oct 19 '19 at 15:29
-
@AndreasWenzel so is there any code or algorithm that can have a miss rate of 100% or close by to 100%, – Weez Khan Oct 19 '19 at 15:32
-
1Probably `return 2` every time the cache is read. – S.S. Anne Oct 19 '19 at 15:43
1 Answers
A cache miss rate of 100% is theoretically possible, but very hard to achieve. You would have to prevent the hardware prefetcher from prefetching the correct cache lines in time, for example by writing the code in such a way that the branch predictor always fails or by having long dependancy chains. Also, since most CPU caches are not fully associative, you could deliberately write code that does cache thrashing, so that only a very small part (one set) of the CPU cache is used.
Of course, you can simply disable CPU caching. On Windows, for example, you can call VirtualAlloc with the PAGE_NO_CACHE bit set in the lProtect parameter.
Also, some BIOSes allow you to disable the hardware prefetcher. But that would make your entire operating system significantly slower, not just one program.
A miss rate of greater than 100% is not possible.

- 328,167
- 45
- 605
- 847

- 22,760
- 4
- 24
- 39
-
IIRC, Linux `perf` will sometimes calculate numbers above 100% when it's actually counting something like *total* L1d misses per *load*, and some of the misses come from stores instead. Or some of the loads come from the page walker, not load instructions. But that's not a real miss rate, it's just dividing two numbers that are measuring different things. – Peter Cordes Oct 19 '19 at 17:00
-
Some more details in this [this Tweet](https://twitter.com/trav_downs/status/1183423852493197312). You can get miss rates more than 100% with those events but only because they aren't really counting in the same domain. – BeeOnRope Oct 20 '19 at 04:19