[Paper Review] An O(1) algorithm for implementing the LFU cache eviction scheme
This paper presents an O(1) algorithm for implementing the LFU (Least Frequently Used) cache eviction scheme by using a dual linked list structure for frequency levels and a hash table for key-based access. The method maintains constant-time operations for insertion, lookup, and eviction by dynamically managing frequency nodes and element sets, achieving optimal O(1) performance across all operations.
Cache eviction algorithms are used widely in operating systems, databases and other systems that use caches to speed up execution by caching data that is used by the application. There are many policies such as MRU (Most Recently Used), MFU (Most Frequently Used), LRU (Least Recently Used) and LFU (Least Frequently Used) which each have their advantages and drawbacks and are hence used in specific scenarios. By far, the most widely used algorithm is LRU, both for its $O(1)$ speed of operation as well as its close resemblance to the kind of behaviour that is expected by most applications. The LFU algorithm also has behaviour desirable by many real world workloads. However, in many places, the LRU algorithm is is preferred over the LFU algorithm because of its lower run time complexity of $O(1)$ versus $O(\log n)$. We present here an LFU cache eviction algorithm that has a runtime complexity of $O(1)$ for all of its operations, which include insertion, access and deletion(eviction).
Motivation & Objective
- To address the performance bottleneck of traditional LFU caches, which operate in O(log n) time due to heap-based frequency tracking.
- To design a data structure that supports all LFU operations in O(1) time, matching LRU’s efficiency while preserving LFU’s frequency-based eviction semantics.
- To enable practical deployment of LFU in high-throughput systems like network proxies and databases where low-latency cache operations are critical.
- To eliminate the need for heap reorganization during frequency updates, which degrades performance in existing implementations.
Proposed method
- The algorithm uses a doubly linked list of frequency nodes, where each node represents a frequency level and contains a set of keys with that frequency.
- A hash table maps each key to its corresponding LFU item, which maintains a reference to its parent frequency node.
- When an item is accessed, it is moved from its current frequency node to the next higher frequency node, which is created on-demand if not present.
- The frequency list is maintained in sorted order, with the least frequently used items at the front, enabling O(1) access to the minimum frequency node.
- A helper function, GET-NEW-NODE, inserts a new frequency node between existing nodes only when needed, ensuring minimal overhead.
- The DELETE-NODE function removes a frequency node from the list if its associated set becomes empty, preserving list integrity.
Experimental results
Research questions
- RQ1Can the LFU cache eviction strategy be implemented with O(1) time complexity for all core operations, including insertion, access, and eviction?
- RQ2Is it possible to maintain frequency-based ordering without relying on a heap or balanced tree structure?
- RQ3How can dynamic frequency node creation and list manipulation be designed to ensure constant-time performance?
- RQ4What data structure design enables efficient movement of items between frequency levels while preserving O(1) complexity?
Key findings
- The proposed algorithm achieves O(1) time complexity for all LFU operations: insertion, lookup, and eviction.
- The use of a frequency-linked list with on-demand node creation eliminates the need for heap reorganization, which previously caused O(log n) overhead.
- The hash table ensures O(1) key-based access, and the frequency list allows O(1) access to the least frequently used item via the head of the list.
- The algorithm dynamically maintains frequency nodes only when necessary, reducing memory and computational overhead.
- The method supports efficient movement of items between frequency levels by updating pointers and maintaining list invariants in constant time.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.