Skip to content

Fix Performance Comparison report-build host-OOM by disabling cgroup memory correction - #108804

Merged
azat merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-perf-report-cgroup-oom
Jun 29, 2026
Merged

azat merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-perf-report-cgroup-oom

Conversation

@groeneai

@groeneai groeneai commented Jun 29, 2026 •

Copy link
Copy Markdown
Collaborator

No related open issue found.

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

Description

Fixes the recurring Performance Comparison (..., master_head/release_base, N/6) job failure "Errors while Building the Report", which is a host-OOM at the report-assembly stage, not a perf regression:

Code: 241. DB::Exception: (total) memory limit exceeded: would use 53.49 GiB
(attempt to allocate chunk of 64.00 MiB), current RSS: 42.98 GiB, maximum: 53.44 GiB:
While executing MergeSortingTransform. (MEMORY_LIMIT_EXCEEDED)

Seen across many unrelated PRs and on master (10+ distinct PRs in the last 7 days on arm_release alone).

Root cause: the report stage runs many clickhouse-local processes concurrently (GNU parallel in compare.sh::analyze_queries, one per query for the randomization step), all inside the job's single cgroup, alongside the OS page cache left by reading the multi-GB datasets and profile TSVs. clickhouse-local defaults to memory_worker_use_cgroup=1, so each process "corrects" its own total-memory tracker up to the cgroup-wide memory.current -- which sums every sibling clickhouse-local plus reclaimable page cache. The tracker then trips its hard limit (Code 241) inside MergeSortingTransform/AggregatingTransform even though each query's own allocations are small (the failing job's own request was well under 1 GiB; it was killed because the cgroup-wide RSS was 42.98 GiB).

Fix: pass --memory_worker_use_cgroup=0 to every report-building clickhouse-local invocation (the analyze/report/metrics queries in compare.sh and the build_raw_query_metrics_tsv / build_flamegraph_upload_tsv calls in performance_tests.py). Each report query is then tracked against its own RSS via jemalloc/proc instead of the shared cgroup, so concurrent siblings and page cache no longer push it over the limit. This does not touch the clickhouse-client calls to the measured left/right servers -- those keep their normal memory limits. Per-query peak memory is unchanged (the queries are data-bound, not thread-bound), so aggregate anonymous memory stays well under the cap and the existing parallel --memsuspend remains the aggregate backstop.

Reproduced locally with the snapshot binary by running several report queries concurrently inside a memory-capped cgroup (systemd-run --scope -p MemoryMax=...): with the default (memory_worker_use_cgroup=1) the jobs fail with the exact Code 241 ... MEMORY_LIMIT_EXCEEDED ... While executing MergeSortingTransform/AggregatingTransform signature; with --memory_worker_use_cgroup=0 they all complete.

Version info

  • Merged into: 26.7.1.254 (included in 26.7 and later)

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Ran several report-build clickhouse-local jobs concurrently inside a memory-capped cgroup (systemd-run --user --scope -p MemoryMax=4G); with the default memory_worker_use_cgroup=1, 6/6 jobs fail on demand with Code: 241 ... (total) memory limit exceeded ... current RSS: 3.5 GiB, maximum: 3.56 GiB: While executing MergeSortingTransform/AggregatingTransform. (MEMORY_LIMIT_EXCEEDED) — the exact CI signature (CI: "would use 53.49 GiB ... current RSS 42.98 GiB ... MergeSortingTransform").
b Root cause explained? Yes. The report stage runs many clickhouse-local processes concurrently (GNU parallel in compare.sh::analyze_queries, one per query) inside the job's single cgroup, next to page cache from the multi-GB datasets/TSVs. With memory_worker_use_cgroup=1 (default), each process corrects its own total-memory tracker up to the cgroup-wide memory.current (sum of all siblings + reclaimable page cache) and trips its hard limit, even though its own allocations are <1 GiB. The CI cap is 53.44 GiB and the cgroup RSS reached 42.98 GiB across the concurrent set.
c Fix matches root cause? Yes. Pass --memory_worker_use_cgroup=0 to every report-building clickhouse-local so each is tracked against its own RSS (jemalloc/proc) instead of the shared cgroup. This directly removes the cross-process/page-cache over-accounting that is the mechanism in (b). Not a band-aid: no thresholds widened, no work removed.
d Test intent preserved / new tests added? Yes. The perf comparison itself (the measured left/right server queries via clickhouse-client) is untouched and keeps its normal memory limits — only the report-assembly clickhouse-local helpers change. No assertion/threshold is weakened. (No new test: this is CI-harness infrastructure, not a product code path; the existing perf job is the test.)
e Both directions demonstrated? Yes. Same 6-concurrent-job / capped-cgroup repro: WITHOUT the fix (memory_worker_use_cgroup=1) → 6/6 Code 241 MEMORY_LIMIT_EXCEEDED; WITH the fix (-- --memory_worker_use_cgroup=0) → 0/6 Code 241, all complete. Verified the eqmed/analyze invocations produce identical output and the -- server-setting form parses cleanly.
f Fix is general across code paths? Yes. Applied uniformly to ALL report-building clickhouse-local sites: the 6 --query invocations + the per-query eqmed.sql parallel template in compare.sh, and both subprocess.run calls (build_raw_query_metrics_tsv, build_flamegraph_upload_tsv) in performance_tests.py. The measured-server clickhouse-client calls are intentionally excluded (they must keep real memory limits).
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (CI harness setting change, not a code-path/datatype bug). The setting governs the memory-tracker source uniformly regardless of query/data.
h Backward compatible? (maintainer-approved exception only) Yes / N/A. No product behavior, on-disk/wire format, or setting default changes — only a per-invocation server setting on internal CI report helpers. No SettingsChangesHistory.cpp impact.
i Invariants and contracts preserved? Yes. memory_worker_use_cgroup=0 makes the tracker read true process RSS (jemalloc/proc) instead of cgroup memory.current; per-query peak memory is unchanged (queries are data-bound), so aggregate anonymous memory stays well under the cap and the existing parallel --memsuspend remains the aggregate backstop. The report output (sorted TSVs) is byte-identical.

Session id: cron:clickhouse-worker-slot-3:20260629-093600

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @azat @alexey-milovidov — could you review? The perf report stage runs many clickhouse-local processes concurrently in one cgroup; with the default memory_worker_use_cgroup=1 each corrects its tracker to the cgroup-wide memory.current (siblings + page cache) and trips its hard limit (the recurring "Errors while Building the Report" Code 241 in MergeSortingTransform). This passes --memory_worker_use_cgroup=0 to the report-building clickhouse-local calls only (the measured servers keep their limits).

Comment thread ci/jobs/performance_tests.py Outdated
Comment on lines +27 to +36
# Server settings (passed after `--`) for the report-building clickhouse-local
# invocations. They run inside the job's cgroup alongside the OS page cache left
# by reading the multi-GB datasets/logs. With memory_worker_use_cgroup=1 (the
# default) each process "corrects" its own memory tracker up to the cgroup-wide
# memory.current -- which includes that reclaimable page cache and any sibling
# clickhouse-local processes -- and can trip its total-memory hard limit with
# Code 241 MEMORY_LIMIT_EXCEEDED even though the query's own allocations are
# small. Disable cgroup correction so each report query is tracked against its
# own usage only. Keep in sync with CHPC_REPORT_LOCAL_SERVER_SETTINGS in
# ci/jobs/scripts/perf/compare.sh.

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.

Here and below the comments should be compact, keep only essential things please

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in 74203e8 — trimmed both comment blocks (compare.sh and performance_tests.py) to the essential what + the keep-in-sync note; the full mechanism is in the commit message.

@azat azat self-assigned this Jun 29, 2026
@azat

azat commented Jun 29, 2026

Copy link
Copy Markdown
Member
Code: 241. DB::Exception: (total) memory limit exceeded: would use 53.49 GiB
(attempt to allocate chunk of 64.00 MiB), current RSS: 42.98 GiB, maximum: 53.44 GiB:
While executing MergeSortingTransform. (MEMORY_LIMIT_EXCEEDED)

Please provide a link to CI report

…correction

The Performance Comparison report stage runs many clickhouse-local
processes concurrently (GNU parallel in compare.sh, one per query for the
randomization step) inside the job's single cgroup, next to the page cache
from reading the multi-GB datasets and profile TSVs. clickhouse-local
defaults to memory_worker_use_cgroup=1, so each process corrects its own
total-memory tracker up to the cgroup-wide memory.current, which sums every
sibling process plus reclaimable page cache, and trips its hard limit
(Code 241 MEMORY_LIMIT_EXCEEDED in MergeSortingTransform/AggregatingTransform)
even though each query's own allocations are small. This produced the
recurring "Errors while Building the Report" job failure across many
unrelated PRs and on master.

Pass --memory_worker_use_cgroup=0 to every report-building clickhouse-local
invocation so each report query is tracked against its own RSS via
jemalloc/proc instead of the shared cgroup. The clickhouse-client calls to
the measured left/right servers are left untouched. Per-query peak memory is
unchanged, so aggregate memory stays well under the cap and parallel
--memsuspend remains the aggregate backstop.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai
groeneai force-pushed the groeneai/fix-perf-report-cgroup-oom branch from bf6deb8 to 74203e8 Compare June 29, 2026 14:18
@groeneai

Copy link
Copy Markdown
Collaborator Author

Please provide a link to CI report

CI report (this failure first surfaced as a finish-ledger line on PR #108790, Performance Comparison (arm_release, master_head, 3/6), commit 73dbf25):

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108790&sha=73dbf259e4018a51223cf7396f9349fd08b7aefe&name_0=PR&name_1=Performance%20Comparison%20%28arm_release%2C%20master_head%2C%203%2F6%29

The job's report.html shows "Errors while Building the Report" = the Code 241 above; the perf comparison itself is clean (408 queries, 0 not-OK, 0 changed, 0 unstable), so the red is purely the report-build step.

It is chronic and fleet-wide, not specific to one PR: in the last 7 days Performance Comparison (arm_release, master_head, 3/6) failed across 10 distinct unrelated PRs (108790, 66467, 101401, 108067, 108655, 101841, 108345, 107476, 108680, 105066), ~770-820 rows each.

@azat

azat commented Jun 29, 2026

Copy link
Copy Markdown
Member

The link is wrong, the report.html does not have "Errors while Building the Report", and neither does job.log.zst

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jun 29, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [74203e8]

Summary: ✅


AI Review

Summary

This PR disables memory_worker_use_cgroup for report-building clickhouse-local invocations in compare.sh and performance_tests.py. The implementation is narrow and I did not find a code-path issue in the changed calls, but the PR still lacks verifiable evidence for the promised recurring CI fix: the cited historical artifact does not contain the described Code 241 / MEMORY_LIMIT_EXCEEDED report-build failure, and the current PR CI report does not appear to exercise this performance-report path.

Missing context / blind spots
  • ⚠️ The PR discussion cites PR 108790, commit 73dbf259e4018a51223cf7396f9349fd08b7aefe, Performance Comparison (arm_release, master_head, 3/6) as evidence for the report-build OOM, but that report.html shows unstable queries and job.log.zst has no matching Code 241, MEMORY_LIMIT_EXCEEDED, or MergeSortingTransform signature. A CI report/log artifact that actually contains the claimed failure would close this gap.
  • ⚠️ The current PR CI report for 74203e8b33e3809e62a26e6b1c63a32043bb6efe currently shows only 2 passed and 158 skipped checks, so it does not validate the changed performance report-building stage. A successful run of the affected Performance Comparison report job with this patch would close this gap.
Tests
  • ⚠️ Please provide the smallest reproducible evidence for the contract: either the correct failing CI artifact plus a passing run with this change, or local repro output showing concurrent report-building clickhouse-local jobs fail before and complete after adding --memory_worker_use_cgroup=0.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: provide verifiable before/after evidence for the reported CI failure and this fix. I do not have a code-level inline finding from the current diff.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 29, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

You are right, and thanks for checking. That link no longer shows it: the master_head, 3/6 job on 73dbf259e40 was retried and the retry passed, overwriting the S3 artifacts at the same path. CIDB has both groups for that sha+check: a failure group at 2026-06-29 07:24:56 and a later success group at 13:16:11. report.html and job.log.zst you opened are from the passing retry, so the error is gone there.

Also, the Code: 241 line is never in report.html or job.log.zst. For these rows CIDB stores only the generic marker Errors while building the report.; the actual exception is in report/errors.log (mirrored from analyze/errors.log), which is bundled inside logs.tar.zst.

Stable examples still on S3 (failure-only, not retried), PR #105066:

It is fleet-wide: 8 distinct unrelated PRs currently have accessible Code: 241 arm_release perf-report artifacts in the last 7d (101038, 105066, 108017, 108067, 108282, 108402, 108522, 108610). The variant is sometimes AggregatingTransform or BufferedShardingTransform instead of MergeSortingTransform, same cgroup cross-accounting root cause.

@azat azat 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.

Ok for now

@azat
azat enabled auto-merge June 29, 2026 15:31
@azat
azat added this pull request to the merge queue Jun 29, 2026
Merged via the queue into ClickHouse:master with commit 5424917 Jun 29, 2026
174 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 29, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Jul 4, 2026
…ode 243

The report-building step of the Performance Comparison job runs many
clickhouse-local processes (the eqmed.sql randomization step over each query,
plus the aggregate report queries) with --memory_worker_use_cgroup=0. Without
cgroup correction, getMostStrictAvailableSystemMemory() returns the full host
RAM, so max_bytes_ratio_before_external_group_by (default 0.5) sets the
external-aggregation spill threshold to ~0.5 * host RAM (~28 GiB on the
arm-medium runner). The heaviest randomization queries cross that threshold and
try to spill, reserving current_memory_usage bytes on report/tmp. But that disk
is mostly full of the perf datasets and has only ~26 GiB free, so the
reservation fails with

  Code: 243. DB::Exception: Not enough space on temporary disk, cannot reserve
  29846883133 bytes on [_tmp_default: available: 26.57 GiB ...]:
  While executing AggregatingTransform. (NOT_ENOUGH_SPACE)

That single stderr line lands in analyze/errors.log, is copied into
report/errors.log, and report.py turns any non-empty report/errors.log into a
"failure" with message "Errors while building the report." So the whole check
goes red even though every query row succeeded and the perf verdict is
computed. It recurs across many unrelated PRs and on master.

These bookkeeping aggregations need well under 1 GiB of tracked memory (the
failing job finishes with max_memory_usage=500M locally); the ~20 GiB RSS is
jemalloc-retained pages and dataset page cache, not spillable state. The
temp disk cannot hold a multi-GiB spill anyway, so spilling here is a
misfiring safety valve. Pin the external group_by/sort thresholds (both the
absolute and the ratio form) to 0 so these queries stay in RAM and never
reserve temp disk, and add a per-query max_memory_usage cap so a pathological
report query fails fast and in isolation instead of exhausting host RAM under
GNU parallel's concurrency (parallel --memsuspend remains the aggregate
backstop). The measured left/right servers are untouched; this changes only
the post-processing local, so it cannot mask a real regression.

Pass these as ordinary clickhouse-local query settings (BEFORE the --
separator), not after it. clickhouse-local only treats arguments after -- as
config/server overrides (LocalServer::initialize loads them from config()),
which is why --memory_worker_use_cgroup=0 (a server setting) is effective
there. But max_bytes_before_external_* and max_memory_usage are user/query
settings (src/Core/Settings.cpp), so after -- they are parsed into the
application config and silently ignored (system.settings shows changed=0). Passed
as normal options before --, they apply (changed=1) and actually close the
Code 243 path. Split the settings accordingly in both compare.sh (the eqmed
parallel step and the report/analyze/metrics heredoc queries) and the mirrored
lists in performance_tests.py.

Related: ClickHouse#108804
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Jul 4, 2026
…ode 243

The Performance Comparison report-building step runs many clickhouse-local
processes with --memory_worker_use_cgroup=0 (ClickHouse#108804). Without cgroup
correction the external-aggregation spill threshold is ~0.5 * host RAM, so the
heaviest report queries try to spill and reserve multi-GiB on the near-full
report/tmp disk, failing with:

  Code: 243. DB::Exception: Not enough space on temporary disk ... (NOT_ENOUGH_SPACE)

That line lands in errors.log and report.py turns any non-empty errors.log into
a report failure, so the whole check goes red although every query row
succeeded. It recurs across unrelated PRs and on master.

Pin the external group_by/sort thresholds to 0 so these small aggregations stay
in RAM (they need well under 1 GiB; the temp disk cannot hold a real spill
anyway), and add a per-query max_memory_usage cap. Pass them as ordinary
clickhouse-local query settings before the -- separator; after -- only
config/server settings apply (which is why --memory_worker_use_cgroup=0 works
there). The measured servers are untouched, so this cannot mask a regression.

Related: ClickHouse#108804
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Jul 4, 2026
…ode 243

The Performance Comparison report-building step runs many clickhouse-local
processes with --memory_worker_use_cgroup=0 (ClickHouse#108804). Without cgroup
correction the external-aggregation spill threshold is ~0.5 * host RAM, so the
heaviest report queries try to spill and reserve multi-GiB on the near-full
report/tmp disk, failing with:

  Code: 243. DB::Exception: Not enough space on temporary disk ... (NOT_ENOUGH_SPACE)

That line lands in errors.log and report.py turns any non-empty errors.log into
a report failure, so the whole check goes red although every query row
succeeded. It recurs across unrelated PRs and on master.

Pin the external group_by/sort thresholds to 0 so these small aggregations stay
in RAM (they need well under 1 GiB; the temp disk cannot hold a real spill
anyway), and add a per-query max_memory_usage cap. Pass them as ordinary
clickhouse-local query settings before the -- separator; after -- only
config/server settings apply (which is why --memory_worker_use_cgroup=0 works
there). The measured servers are untouched, so this cannot mask a regression.

Related: ClickHouse#108804
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Jul 4, 2026
…ode 243

The Performance Comparison report-building step runs many clickhouse-local
processes with --memory_worker_use_cgroup=0 (ClickHouse#108804). Without cgroup
correction the external-aggregation spill threshold is ~0.5 * host RAM, so the
heaviest randomization queries (eqmed.sql: input cross-joined with
numbers(1,10000) + medianExactForEach state) try to spill and reserve ~28 GiB
on the near-full report/tmp disk, failing with:

  Code: 243. DB::Exception: Not enough space on temporary disk ... (NOT_ENOUGH_SPACE)

That line lands in errors.log and report.py turns any non-empty errors.log into
a report failure, so the whole check goes red although every query row
succeeded. It recurs across unrelated PRs and on master.

The temp disk (~26 GiB free) cannot hold a spill of these queries, so spilling
is not viable here; they must stay in RAM, which the runner has (host ~55 GiB,
concurrency already bounded by parallel --memsuspend). Pin the external
group_by/sort thresholds to 0 so the report aggregations never spill and never
reserve temp disk. Pass them as ordinary clickhouse-local query settings before
the -- separator; after -- only config/server settings apply (which is why
--memory_worker_use_cgroup=0 works there). The measured servers are untouched,
so this cannot mask a regression.

Related: ClickHouse#108804
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Jul 5, 2026
… data)

The report-building clickhouse-local tries external aggregation for the
heaviest eqmed.sql queries and fails with Code: 243 (NOT_ENOUGH_SPACE),
because the near-full report/tmp disk cannot hold the reservation. That line
lands in errors.log and report.py turns any non-empty errors.log into a report
failure, so the whole check goes red although every query row succeeded.

Disable external aggregation so these queries stay in RAM. With spilling off a
single heavy job can peak ~30G, so also bound the parallel report jobs by host
RAM to avoid Code: 241 (MEMORY_LIMIT_EXCEEDED). Also print report/errors.log to
the job log so future failures are diagnosable without the results archive.

The query settings must be passed before the -- separator; after -- only
config/server settings apply (which is why --memory_worker_use_cgroup=0 works
there). The measured servers are untouched, so this cannot mask a regression.

Related: ClickHouse#108804
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…report-cgroup-oom

Fix Performance Comparison report-build host-OOM by disabling cgroup memory correction
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 pr-ci 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.

4 participants