{
  "slug": "reuse-distance",
  "term": "Reuse distance",
  "aliases": [
    "LRU stack distance",
    "distinct-reference distance"
  ],
  "definition": "Reuse distance counts distinct identities accessed strictly between consecutive references to the same cache entry.",
  "note": "Immediate repetition has distance zero; a first appearance has no finite distance in a cold-start trace. Under equal-size, fully associative LRU with immediate demand admission, a reuse hits when its distance d is less than capacity C. Equality is a miss. [reuse-report]\n\nSome literature instead reports a one-based stack position s = d + 1, which hits when s <= C. Check the convention before comparing values or thresholds. [counter-stacks]\n\nExact analysis with a balanced tree and hash table uses O(N log M) time and O(M) space for N references and M identities. SHARDS samples identities by hash and rescales distances; its memory-bounded variant adapts the sampling rate. [shards]\n\nReported accuracy: with an 8K sample cap across 124 traces, fixed-size SHARDS had median per-trace MAE 0.0072 and maximum 0.078; the adjusted variant had 0.0027 and 0.017. MAE averages absolute miss-ratio differences over evaluated cache sizes. Neither statistic bounds error at every capacity or guarantees accuracy on another workload. [shards]\n\nEfficient exact evaluation keeps one last-access timestamp per identity and counts active timestamps after the preceding occurrence. Ding and Zhong describe this counting approach. Hesela's bounded evaluator uses a binary indexed tree with O(N) positional storage, distinct from a tree with O(M) storage for M unique identities. [reuse-report]",
  "status": "research",
  "advantages": [
    {
      "text": "One pass that collects a reuse-distance histogram yields the LRU miss ratio for every cache size, without one simulation per size.",
      "citationIds": [
        "shards"
      ]
    }
  ],
  "limitations": [
    {
      "text": "The d < C threshold is for exact LRU under the stated demand-cache assumptions, not every policy using a stack. LIRS requires its own state transitions; sharding, invalidation or admission changes also require a matching model.",
      "citationIds": [
        "reuse-report",
        "lirs05"
      ]
    }
  ],
  "related": [
    "lru-replacement",
    "miss-ratio-curve",
    "cache-inclusion-property",
    "mapping-cache",
    "adaptive-replacement-cache",
    "working-set",
    "locality-of-reference",
    "lirs-replacement",
    "linux-refault-distance",
    "clock-pro",
    "reuse-time",
    "move-to-front",
    "shards",
    "statstack",
    "counter-stacks"
  ],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-11-18",
  "citations": [
    {
      "id": "reuse-report",
      "title": "Ding and Zhong. Reuse Distance Analysis. UR-CS-TR-741, February 2001, sections 2.1-2.2 and Figures 1-3.",
      "url": "https://www.cs.rochester.edu/u/cding/Documents/Publications/TR741.pdf",
      "accessed": "2026-11-01"
    },
    {
      "id": "counter-stacks",
      "title": "Wires et al. Characterizing Storage Workloads with Counter Stacks. OSDI 2014, sections 2 and 3.2.",
      "url": "https://files.usenix.org/s3fs-public/cdn/osdi14-paper-wires.pdf",
      "accessed": "2026-10-23"
    },
    {
      "id": "hesela",
      "title": "Hesela. LRU sizing from distinct-entry reuse distances; constructed examples.",
      "url": "https://hesela.com/analyses/ssd-mapping-cache-hmb/#reuse-distance",
      "accessed": "2026-10-19"
    },
    {
      "id": "shards",
      "title": "Waldspurger et al. Efficient MRC Construction with SHARDS. FAST 2015, sections 2, 4.2 and 4.3.1-4.3.3; Figure 4.",
      "url": "https://www.usenix.org/system/files/conference/fast15/fast15-paper-waldspurger.pdf",
      "accessed": "2026-11-01"
    },
    {
      "id": "lirs05",
      "title": "Jiang and Zhang. Making LRU Friendly to Weak Locality Workloads. IEEE TC 54(8), 939-952 (2005), sections 1.2, 3.3 and 4.",
      "url": "https://ranger.uta.edu/~sjiang/pubs/papers/jiang05_LIRS.pdf",
      "accessed": "2026-10-30"
    }
  ],
  "provenance": [
    "SHARDS sections 4.2 and 4.3.1-4.3.3 and Figure 4 checked 2026-11-01 for population, capacity-averaged error and original versus adjusted results.",
    "counter-stacks read 2026-10-23, sections 2 and 3.2, for the stack-position convention.",
    "A companion analysis with constructed traces is listed but not used in prose."
  ]
}
