Skip to content

Real cache size - #79490

Merged
alexey-milovidov merged 97 commits into
ClickHouse:masterfrom
codeworse:physical_cache_size
Oct 15, 2026
Merged

alexey-milovidov merged 97 commits into
ClickHouse:masterfrom
codeworse:physical_cache_size

Conversation

@codeworse

@codeworse codeworse commented Apr 23, 2025 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Added a new filesystem cache setting use_real_disk_size (disabled by default). When enabled, cache reservations are accounted in filesystem allocation units (block size) instead of raw reserved bytes, so the FilesystemCacheSize metric, the eviction-size metrics, and current_size in system.filesystem_cache_settings use block-aligned reservation accounting. The accounting is a block-aligned approximation of the reservation footprint on disk, not the exact allocated size; an in-flight read can include reserve-ahead bytes that have not yet been written.

Documentation entry for user-facing changes

  • Documentation is written

Documented the use_real_disk_size filesystem cache setting in docs/concepts/features/configuration/server-config/storing-data.mdx. It accounts cache reservations in filesystem allocation units (block size), so FilesystemCacheSize, the eviction-size metrics, and current_size in system.filesystem_cache_settings use block-aligned reservation accounting (a block-aligned approximation of the reservation footprint on disk). The per-segment size in system.filesystem_cache is not affected by this setting and stays the segment's logical range size; for a partially downloaded segment, use downloaded_size for the bytes actually written.


Workflow [PR]
Sync PR [sync-upstream/pr/79490]

Version info

  • Merged into: 26.10.1.2433-master (included in 26.10 and later)

@kssenii kssenii self-assigned this Apr 24, 2025
Comment thread src/Interpreters/Cache/Metadata.h Resolved
Comment thread tests/integration/helpers/cluster.py Resolved
@codeworse
codeworse marked this pull request as ready for review April 28, 2025 12:50
@codeworse

Copy link
Copy Markdown
Contributor Author

@kssenii Could you add labels to test PR?

@kssenii kssenii added the can be tested Allows running workflows for external contributors label Apr 30, 2025
@clickhouse-gh

clickhouse-gh Bot commented Apr 30, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [76af1f5]

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Apr 30, 2025
Comment thread src/Common/filesystemHelpers.cpp Resolved
Comment thread src/Common/filesystemHelpers.h Resolved
Comment thread src/Common/filesystemHelpers.h Resolved
Comment thread src/Interpreters/Cache/Metadata.h Resolved
@codeworse
codeworse force-pushed the physical_cache_size branch from fc4e793 to e3e450b Compare May 12, 2025 16:44
Comment thread src/Interpreters/Cache/Metadata.cpp Resolved
@kssenii

kssenii commented May 27, 2025

Copy link
Copy Markdown
Member

From previous commit, where there was "invalid check_status.txt" in run.log:

<Fatal> : Logical error: 'Mismatch of file segment size in file segment metadata and priority queue: 4096 != 1 (File segment: [0, 0], key: 86ad97577bbaab14994b56ba2ff74e3f, state: DOWNLOADED, downloaded size: 1, reserved size: 1, downloader id: None, current write offset: 1, caller id: acac9396-c39e-4eaf-8476-8059ddf9989c:3403, kind: Regular, unbound: 0)'.

https://s3.amazonaws.com/clickhouse-test-reports/PRs/79490/e94277bc97c01bc4045fbee4e8d563fdeb7064d7//stateless_tests_tsan_s3_storage_1_3/run.log

Need to use here entry.getFilledSize() instead of entry.getSize() I guess
https://github.com/ClickHouse/ClickHouse/blob/27ced4818a17e0bd543eaf62f70f0133f4b4208d/src/Interpreters/Cache/LRUFileCachePriority.cpp#L212-L219

Comment thread src/Interpreters/Cache/FileSegment.h Resolved
@codeworse
codeworse force-pushed the physical_cache_size branch from 9db3ffe to 7253282 Compare June 2, 2025 14:09
Comment thread tests/integration/parallel_skip.yaml Resolved
Comment thread tests/config/config.d/storage_conf.xml Resolved
Comment thread src/Interpreters/Cache/FileSegment.cpp Resolved
Comment thread src/Interpreters/Cache/FileSegment.cpp Resolved
@codeworse
codeworse force-pushed the physical_cache_size branch from 516514c to 050df75 Compare June 11, 2025 13:11
@abashkeev abashkeev added the comp-filesystem-cache Filesystem cache for remote/object storage, page cache, and read caching infrastructure. label Sep 3, 2026
…umn descriptions

