Skip to content

perf(cache): preserve adaptive LRU during autopin - #815

Merged
JustVugg merged 1 commit into
JustVugg:devfrom
bherald:perf/autopin-preserve-lru
Aug 4, 2026
Merged

perf(cache): preserve adaptive LRU during autopin#815
JustVugg merged 1 commit into
JustVugg:devfrom
bherald:perf/autopin-preserve-lru

Conversation

@bherald

@bherald bherald commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • cap automatic history pinning so it cannot reduce the adaptive LRU capacity that fits before pinning
  • leave explicit PIN and PIN_GB behavior unchanged
  • add focused cache-budget regression cases and document the shared RAM policy

Why

Automatic history pinning currently claims up to half of the entire expert RAM budget before cap_for_ram() sizes the adaptive LRU. On memory-constrained systems, the pinned hot store can therefore displace LRU slots even when that produces more misses and expert I/O.

The new calculation determines the no-pin LRU capacity, up to the requested cap, reserves the bytes needed for those slots, and gives automatic pinning only the remaining expert budget. Systems with enough RAM retain the existing half-budget plan. Explicit pin settings remain authoritative.

Validation

  • Linux make -C c test-c: all native C gates passed
  • Linux make -C c test-python: 281 passed, 19 skipped
  • Windows 11 / Ryzen 9 7845HX:
    • make -C c check ARCH=native
    • all native C gates passed
    • 286 Python tests passed, 51 skipped
  • fixed 24-token CPU-only replay on Windows 11 with 32 GB RAM and a regular SSD, three balanced repetitions per arm:
    • constrained autopin: 1.4 GB pinned, LRU cap 4, 22.2% hit rate, 254.4 GB fetched, 0.54 tok/s in all three runs
    • previous half-budget placement: 7.1 GB pinned, LRU cap 2, 16.1% hit rate, 266.4 GB fetched, 0.52 tok/s in all three runs
    • median throughput improved 3.85%, with 4.5% less expert I/O
    • autopin disabled also retained cap 4 and had a 0.54 tok/s median, while the constrained hot set was stable and fetched 1.3 GB less

The replay used the same binary, model, frozen usage history, token sequence, and CPU-only environment for every arm.

Automatic history pinning took up to half of the expert RAM budget before the adaptive LRU was sized, allowing learned pins to reduce cache capacity and increase expert I/O on constrained systems.

Reserve the affordable no-pin LRU capacity before calculating the automatic pin budget. Keep explicit PIN and PIN_GB settings authoritative, and document the shared RAM policy.

Add focused budget regression cases. Verify the change with the complete Linux and Windows suites and a balanced fixed-token Windows replay that improves median throughput by 3.85% while reducing expert I/O by 4.5%.
@JustVugg
JustVugg merged commit a4d7b90 into JustVugg:dev Aug 4, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants