Repository navigation
File cache: make reserve granularity dynamic - #123255
Conversation
The reserve-ahead used by `FileSegment::reserve` now starts from 0 for every reader/writer (the first reservation is exact), then equals the requested size and doubles with each further reservation the same reader/writer makes, up to `reserve_granularity` (default 4Mi), which now acts as the upper limit. It is reset after a failed reservation. A one-off small read no longer charges a whole granule against the cache, while long sequential downloads still reach the limit quickly. The state (`FileCacheReserveAhead`) lives in the caller: the cached read buffer (kept across file segments and seeks), the write-through range writer, `WriteBufferToFileSegment` and the background download loop. Callers that do not pass it reserve exactly the requested size. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Workflow [PR], commit [05ba339] Summary: ✅
AI ReviewSummaryThis PR makes filesystem-cache Final Verdict
LLVM Coverage ReportMeasured on commit 05ba339.
Changed lines: Changed C/C++ lines covered: 116/122 (95.08%) · Uncovered code |
…ahead at twice the request Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…oard Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units1811 translation units recompiled, 11548 s compile time in total, 1811 of them have a recent master baseline. |
…tries as failures Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… it on jumpToPosition Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
| struct FileCacheReserveAhead | ||
| { | ||
| /// Returns the size to reserve, at least `size_to_reserve`, and grows the reserve-ahead. | ||
| size_t getReserveSize(size_t size_to_reserve, size_t max_reserve_size, size_t limit) |
There was a problem hiding this comment.
I read this paraments as:
limit - > max_reserve_step / max_step, do not reserve more that this right now, actually very close to max_reserve_size but this is about experiential growth
granularity -> next_reserve_step / next_step, It is not granularity. This is experiential growth.
max_reserve_size -> size_left_to_reserve / reserve_upper_bound, very close to limit but about the global limitation, we do not need more
may be some of them is good to rename in this way.
| size_t getReserveSize(size_t size_to_reserve, size_t max_reserve_size, size_t limit) | ||
| { | ||
| const size_t result = std::max(size_to_reserve, std::min({granularity, limit, max_reserve_size})); | ||
| granularity = std::min(limit, granularity ? granularity * 2 : size_to_reserve * 2); |
There was a problem hiding this comment.
I suggest
granularity = std::min(limit, std::max(granularity, size_to_reserve) * 2);
to exclude the case when the start is too small.
The scenario: other reader become the leader/downloader or the background downloader need to finish the work, it writes to the reserverd space and the last write need few more bytes, that triggers getReserveSize with short size_to_reserve, then the granularity is inited short and next calls do not reserve data ahead, they go with exact request.
In that way we start or/and adjust granularity at least up to size_to_reserve.
`limit` -> `max_reserve_granularity`, `max_reserve_size` -> `segment_reserve_limit`, to tell the cap on the reserve-ahead growth from the cap on the total reservation. Related: #123255 (comment) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A short first request (e.g. a reader taking over a segment with leftover reservation) started the reserve-ahead tiny, so the following larger requests were reserved exactly for many calls until the doubling caught up. Related: #123255 (comment) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`DiskCacheWriter::write` called `FileSegment::reserve` without a reserve-ahead state, so the cache-miss fill path reserved exactly per window and took the cache lock on every write. Keep one state per writer (it owns a single append-only segment) and cap reserve-ahead at the end of the miss range. Related: #123255 (comment) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Backport #123255 to 26.9: File cache: make reserve granularity dynamic
Backport #123255 to 26.8: File cache: make reserve granularity dynamic
…o master `SegmentSizes` released a reserved but unwritten temporary segment, which aborts on `EMPTY => !queue_iterator` in builds with `chassert`. `EfficiencyWindow` relied on implicit reserve-ahead, which #123255 made explicit.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Filesystem cache: make reserve granularity dynamic
Workflow [PR]
Sync PR [sync-upstream/pr/123255]
Version info
26.10.1.1632-master(included in26.10and later)26.9.12.7,26.8.19.9