Locality

peyman afshani, John Iacono, Varunkumar Jayapaul, Ben Karsin

Abstract: This paper establishes a theoretical foundation for the performance of cache-oblivious algorithms across diverse hardware architectures. By introducing the Locality of Reference (LoR) model, the authors prove that algorithms optimized for hierarchical cache models are asymptotically optimal for any system that rewards spatial or temporal locality, including virtual memory and physical storage.

The Challenge of Modeling Modern Hardware

Modeling the performance of modern computers is a significant challenge. Between multiple levels of L1/L2/L3 caches, Translation Lookaside Buffers (TLBs) for virtual memory, prefetching logic, and the varying speeds of RAM, SSDs, and HDDs, the "cost" of a memory access is highly volatile. Historically, theorists used the Disk Access Model (DAM), which assumes a simple two-level hierarchy. Later, Cache-Oblivious (CO) algorithms were developed to be efficient across all levels of a hierarchy simultaneously, without knowing specific parameters like cache size ($M$) or block size ($B$).

The memory hierarchy and the corresponding increase in access time across the address space.

However, even the CO framework is built on a specific mental model where data is moved in discrete "blocks." Real hardware often rewards locality in more complex, continuous ways. This paper addresses whether an algorithm can be proven optimal on all systems that reward locality, regardless of how that locality manifests.

The Locality of Reference (LoR) Model

The authors introduce a holistic framework called the Locality of Reference (LoR) model to bridge the gap between discrete cache models and continuous hardware reality. This model relies on several key components:

  1. Locality Functions: Instead of counting "cache misses," they define a function $\ell(d)$ representing the cost of accessing a memory address based on its distance $d$ from the previous access.
  2. Bidimensional Locality: This extends to a function $\ell(d, \delta)$, where $d$ is spatial distance and $\delta$ is temporal distance (how long ago the data was last accessed), capturing the "working set" concept.
  3. B-smoothed Analysis: To connect discrete blocks to continuous distance, the authors use a technique that averages costs over all possible memory alignments.

Key Theoretical Insights

The core of the paper consists of mathematical proofs showing that if an algorithm is optimal in the "ideal-cache model," it is also optimal in the LoR model for any "reasonable" (non-negative, non-decreasing, and concave) locality function.

  • The Concavity Connection: The most significant insight is that any concave locality function can be mathematically represented as a weighted sum of "step functions." Since these step functions behave like cache misses at different block sizes, a CO algorithm—which is optimal for all block sizes—is naturally optimal for the entire sum.
  • Beyond Caches: CO algorithms optimize for factors they weren't explicitly designed for, such as the cost of address translation in virtual memory.
  • The "Tall Cache" Link: The authors find a deep connection between the standard "tall cache assumption" ($M \ge B^2$) in CO theory and the requirement that locality functions should not be more sensitive to time than they are to space.

Results and Implications

The paper proves the Universality of CO Algorithms, establishing that they are "LoR-optimal." This means they are asymptotically the best possible algorithms for any device that rewards spatial or temporal locality.

Furthermore, the authors demonstrate that the van Emde Boas (vEB) tree layout—a staple of cache-oblivious data structures—is optimal for virtual memory translation costs. They also establish a formal equivalence between being optimal in the Least Recently Used (LRU) cache model and being optimal in their general LoR model.

Limitations and Future Work

The authors acknowledge that their proof does not apply to "non-B-stable" problems—cases where the worst-case scenario fluctuates wildly with changes in block size—though these are rare in practice. Additionally, the results rely on the locality function being concave. While this matches the "diminishing returns" seen in most hardware, it may not capture every exotic architecture.

Ultimately, this research allows developers to use the CO model with greater confidence, knowing that algorithms designed within it will perform well on diverse, ever-changing hardware without needing to be redesigned for every new architectural shift.

Summary updated

BibTeX
@inproceedings{afshani2022locality,
  author = {peyman afshani and John Iacono and Varunkumar Jayapaul and Ben Karsin},
  title = {{Locality}},
  booktitle = {Apocs},
  year = {2022},
  doi = {10.1137/1.9781611977059.3},
}
Figure