
The LRU-K Replacement Algorithm
DBA manages the size of the buffer. With time, the buffer fills with cached database pages. To make room for more pages, earlier pages must be removed from the cache. DBA provides a mechanism to determine which pages stay in the cache. Traditionally, database systems use the least recently used (LRU) algorithm, first described by Denning in 1968 (P. J. Denning, Resource Allocation In Multiprocess Computer Systems, Massachusetts Institute of Technology, Cambridge, MA, 1968). When buffer space is needed, LRU drops from the memory buffer the page that has not been accessed for the longest time.
However, the LRU algorithm has a flaw. It decides what page to drop from memory based only on the time of last reference. Specifically, LRU is unable to differentiate between pages that have relatively frequent references and pages that have very infrequent references. For example, a page may have been accessed 100 times, followed by another page, accessed only a single time. According to LRU, the page accessed 100 times would be dropped, regardless of the fact that this page is more popular than the other page that was only accessed once.
To optimize database disk buffering, the LRU-K algorithm was introduced in 1993 (Elizabeth J. O'Neil, Patrick E. O'Neil, Gerhard Weikum, The LRU-K Page Replacement Algorithm For Database Disk Buffering. SIGMOD Conference 1993). This algorithm surpasses conventional buffering algorithms by discriminating between frequently and infrequently referenced pages. Exchange Server 2003 uses the LRU-K algorithm.
The LRU-K algorithm keeps track of the times of the last K references to memory pages (ESE sets the default value of K to 2) and uses this statistical information to rank-order the pages according to their expected future behavior. Based on this statistical information, ESE can decide which memory-resident page to drop in order to make room for a newly accessed page that must be read into memory. Because statistical information about referenced pages is constantly collected, the LRU-K algorithm adapts in real time to changing patterns of access. This algorithm is fairly simple and incurs little bookkeeping overhead. It uses the last two or more references, generally the last K references, (where K is greater than or equal to 2) for each page to decide which page should be dropped.