Limited Associativity Makes Concurrent Software Caches a Breeze

Dolev Adas, Gil Einziger, Roy Friedman

TL;DR

Traditional software caches default to fully associative designs, which suffer from severe synchronization bottlenecks in multi-threaded environments. This paper demonstrates that borrowing a page from hardware design—using limited associativity ($k$-way set associative caches)—makes concurrent software caches embarrassingly parallel. This architectural shift boosts throughput by up to 5x compared to production-grade libraries with almost no impact on the cache hit ratio.

What Problem Does This Paper Address?

Software caches (such as those embedded in Redis, Cassandra, or Caffeine) are critical for accelerating data retrieval in modern databases and storage systems. Traditionally, these caches are designed to be fully associative, meaning any cached item can be evicted to make room for any new incoming item. To implement smart eviction policies like Least Recently Used (LRU), these caches rely on global data structures (e.g., a concurrent hash table combined with a doubly linked list).

However, when multiple threads access the cache simultaneously, these global structures become massive contention hot-spots. For instance, every thread executing a cache hit under an LRU policy must fight to update the head of the same global list. While state-of-the-art libraries use relaxed lock designs or batching to mitigate this, synchronization remains a fundamental bottleneck for scaling throughput on modern multi-core processors.

Methods

The authors propose shifting software cache design to a limited associativity architecture, directly mimicking how CPU hardware caches operate. Instead of one massive pool, the cache is partitioned into $n$ independent sets, where each set contains exactly $k$ slots ("ways") to store data items.

An example of a 48-item cache organized in a 6-way set associative design.

When an item arrives, a hash function maps its ID to a specific set. If that set is full, the eviction policy only evaluates the $k$ items within that specific set to choose a victim, ignoring the rest of the cache.

The authors implemented three concurrent variants of this $k$-way architecture in Java:

  1. KW-WFA (Wait-Free Array): Each set is an array of atomic node references. It uses Compare-And-Swap (CAS) operations to replace victim nodes atomically without locking.
  2. KW-WFSC (Wait-Free Separate Counters): To maximize hardware cache locality, this variant separates metadata (counters and fingerprints) from the actual data nodes into continuous memory arrays. This allows the CPU to scan a set's metadata rapidly without traversing pointer-heavy node structures.
  3. KW-LS (Lock Set): A simpler approach that assigns a single read/write lock (StampedLock) to each set, drastically reducing lock contention compared to a single global lock.

Additionally, the paper provides a formal mathematical analysis using Chernoff bounds to prove that a $k$-way set associative cache can effectively mimic a smaller fully associative cache with very high probability.

Datasets

The approach was rigorously evaluated against a diverse suite of real-world production workloads:

  • Wikipedia Traces: wiki1190322952 and wiki1191277217 (representing 10% of Wikipedia's web traffic over three months).
  • File System Traces: sprite (Sprite network file system requests) and OLTP (an OLTP server file system trace).
  • Database & Search Traces: multi1, multi2, multi3 (relational database queries and compilation workloads from UC Berkeley), as well as search engine traces (DS1, S1, S3, W2, W3).
  • Storage Accesses: P8, P12, P14 (Windows server disk access traces).

Key Insights and Ideas

  • Embarrassingly Parallel Caching: Because each set is completely self-contained, threads operating on different sets require absolutely no synchronization. This naturally distributes the workload across cores and eliminates global hot-spots.
  • The Power of Small $k$: A crucial "aha!" discovery is that $k$ does not need to be large. An associativity value as small as $k=8$ or $k=16$ provides a hit ratio nearly identical to a fully associative cache, while keeping set scans incredibly fast ($O(k)$ constant time).
  • Denser Data Representation: Fully associative open-addressed hash tables must maintain a constant fraction of empty slots to prevent performance degradation. Limited associativity caches can safely utilize 100% of their allocated array cells, maximizing data density.
  • Hardware-Friendly Software: By grouping set metadata continuously in memory (the KW-WFSC approach), software caches exploit CPU cache lines efficiently, speeding up the software by aligning with the underlying hardware architecture.

Key Results

  • Up to 5x Throughput Boost: In multi-threaded benchmarks, the $k$-way implementations achieved up to a 5x throughput improvement over production-grade libraries like Guava and Caffeine, particularly in write-heavy or high-miss scenarios where traditional libraries struggle with write-buffer bottlenecks.
  • Linear Scalability: The proposed architecture scales linearly with thread count, avoiding the performance plateaus typical of traditional architectures.
  • Marginal Hit-Ratio Impact: Across almost all real-world traces, the difference in hit ratio between the $k$-way associative scheme and a fully associative scheme was negligible (often under 1%).

Limitations and Future Work

  • High Hit-Ratio Overhead: When a workload exhibits an extremely high hit ratio (e.g., >95%), production libraries like Caffeine can still be faster on reads. Caffeine performs a direct hash table lookup, whereas a $k$-way cache must scan the set (averaging $k/2$ comparisons) even during a hit.
  • Dynamic Associativity: In hardware architecture, advanced designs dynamically vary associativity on a per-set basis to adapt to shifting program demands. The authors point out that exploring software-defined dynamic associativity is a promising avenue for future research to close the remaining minor hit-ratio gaps.

Summary updated

BibTeX
@inproceedings{adas2022limited,
  author = {Dolev Adas and Gil Einziger and Roy Friedman},
  title = {{Limited Associativity Makes Concurrent Software Caches a Breeze}},
  booktitle = {ICDCN},
  year = {2022},
  doi = {10.1145/3491003.3491013},
}
Figure