Repository navigation
Fix memory usage growth in fs cache - #106387
Conversation
|
Workflow [PR], commit [ff8117a] Summary: ✅
AI ReviewSummaryThe PR adds proactive background cleanup for invalidated filesystem cache priority queue entries, exposes cleanup tuning settings and profile events, avoids registering soon-to-be-removed entries, and adds an integration regression test for delayed cleanup. I traced the final Final VerdictStatus: ✅ Approve |
11e1565 to
12aec51
Compare
6e7db3e to
6ec0d63
Compare
| if (entry_size) | ||
| cache_priority->state->sub(entry_size, 1); | ||
|
|
||
| cache_priority->addInvalidatedRef(entry, iterator); |
There was a problem hiding this comment.
I guess we need to make sure this function doesn't throw exceptions? eg block memory exceeded
…invalidated-entries-cleanup # Conflicts: # src/Interpreters/FileCache/IFileCachePriority.cpp # src/Interpreters/FileCache/IFileCachePriority.h
…atedEntries The invalidate contract must not throw: mark `IFileCachePriority::Iterator::invalidate` and its `SLRU`/`Split` overrides `noexcept` (only `LRUIterator` was), and mark the `addInvalidatedRef` helper `noexcept` too so the compiler enforces it. Also guard the `push_front` in the `removeInvalidatedEntries` catch block with `LockMemoryExceptionInThread`: it runs while handling a caught exception (so `std::uncaught_exceptions()` no longer blocks the tracker), and a throw there would lose the ref and mask the original exception. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
51383b3 to
a739872
Compare
a739872 to
8f0ed68
Compare
|
📊 Cloud Performance Report ✅ AI verdict: This PR adds a background cleanup task that purges lazily-invalidated filesystem-cache priority-queue entries (plus new settings and profile events). That logic only runs during cache eviction and DROP CACHE, not on the warm-cache read path that the benchmark queries execute, so it can't plausibly make these SELECTs 20-48% faster. ClickBench Q22 and TPC-H Q20 also had very noisy baselines, and the TPC-H queries are intrinsically flaky, so all four flagged improvements have been downgraded to not-sure as likely baseline variance rather than a real effect of this change. No regressions were observed. clickbenchFlagged queries (2 of 43)
q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_officialFlagged queries (2 of 22)
q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. Debug info
|
`LRUIterator::invalidate` recorded every invalidated queue entry into `invalidated_refs` for the background cleanup task to drain. However, that cleanup task is only started in `startup`, which is called for `main_priority` only. A `Query` priority (constructed by `FileCacheQueryLimit::QueryContext`) never drains `invalidated_refs`, so when per-query recache evicts entries with `enable_filesystem_query_cache_limit` enabled, `EvictionCandidates` calls `invalidate` and one stale ref accumulated per eviction until query end. Only register refs for the `Main` priority, which is the one actually drained. The queue node itself is still removed opportunistically through `remove`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 130/154 (84.42%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 10 line(s) · Uncovered code |
|
Added above labels (26.5 and long term support 26.3) for public backports only, backports to private branches I already did separately. |
Cherry pick #106387 to 26.5: Fix memory usage growth in fs cache
Backport #106387 to 26.5: Fix memory usage growth in fs cache
Before this PR invalidated entries removal (delayed cleanup) was made either during eviction or by keep_up_free_space background thread, which misses a case when eviction is not made since cache size limit is not reached. This PR adds unconditional cleanup to cover eviction-free case. This is a pre-existing issue and not related to any recent release.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix memory usage growth in filesystem cache.
Version info
26.6.1.883(included in26.6and later)26.5.6.72