disk: bound resident LRU index entries with WithMaxEntries (WS2) - #32
Draft
shreyas-blacksmith wants to merge 1 commit into
Draft
disk: bound resident LRU index entries with WithMaxEntries (WS2)#32shreyas-blacksmith wants to merge 1 commit into
shreyas-blacksmith wants to merge 1 commit into
Conversation
The byte budget does not bound entry count: zero-byte blobs charge nothing and tiny blobs at most one 4 KiB block, while each resident entry costs a measured ~268 B of index metadata (key string, entry struct, list node, map slot). A byte-full 10 GiB cache can therefore hold ~2.6M entries (~670 MiB of metadata). WithMaxEntries adds an opt-in entry-count cap with the same eviction semantics as the byte budget, enforced on Add and during the startup scan, plus a counter separating count-cap evictions from byte-cap evictions. Co-authored-by: Cursor <cursoragent@cursor.com>
This was referenced Jul 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WithMaxEntries(n)option: inserting a new key past the cap evicts from the LRU tail, exactly like the byte budget but counting entries. The startup scan enforces it too (oldest trimmed during load, like a restart with a smaller max size). Default (n <= 0) is bit-identical to upstream.bazel_remote_disk_cache_max_entries_evictions_totalto separate count-cap evictions from byte-cap evictions, and an opt-in measurement test (TestLRUEntryMetadataCost) documenting the per-entry constant.Part of the embedder's memory-envelope program (WS2); stacked on the bounded zstd transcoding branch (#27).
Test plan
go test ./cache/... ./server/...greendisk.New+WithMaxEntriesunder puts; startup trim of an over-cap cache directoryMade with Cursor
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled. (Staging)Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.