93 points · by 1a1a11a · 3y ago · 49 comments
Start with a dumb-cache using "FIFO" (first in/first out)
Keep track of anything with "hits" while in the cache (simple boolean/bitmap instead of complicated locks/data structures)
Re-insert "hit" items when they would normally be evicted/age out (Lazy Promotion).
BTW, also have a mini-cache in front of the main cache (10% of cache size) which tries to "drop off quickly" (effectively: must have a "hit" within first 10% of being cached).
BTW, also keep track of a "ghost cache" ("hits only", not contents??) for the duration of the overall FIFO-cache, and use that to guide eviction/re-insertion. I'm a little bit unclear on this aspect, but it seems like an "obvious in retrospect" set of guidance.
Probationary 10% + Traditional 90% (of memory).
The idea is that most items are not requested again prior to dropping out of probationary and so don't take up space and process in the Traditional Cache.
Some infrequently used items however would remain inside the Traditional cache but never make it through the probationary cache. So a small "ghost" cache is used to specifically detect these items rejected from the Probationary cache.
Next time we go to fetch a ghost item they go directly into the Traditional cache. The ghost cache is just storing metadata (pointers essentially).
There is an "active" queue and an "inactive" queue. The pageout daemon tries to maintain them in a 1:2 ratio. Active drains to inactive; inactive drains to be paged out. Both are simple FIFO, but the daemon clears the page table referenced bit of pages as they are enqueued onto inactive.
When dequeueing a page from inactive, the referenced bit is checked. If it's been set (i.e., the page was referenced since being moved to inactive), the page is diverted back up to active. Otherwise, it's paged out.
https://developer.apple.com/library/archive/documentation/Pe...
1. You've got a cache miss 2. You need to evict something, so look at the next item due for eviction. 3. It's a candidate for promotion, so you reinsert it. 4. You still need to evict something, so goto 2.
Isn't that a potential infinite loop? And even if not (because there's some other exit clause), how is it quick?
The second is quick demotion which uses a small FIFO to filter out most objects that are not requested soon after insertion in the cache.
https://github.com/ben-manes/caffeine/wiki/Efficiency Shows that it really outperforms ARC as well and they also have an optimal oracle version that they evaluate against to show how much room there is left (admittedly the oracle version itself implies you’re picking some global criterion to optimize but that’s trickier when in reality there are multiple axes along which to optimize and you can’t simultaneously do well across all of them).
Also the lack of evaluation of the cache strategy against shifting workloads is also problematic.
They refer to the W-TinyLFU paper as reference 34.
> Moreover, admission algorithms, e.g., TinyLFU [ 33, 34], Bloom Filter [18, 54 ], probabilistic [ 15] and ML-based [ 35] admission algorithms, can be viewed as a form of QD — albeit some of them are too aggressive at demotion (rejecting objects from entering the cache).
I know the ARC paper discusses that other algorithms are often better if properly tuned, although ARC is usually consistently decent in a variety of situations without tuning. It would be awesome to have a new algorithm in that space.
My experience trying out cache algorithms is that they are all very generic, cache benchmarks are typically based on random distributions or on web-request datasets (twitter, CDNs, ...) that may not match your use case. Mine is about caching data stream transformations with specific ORDER BYs. Hits may come at a very wide point in time and LFU ended-up working better for me. Also your eviction policy choice is very important like number of items or RAM use (my case). So don't go running to the latest "benchmark proven" cache algorithm paper without weighting in your specific needs.