Skip to content

Lower max_server_memory_usage_to_ram_ratio to 0.7 on sanitizer stateless runs - #110293

Merged
alexey-milovidov merged 5 commits into
masterfrom
fix-sanitizer-stateless-oom-memory-ratio
Jul 15, 2026
Merged

alexey-milovidov merged 5 commits into
masterfrom
fix-sanitizer-stateless-oom-memory-ratio

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 13, 2026 •

Copy link
Copy Markdown
Member

Fixes recurring runner-wide OOM (Server died / OOM in dmesg) on the heaviest stateless configs (ASan/UBSan, parallel), where the clickhouse-server process is killed by the host OOM killer rather than by a per-query max_memory_usage limit or a per-test bug.

Root cause. On a sanitizer host the server is not the only large memory consumer. The parallel runner keeps dozens of ASan-instrumented clickhouse-client processes alive at once (~0.4 GiB each, ~17 GiB in total on a 60 GiB host). With the default max_server_memory_usage_to_ram_ratio of 0.9 the server alone is allowed to grow to ~0.9 of RAM, so together with the clients it exhausts the host: a global OOM reaps clickhouse-serv at an RSS well below the server's own logical limit, before any query can hit MEMORY_LIMIT_EXCEEDED.

Evidence (master, sha f76b144fcba2, Stateless tests (amd_asan_ubsan, distributed plan, parallel)):

  • Host RAM 59.77 GiB; max_server_memory_usage set to 53.79 GiB (0.9 ratio).
  • Host OOM-killed the server at 42.67 GiB anon-rss (global_oom, constraint=CONSTRAINT_NONE), while ~17 GiB was held by the concurrent ASan clickhouse-client processes (dozens visible in the dmesg process table).
  • ClickHouse's own memory tracker never exceeded ~1.6 GiB during the whole 78-minute run, and every detailed log (query_log, trace_log, metric_log, server log) truncates 4-8 s before the fatal window — the runaway allocation starved logging. So the specific victim query is unattributable, consistent with the external-kill host-OOM class in Runner-wide OOM (OOM in dmesg / Server died) on Stateless test runners, especially arm_asan_ubsan, azure #108689.
  • Retries of the same job on the same sha passed, confirming a memory-pressure flake rather than a deterministic regression.

Fix. The reduced ratio was previously applied only in the flaky check (0.8, sufficient there only because it runs a small test subset at reduced concurrency). Apply it to every sanitizer run and lower it to 0.7 (41.8 GiB cap on this host) so the clients' footprint still fits and the server kills a runaway query gracefully with MEMORY_LIMIT_EXCEEDED instead of being OOM-killed by the host. 0.7 stays comfortably above the largest legitimate single-query need (the ~25 GiB stateful-load INSERT).

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=f76b144fcba22d6bedfb5ea7e5f1822456b549fb&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29

Related: #108689

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):

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

🤖 Generated with Claude Code

Version info

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

…ess runs

Fixes recurring runner-wide OOM ("Server died" / "OOM in dmesg") on the
heaviest stateless configs (ASan/UBSan, parallel), where the server is
killed by the host OOM killer rather than by a per-query `max_memory_usage`
limit.

Root cause: on a sanitizer host the server is not the only large memory
consumer. The parallel runner keeps dozens of ASan-instrumented
`clickhouse-client` processes alive at once (~0.4 GiB each, ~17 GiB total on
a 60 GiB host). With the default `max_server_memory_usage_to_ram_ratio` of
0.9 the server alone is allowed to grow to ~0.9 of RAM, so together with the
clients it exhausts the host: a global OOM reaps `clickhouse-serv` at an RSS
well below the server's own logical limit, before any query can hit
`MEMORY_LIMIT_EXCEEDED`.

