Skip to content

Commit 8174a13

Browse files
Make memory_worker_rss_speculative_reserve_ratio default to 0 (opt-in)
CI for #104976 showed that the default ratio of `1.0` causes widespread `MEMORY_LIMIT_EXCEEDED` errors in the ASan + UBSan stateless tests: under those sanitizers the gap `resident - tracked` is dominated by sanitizer shadow memory rather than tracker bookkeeping lag, so doubling the apparent RSS pushes the tracker past `max_server_memory_usage` and stops ordinary, non memory-stress queries. Failing checks (~282 stateless tests in each shard): - https://github.com/ClickHouse/ClickHouse/actions/runs/25880162948/job/76062000101 - https://github.com/ClickHouse/ClickHouse/actions/runs/25880162948/job/76062000097 The mechanism is still useful in OOM-stress scenarios as documented in the PR description, so keep the setting but make it opt-in: change the default from `1.0` to `0.0`. Operators wanting the OOM-survival behaviour set the ratio explicitly (per the PR's own stress harness, e.g. `ratio = 1.0` or `2.0`). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent f451d0c commit 8174a13

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎src/Common/MemoryWorker.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct MemoryWorkerConfig
4141
bool correct_tracker = false;
4242
uint64_t decay_adjustment_period_ms = 0;
4343
bool use_cgroup = true;
44-
double rss_speculative_reserve_ratio = 1.0;
44+
double rss_speculative_reserve_ratio = 0.0;
4545
};
4646

4747
/// Correct MemoryTracker based on external information (e.g. Cgroups or stats.resident from jemalloc)
@@ -90,7 +90,7 @@ class MemoryWorker
9090
double purge_dirty_pages_threshold_ratio;
9191
uint64_t page_size = 0;
9292
std::chrono::milliseconds decay_adjustment_period_ms{0};
93-
double rss_speculative_reserve_ratio = 1.0;
93+
double rss_speculative_reserve_ratio = 0.0;
9494

9595
MemoryUsageSource source{MemoryUsageSource::None};
9696

‎src/Core/ServerSettings.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ The policy on how to perform a scheduling of CPU slots specified by `concurrent_
11711171
Whether background memory worker should correct internal memory tracker based on the information from external sources like jemalloc and cgroups
11721172
)", 0) \
11731173
DECLARE(Bool, memory_worker_use_cgroup, true, "Use current cgroup memory usage information to correct memory tracking.", 0) \
1174-
DECLARE(Double, memory_worker_rss_speculative_reserve_ratio, 1.0, R"(
1174+
DECLARE(Double, memory_worker_rss_speculative_reserve_ratio, 0.0, R"(
11751175
On each `MemoryWorker` tick the difference between the observed RSS and the
11761176
globally-tracked memory (`resident - tracked`) represents allocations that
11771177
happened during the last tick but are not yet reflected in the tracker.
@@ -1180,9 +1180,9 @@ The policy on how to perform a scheduling of CPU slots specified by `concurrent_
11801180
the same amount. The reservation is applied to the `rss` counter that the
11811181
global hard-limit check consults via `MemoryTracker::allocImpl`, so when the
11821182
extrapolated value crosses `max_server_memory_usage`, subsequent allocations
1183-
throw `MEMORY_LIMIT_EXCEEDED` before the kernel OOM-killer fires. A value of
1184-
`0` disables speculation (the previous behaviour); the default `1` reserves
1185-
one full delta of headroom for the next interval.
1183+
throw `MEMORY_LIMIT_EXCEEDED` before the kernel OOM-killer fires. The default
1184+
value `0` disables speculation; setting it to `1` reserves one full delta of
1185+
headroom for the next interval.
11861186
)", 0) \
11871187
DECLARE(Bool, disable_insertion_and_mutation, false, R"(
11881188
Disable insert/alter/delete queries. This setting will be enabled if someone needs read-only nodes to prevent insertion and mutation affect reading performance. Inserts into external engines (S3, DataLake, MySQL, PostrgeSQL, Kafka, etc) are allowed despite this setting.

0 commit comments

Comments
 (0)