Skip to content

fix(memory): recover stale LRU high-priority weight - #1300

Open
mjc wants to merge 1 commit into
foyer-rs:mainfrom
mjc:mjc/lru-overflow-recovery
Open

mjc wants to merge 1 commit into
foyer-rs:mainfrom
mjc:mjc/lru-overflow-recovery

Conversation

@mjc

@mjc mjc commented Jun 16, 2026

Copy link
Copy Markdown

What's changed and what's your intention?

Fix LRU high-priority weight recovery when the tracked counter drifts from the intrusive high-priority list.

The overflow path assumed high_priority_weight > high_priority_weight_capacity always implied a non-empty high-priority list, and could panic if the accounting was already stale. This PR repairs stale accounting by recomputing the actual high-priority list weight when recovery is needed, and routes high-priority decrements through a checked helper used by overflow, pop, remove, and acquire paths.

A user of a crate I maintain ran into this scenario in nntp-proxy#73.

Checklist

  • I have written the necessary rustdoc comments
  • I have added the necessary unit tests and integration tests
  • I have passed cargo x (or cargo x --fast instead if the old tests are not modified) in my local environment.

cargo x --fast was run; clippy, strict test run, doctests, docs, examples, and cargo-machete passed, then the final legacy license-eye header check step failed. The current license workflow command, hawkeye check, passes.

@mjc
mjc requested review from MrCroxx and tisonkun as code owners June 16, 2026 02:28
@yihong0618

Copy link
Copy Markdown
Contributor

interesting this kind of releated #1237 and #1238

@mjc

mjc commented Jun 16, 2026 •

Copy link
Copy Markdown
Author

@yihong0618 yes it was still possible to get into the state mentioned; this refactor should make it recoverable in a safe way

@codecov

codecov Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
foyer-memory/src/eviction/lru.rs 97.15% <100.00%> (+1.04%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mjc
mjc force-pushed the mjc/lru-overflow-recovery branch from b144ca7 to 5405515 Compare June 16, 2026 04:33
Avoid panicking when LRU high-priority weight accounting drifts from the intrusive high-priority list.

Replace the empty-list overflow unwrap with recovery that recalculates the tracked weight from the actual list. Route high-priority weight decrements through a checked helper so overflow, pop, remove, and acquire paths repair stale accounting instead of underflowing or preserving poisoned state.

Add regression coverage for empty-list overcount, understated counters, and last-entry overflow recovery.

Signed-off-by: Mika Cohen <mjc@kernel.org>
@mjc
mjc force-pushed the mjc/lru-overflow-recovery branch from 5405515 to 73d40aa Compare June 19, 2026 15:31

This branch has not been deployed

No deployments
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