The AI review noted that the guide explains how `use_real_disk_size`
affects `current_size` in `system.filesystem_cache_settings` and leaves
`system.filesystem_cache.size` as the logical segment size, while the
source-registered column descriptions - which are the source of truth
for the autogenerated system-table references - still said only
`Current cache size` and `Size of the file segment`.

Tighten both descriptions so the structured reference documentation
states the same contract. The generated regions under
`docs/reference/system-tables/` are not edited here: they are refreshed
by the documentation autogeneration workflow from these comments.
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Addressed the remaining AI review nit and merged master (bc3441225..0767bdd7c).

Review nit — system-table column descriptions (423a980c6f42). The guide already explained that use_real_disk_size changes current_size in system.filesystem_cache_settings and leaves system.filesystem_cache.size as the logical segment size, but the source-registered column descriptions, which are the source of truth for the autogenerated system-table references, still read only Current cache size and Size of the file segment. Both are tightened now:

  • current_size in src/Interpreters/FileCache/FileCacheSettings.cpp — the sum of the reserved sizes of the cache file segments by default; with use_real_disk_size the reservations are accounted in filesystem block-aligned units, so the value approximates the space the cache occupies on disk.
  • size in src/Storages/System/StorageSystemFilesystemCache.cpp — the logical size of the file segment range, explicitly not affected by use_real_disk_size, with a pointer to downloaded_size for the bytes actually written.

The generated regions in docs/reference/system-tables/filesystem_cache_settings.mdx and docs/reference/system-tables/filesystem_cache.mdx are intentionally untouched: they lie between AUTOGENERATED_START and AUTOGENERATED_END and are refreshed from these source comments by the documentation autogeneration workflow.

Master merge (0767bdd7cff0). A single merge base, no conflicts. The diff against master is exactly this pull request's own delta, no submodule gitlink is dropped, and 02344_describe_cache.reference needs no update — master has not touched src/Interpreters/FileCache/ since the previous base. The upgrade-check version gate in tests/config/install.sh still reads check_clickhouse_version 26.9 and master is still 26.9.1, so no bump was due this time.

ninja clickhouse and src/CMakeFiles/unit_tests_dbms.dir/Interpreters/tests/gtest_filecache.cpp.o both build with exit code 0, and the C++ style check passes locally.

The previous commit was fully green apart from CH Inc sync, which is chronically pending on fork pull requests and is not a required check.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master (0767bdd7c..9d9bded6d, conflict-free; the branch was 8 days behind). Master touched FileCacheSettings only to mark write_cache_per_user_id_directory obsolete and add a warning, so 02344_describe_cache.reference is unchanged and the install.sh gate for use_real_disk_size stays at 26.9 (master is still 26.9). Rebuilt clickhouse and gtest_filecache.cpp.o cleanly and re-ran test_aligned_cache_s3 locally: 4 passed. Approved the gated CI run.

alexey-milovidov and others added 2 commits September 23, 2026 16:22
…he priority queue; bump upgrade gate to 26.10

`getUsedCacheSize` reads `main_priority->getSizeApprox`, which also includes
transient holds from `LRUFileCachePriority::holdImpl`, so `current_size` is not
only the sum of file segment reservations.

Master bumped `VERSION_MINOR` to 26.10, so the previous release in the upgrade
check (26.9) does not know `use_real_disk_size`; strip it for versions below 26.10.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master (single merge base, no conflicts), which also pulls in #119810 — the fix for the Stress test (arm_asan_ubsan, s3) red (t_pfl_05079 could not be re-attached). Bumped the use_real_disk_size upgrade-check gate to 26.10 because master is now 26.10. Addressed the current_size description review thread. The Build profile diff red was an infrastructure error (the CI logs cluster query failed) and has nothing to do with this PR. clickhouse and gtest_filecache build locally.