Example (master, sha f76b144, "Stateless tests (amd_asan_ubsan,
distributed plan, parallel)"): host 59.77 GiB, `max_server_memory_usage`
53.79 GiB (0.9), but the host OOM-killed the server at 42.67 GiB anon-rss
while ~17 GiB was held by concurrent ASan clients. ClickHouse's own memory
tracker never exceeded ~1.6 GiB during the whole run.

The reduced ratio was previously applied only in the flaky check (0.8, which
is sufficient there only because it runs a small test subset at reduced
concurrency). Apply it to every sanitizer run and lower it to 0.7 (41.8 GiB
cap on this host) so the clients' footprint still fits and the server kills a
runaway query gracefully instead of being OOM-killed by the host. 0.7 stays
comfortably above the largest legitimate single-query need (the ~25 GiB
stateful-load INSERT).

CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=f76b144fcba22d6bedfb5ea7e5f1822456b549fb&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29

Related: #108689

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a27a197]

Summary: ✅


AI Review

Summary

This PR lowers max_server_memory_usage_to_ram_ratio to 0.7 for sanitizer-backed stateless runs and now also covers the BugfixValidation and DBReplicated branches that were missed earlier in the review. The current code paths look correct, but I do not think this should merge without focused regression coverage: both subtle branches already escaped once in this same PR, so the same runner-wide OOM behavior can silently come back on a later refactor.

Tests
  • ⚠️ Add a small ci/tests regression for the selector logic in ci/jobs/functional_tests.py (BugfixValidation must derive the decision from build_types, normal runs from args.options) and for ClickHouseProc.set_memory_ratio with is_db_replicated=True writing max_server_memory_usage_to_ram_ratio.xml into all three config dirs.
Final Verdict
  • Status: ⚠️ Request changes

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 13, 2026
Comment thread ci/jobs/functional_tests.py Resolved
alexey-milovidov and others added 2 commits July 14, 2026 05:46
The previous commit keyed the `max_server_memory_usage_to_ram_ratio`
override off `args.options`, but in `bugfix_validation` mode `args.options`
is only `BugfixValidation` - the sanitizer names never appear there. That
mode downloads and swaps through several master-HEAD build-type binaries
(`build_types`, e.g. `amd_asan_ubsan` / `amd_tsan` / `amd_msan`), most of
them sanitizer builds, on the same memory-constrained runner, so it was
left at the default `0.9` ratio and the same runner-wide OOM could still
kill `clickhouse-server` instead of surfacing `MEMORY_LIMIT_EXCEEDED`.

Key the ratio off the actual `build_types` under test in bugfix-validation
mode so those sanitizer binaries are covered too, making the override apply
to every sanitizer run as the comment claims.

Addresses the AI review finding on
#110293

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread ci/jobs/functional_tests.py Resolved
alexey-milovidov and others added 2 commits July 14, 2026 16:39
The AI review pointed out that `DBReplicated` sanitizer runs still escaped
the reduced `max_server_memory_usage_to_ram_ratio`: `tests/config/install.sh`
clones `/etc/clickhouse-server` into `/etc/clickhouse-server1` and
`/etc/clickhouse-server2` before `set_memory_ratio` runs, and `ClickHouseProc.start`
later launches both extra replicas from those copied configs. So a supported
job like `amd_asan_ubsan,DBReplicated` left two server processes at the default
`0.9` ratio, which can reproduce the same runner-wide host OOM under an even
heavier three-server footprint.

Make `set_memory_ratio` write the override into every replica config dir
(`/etc/clickhouse-server1`, `/etc/clickhouse-server2`) as well as the primary
when `is_db_replicated` is set, so all three servers honor the cap.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread ci/jobs/functional_tests.py Resolved
@alexey-milovidov alexey-milovidov self-assigned this Jul 15, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

LGTM

@alexey-milovidov
alexey-milovidov merged commit 8703368 into master Jul 15, 2026
174 of 175 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-sanitizer-stateless-oom-memory-ratio branch July 15, 2026 01:07
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 15, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

#110293 lowered max_server_memory_usage_to_ram_ratio to 0.7 on sanitizer stateless runs. On Stateless tests (amd_asan_ubsan, distributed plan, parallel) this now trips Code 241 MEMORY_LIMIT_EXCEEDED at the server total cap (maximum: 41.84 GiB) at scale:

  • 07-14: 55 failures, 4 at the memory cap
  • 07-15: 11069 failures, 10407 at the 41.84 GiB cap, across master (629) plus 123 PRs

The failing queries are heavy but legitimate (TPC-DS/TPC-H, 03742_nested_loop_join_long, 04537_aggregation_in_order_serialized_keys, 4061_truncate_many_dedup_blocks). Each reruns clean in isolation (the CI diagnosis reports "not reproducible"), so this is not per-test bloat: it is the parallel config's aggregate concurrent working set exceeding 41.84 GiB, with OvercommitTracker stopping queries. The 0.7 rationale sized for the largest single query (~25 GiB), which does not cover N heavy queries running at once on the parallel shard.

Data: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110534&sha=e581471b0232a942cd1c5b6109f39231edb8da47&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Thanks, reverted.

pull Bot pushed a commit to CrazyForks/ClickHouse that referenced this pull request Jul 18, 2026
…oncurrency

Re-applies the sanitizer `max_server_memory_usage_to_ram_ratio` of 0.7 from
ClickHouse#110293 (reverted in ClickHouse#110572 because it caused a flood of
`MEMORY_LIMIT_EXCEEDED` in the "Stateless tests (amd_asan_ubsan, distributed
plan, parallel)" job on master), and this time also lowers the test concurrency
for that job so the *aggregate* server memory of concurrent queries fits under
the cap.

ClickHouse#110293 lowered the ratio to 0.7 to stop the host OOM killer from reaping the
server ("Server died") on the heaviest sanitizer stateless configs, where
~17 GiB of concurrent ASan `clickhouse-client` processes plus a 0.9-of-RAM
server exceed the 60 GiB host. That reasoning only accounted for the largest
single query (~25 GiB), but in the parallel runner dozens of test queries share
one server, so the server memory tracker sees the aggregate, and
`--distributed-plan` fans each query across local parallel replicas,
multiplying per-query server memory. The aggregate then exceeds the lowered
41.84 GiB cap and the `OvercommitTracker` rejects queries across all
co-scheduled tests (Code 241, `MEMORY_LIMIT_EXCEEDED`), so hundreds of
unrelated tests failed on master with 6-213 failures per run.

Fix:
- Re-apply `set_memory_ratio(0.7)` for every sanitizer stateless run.
- Cut the parallel distributed-plan sanitizer job's concurrency to 0.35 * CPU
  (below the 0.4 that azure already uses for the identical failure mode), so
  the aggregate concurrent RSS stays under the cap. The reduction is gated to
  sanitizer builds, since only they carry the 0.7 cap; the healthy
  non-sanitizer (amd_debug) distributed-plan parallel job is left at the
  default concurrency.
- Raise that job's timeout from 2.5h to 3h so the reduced throughput (the job
  runs ~80 min at 0.6 * CPU) cannot turn a memory-red into a timeout-red.

CI report of the disaster (master, Code 241 flood):
https://play.clickhouse.com/play?user=play&run=1&color_modes=%7B%22ppm%22%3A%22none%22%2C%22test_name%22%3A%22categorical%22%7D&tab=Failed%20checks#U0VMRUNUIGNoZWNrX3N0YXJ0X3RpbWUsIGNoZWNrX25hbWUsIHRlc3RfbmFtZSwgcmVwb3J0X3VybApGUk9NIGNoZWNrcwpXSEVSRSAxCiAgICBBTkQgY2hlY2tfc3RhcnRfdGltZSA+PSBub3coKSAtIElOVEVSVkFMIDI0IEhPVVIKICAgIEFORCAoaGVhZF9yZWYgPSAnbWFzdGVyJyBBTkQgc3RhcnRzV2l0aChoZWFkX3JlcG8sICdDbGlja0hvdXNlLycpKQogICAgQU5EIHRlc3Rfc3RhdHVzICE9ICdTS0lQUEVEJwogICAgQU5EICh0ZXN0X3N0YXR1cyBMSUtFICdGJScgT1IgdGVzdF9zdGF0dXMgTElLRSAnRSUnKQogICAgQU5EIGNoZWNrX3N0YXR1cyAhPSAnc3VjY2VzcycKT1JERVIgQlkgY2hlY2tfc3RhcnRfdGltZSBERVNDLCBjaGVja19uYW1lLCB0ZXN0X25hbWU7

Related: ClickHouse#108689
Related: ClickHouse#110293
Related: ClickHouse#110572

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
huldarchen pushed a commit to huldarchen/ClickHouse that referenced this pull request Sep 3, 2026
The fuzzer jobs give one unbounded container a whole shared runner:
get_run_command passes no --memory, and inside the container only
max_server_memory_usage_to_ram_ratio is set while max_server_memory_usage stays
0, so the server sizes itself from the host (46.33 of 61.78 GiB). On PR ClickHouse#116666
the container reached "current RSS: 57.14 GiB" against "maximum: 46.18 GiB"
while every query was refused with Code 241. That RSS is the container cgroup's
anon, so it charges clickhouse-client and two gdb processes as well, and the
server's own ratio cannot bound it. About 4.6 GiB was left for the runner agent;
it lost communication, the Run step concluded cancelled, and since upload
happens after Run the job published nothing. CI DB has 0 rows for
AST fuzzer (amd_debug, targeted) at that commit, while the twin
old_compatibility arm fuzzed the same two query files against the same diff at
the same commit and passed.

--memory is a kernel bound on the whole container, so the reserve holds whatever
the server, gdb and the client do. The launcher stays outside the container, so
an in-container kill leaves it alive to publish a result. The derived form
follows ci/defs/job_configs.py and adapts to both runner classes; 8 GiB rather
than that file's 2 GiB because the agent lost communication with 4.64 GiB still
available, and the runner's at-rest footprint is already about 2.4 GiB.

max_server_memory_usage_to_ram_ratio is deliberately unchanged and becomes an
inner margin: the container cap is 53.78 GiB and the server ceiling 40.33
instead of 46.33 GiB. Lowering that ratio was tried and reverted before
(ClickHouse#110293, reverted by ClickHouse#110572) for flooding unrelated tests with
MEMORY_LIMIT_EXCEEDED.

Validated locally: the flag binds a container carrying this job's exact flags
including --privileged, and ClickHouse then reports the container size rather
than the host's (8.00, 4.00 and 16.00 GiB as the cap varies, 755.49 GiB with no
flag, and 8.00 down to 3.00 GiB through the cgroups v1 code path); 2 GiB of anon
in a 512 MiB container of this shape is killed by the kernel and succeeds
uncapped; all 10 fuzzer job digests change while 164 other PR jobs do not; and
pytest ci/tests/ has identical pass/fail sets with and without the change.

Related: ClickHouse#111892

Co-Authored-By: Claude Opus 5 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The previous commit keyed the `max_server_memory_usage_to_ram_ratio`
override off `args.options`, but in `bugfix_validation` mode `args.options`
is only `BugfixValidation` - the sanitizer names never appear there. That
mode downloads and swaps through several master-HEAD build-type binaries
(`build_types`, e.g. `amd_asan_ubsan` / `amd_tsan` / `amd_msan`), most of
them sanitizer builds, on the same memory-constrained runner, so it was
left at the default `0.9` ratio and the same runner-wide OOM could still
kill `clickhouse-server` instead of surfacing `MEMORY_LIMIT_EXCEEDED`.

