
2Q buffer cache algorithm - wkornewald
http://www.tedunangst.com/flak/post/2Q-buffer-cache-algorithm
======
morgo
FWIW, MySQL's InnoDB Storage Engine switched a few years ago from an LRU to
something similar to what is described as the final solution here.

The LRU is split to a hot (5/8ths) and cold (3/8ths) chain. Scans can only
evict contents of the cold chain, and optionally you can specify a minimum
amount of time (5.6 default: 1000ms) before a page can be promoted to the hot
chain.

More details: [http://dev.mysql.com/doc/refman/5.6/en/innodb-performance-
mi...](http://dev.mysql.com/doc/refman/5.6/en/innodb-performance-
midpoint_insertion.html)

------
squeed
2Q is clever, but certainly not the only improvement over LRU for page
caching. Of interest, also, is LIRS, which uses the timing between the last
two accesses to decide on a caching strategy.

There is a good comparison of page caching algorithms here:
[http://people.cs.vt.edu/~butta/docs/sigmetrics05_kernelPrefe...](http://people.cs.vt.edu/~butta/docs/sigmetrics05_kernelPrefetch.pdf)
. However, the conclusion seems to be that for non-synthetic loads, the
difference is fairly minimal.

------
Sami_Lehtinen
How does that compare against ARC, CAR, LIRS and CLOCK-Pro?
[https://bitbucket.org/SamiLehtinen/pyclockpro](https://bitbucket.org/SamiLehtinen/pyclockpro)

~~~
dmit
When Postgres switched from ARC to 2Q in 8.0.2 due to patent concerns testing
showed that "there is little if any performance loss from doing this."

[http://www.varlena.com/GeneralBits/96.php](http://www.varlena.com/GeneralBits/96.php)

[https://github.com/postgres/postgres/commit/4e8af8d27315c4f3...](https://github.com/postgres/postgres/commit/4e8af8d27315c4f362f110c1a67e3251dd6b1872)

Edit: this ARC paper has a performance comparison of various cache algorithms:
[http://dbs.uni-leipzig.de/file/ARC.pdf](http://dbs.uni-
leipzig.de/file/ARC.pdf)

------
gioele
Going from LRU to 2Q looks like going from Mark and sweep garbage collection
to the JVM's eden, survivor, tenured, permanent spaces.

------
ihsanyounes90
Interesting, but what about priority algoritms? I think you have the same
result of 2Q buffer.