alexey-milovidov and others added 3 commits October 2, 2026 11:11
Resolved conflict in `FileCache::doTryReserve`: took master's `rollback_main_entry` lambda, keeping the PR's `aligned_delta` for the size rollback.
…t_size`

The process-wide `FilesystemCacheSize` metric and eviction-size profile events
sum over all caches, so they are uniform only when all caches use the same mode.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	docs/concepts/features/configuration/server-config/storing-data.mdx
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master (7fbdb445a..b6f2cd47b). The only conflict was in the cache settings table of docs/concepts/features/configuration/server-config/storing-data.mdx: master added rows for background_download_threads, background_download_queue_size_limit, background_download_max_file_segment_size, load_metadata_asynchronously, and reworded use_split_cache. I kept all of master's rows and put the use_real_disk_size row back before use_split_cache. The FileCache translation units still build. The use_real_disk_size upgrade-check gate in install.sh stays at 26.10, which matches master's VERSION_MINOR.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master (b6f2cd47b..c12f3bf9c, conflict-free). Master brought in the dynamic reserve-ahead rework (#123255) in FileSegment/FileCacheReserveAhead; it does not touch the use_real_disk_size accounting in FileCache::doTryReserve, and clickhouse and gtest_filecache.cpp.o rebuild cleanly. The diff against master is unchanged (same 23 files). There are no unresolved review threads.

CI has not run on this branch since 2026-10-04: the PR workflow for the previous head is in action_required, because this is a fork PR with the manual approve label. A maintainer has to approve the workflow run for the new head.

@clickhouse-gh

clickhouse-gh Bot commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 31 queries analysed

This PR adds an opt-in use_real_disk_size setting for the filesystem cache, which counts cache reservations in filesystem-block-aligned units. The setting is off by default, and with it off the new code returns the same sizes as before. The only flagged query is clickbench Q30. It shows +10.3% (242.0 vs 219.5 ms), but that is inside master's current run-to-run range, and CPU time did not move (2330.6 vs 2315.1 ms). It stays not_sure and cannot be attributed to this PR, and no other query changed.

clickbench

⚠️ 1 inconclusive

Flagged queries (1 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 30 not_sure 220 242 +10.3% <0.0001 cpu: The +10.3% wall-time shift sits inside master's current 200-296 ms range, and CPU time is flat (2330.6 vs 2315.1 ms). The cache-accounting change does nothing with use_real_disk_size off, so this cannot be pinned on the PR.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. 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_official

🟢 No significant changes

Debug info
  • StressHouse run: 4079df75-95a8-47dc-8a81-cde51c688411
  • MIRAI run: 0d427b79-26f1-411c-84d6-3a0a44701ef2
  • PR check IDs:
    • clickbench_749765_1791658501
    • clickbench_749771_1791658501
    • clickbench_749777_1791658501
    • tpch_adapted_1_official_749787_1791658501
    • tpch_adapted_1_official_749799_1791658501
    • tpch_adapted_1_official_749835_1791658501

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is clean and straightforward.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 12, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 12, 2026
# Conflicts:
#	tests/docker_scripts/stress_runner.sh
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master (c12f3bf9c..a90b3e174). The only conflict was in tests/docker_scripts/stress_runner.sh: master added the mark_cache_policy/uncompressed_cache_policy randomization at the same spot where this PR randomizes use_real_disk_size; both blocks are kept. The changed FileCache translation units and gtest_filecache.cpp compile against current master.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 The CI failures on a90b3e17 are unrelated to this change; none of them involve FileCache:

  • Build (arm_fuzzers): the Docker container died during the final fuzzer link steps (error waiting for container: unexpected EOF, exit code 125). There were no compile errors.
  • Stateless tests (arm_asan_ubsan, azure, parallel): the runner was lost after exactly 30 minutes, with no steps recorded.
  • Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel): 05210_lightweight_update_materialized_cte_in_ignore failed with UNKNOWN_TABLE for a materialized CTE. The flaky-check reruns classified it as flaky (1 failure in 119 reruns).
  • Performance Comparison (arm_release, master_head, 3/6): the results could not be uploaded to CIDB (play.clickhouse.com refused the connection), so no verdict was produced.

I re-ran the failed jobs (run attempt 4).

CH Inc sync: the sync PR had a merge conflict in tests/docker_scripts/stress_runner.sh. It is the same spot as in the last public master merge: the use_real_disk_size randomization next to master's new mark_cache_policy/uncompressed_cache_policy block. I merged private master into the sync branch, kept both blocks, then merged the PR head a90b3e17 cleanly and pushed. The sync PR is now MERGEABLE. Its diff against private master contains this PR's 23 files plus the existing private gtest_filecache_overcommit adaptation.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 15, 2026
Merged via the queue into ClickHouse:master with commit aa8b9aa Oct 15, 2026
514 of 523 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-filesystem-cache Filesystem cache for remote/object storage, page cache, and read caching infrastructure. manual approve Manual approve required to run CI pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants