DescriptionIn poking around ImageCache internals, I noticed what I think is a bug: although find_tile_main_cache marks the tiles it retrieves as 'used', the main outer routine find_tile -- which wraps find_tile_main_cache but only calls it if the tile we're seeking is not in the per-thread 2-tile microcache -- does not! That means that potentially the MOST frequently accessed files -- accessed so frequently that they perpetually stay in the microcache -- may fall out of the main cache because they don't look used.
Consider this 2-thread access pattern (assume a tiny main cache):
thread 0 thread 1
A B
A C (note: A not marked used)
A D (A not marked used)
A E (A has fallen out of the main cache, though still in 0's microcache)
B F
C C (now A is out of 0's microcache, and thus freed)
A <- main cache miss! Despite being the most commonly used file!
And it can even be a problem for single thread, consider the following access pattern: A, B, A, C, A, D, A, F, G, A <- main cache miss, despite A being the most commonly used tile.
I don't know if this actually results in worse performance for typical scenes (we certainly see a great cache hit rate for production scenes). Today I'll try a couple benchmarks and see how it changes the stats. But either way, I still think it's a bug and can't be a good thing. Do you guys agree?
The solution is to move the used() call out of find_tile_main_cache and into find_tile (the only other place that ever calls find_tile_main_cache already explicitly calls used() immediately thereafter. I believe this marks every retrieved tile as used, regardless of whether it was retrieved from the main or micro cache.
Patch Set 1 #Patch Set 2 : Update after catching a minor bug in my original diff #Patch Set 3 : Update: simplify, I prefer this formulation of the patch #Patch Set 4 : Typo fix (used -> use!) and make m_used atomic #MessagesTotal messages: 8
|