Key the ratio off the actual `build_types` under test in bugfix-validation
mode so those sanitizer binaries are covered too, making the override apply
to every sanitizer run as the comment claims.

Addresses the AI review finding on
ClickHouse#110293

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ateless-oom-memory-ratio

Lower max_server_memory_usage_to_ram_ratio to 0.7 on sanitizer stateless runs
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…oncurrency

Re-applies the sanitizer `max_server_memory_usage_to_ram_ratio` of 0.7 from
ClickHouse#110293 (reverted in ClickHouse#110572 because it caused a flood of
`MEMORY_LIMIT_EXCEEDED` in the "Stateless tests (amd_asan_ubsan, distributed
plan, parallel)" job on master), and this time also lowers the test concurrency
for that job so the *aggregate* server memory of concurrent queries fits under
the cap.

ClickHouse#110293 lowered the ratio to 0.7 to stop the host OOM killer from reaping the
server ("Server died") on the heaviest sanitizer stateless configs, where
~17 GiB of concurrent ASan `clickhouse-client` processes plus a 0.9-of-RAM
server exceed the 60 GiB host. That reasoning only accounted for the largest
single query (~25 GiB), but in the parallel runner dozens of test queries share
one server, so the server memory tracker sees the aggregate, and
`--distributed-plan` fans each query across local parallel replicas,
multiplying per-query server memory. The aggregate then exceeds the lowered
41.84 GiB cap and the `OvercommitTracker` rejects queries across all
co-scheduled tests (Code 241, `MEMORY_LIMIT_EXCEEDED`), so hundreds of
unrelated tests failed on master with 6-213 failures per run.

Fix:
- Re-apply `set_memory_ratio(0.7)` for every sanitizer stateless run.
- Cut the parallel distributed-plan sanitizer job's concurrency to 0.35 * CPU
  (below the 0.4 that azure already uses for the identical failure mode), so
  the aggregate concurrent RSS stays under the cap. The reduction is gated to
  sanitizer builds, since only they carry the 0.7 cap; the healthy
  non-sanitizer (amd_debug) distributed-plan parallel job is left at the
  default concurrency.
- Raise that job's timeout from 2.5h to 3h so the reduced throughput (the job
  runs ~80 min at 0.6 * CPU) cannot turn a memory-red into a timeout-red.

CI report of the disaster (master, Code 241 flood):
https://play.clickhouse.com/play?user=play&run=1&color_modes=%7B%22ppm%22%3A%22none%22%2C%22test_name%22%3A%22categorical%22%7D&tab=Failed%20checks#U0VMRUNUIGNoZWNrX3N0YXJ0X3RpbWUsIGNoZWNrX25hbWUsIHRlc3RfbmFtZSwgcmVwb3J0X3VybApGUk9NIGNoZWNrcwpXSEVSRSAxCiAgICBBTkQgY2hlY2tfc3RhcnRfdGltZSA+PSBub3coKSAtIElOVEVSVkFMIDI0IEhPVVIKICAgIEFORCAoaGVhZF9yZWYgPSAnbWFzdGVyJyBBTkQgc3RhcnRzV2l0aChoZWFkX3JlcG8sICdDbGlja0hvdXNlLycpKQogICAgQU5EIHRlc3Rfc3RhdHVzICE9ICdTS0lQUEVEJwogICAgQU5EICh0ZXN0X3N0YXR1cyBMSUtFICdGJScgT1IgdGVzdF9zdGF0dXMgTElLRSAnRSUnKQogICAgQU5EIGNoZWNrX3N0YXR1cyAhPSAnc3VjY2VzcycKT1JERVIgQlkgY2hlY2tfc3RhcnRfdGltZSBERVNDLCBjaGVja19uYW1lLCB0ZXN0X25hbWU7

Related: ClickHouse#108689
Related: ClickHouse#110293
Related: ClickHouse#110572

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants