Skip to content

Cherry pick #126176 to 26.8: Do not correct the global memory tracker below jemalloc stats.allocated - #131849

Merged
robot-clickhouse merged 5 commits into
backport/26.8/126176from
cherrypick/26.8/126176
Nov 18, 2026
Merged

robot-clickhouse merged 5 commits into
backport/26.8/126176from
cherrypick/26.8/126176

Conversation

@robot-clickhouse-ci-1

Copy link
Copy Markdown
Contributor

Original pull-request #126176

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

alexey-milovidov and others added 4 commits October 16, 2026 02:09
Since `memory_worker_correct_memory_tracker` is enabled by default, the memory
worker resets the global memory tracker to RSS. RSS does not include memory that
is allocated but not yet touched, so the concurrent `GROUP BY` queries of
`test_multiple_queries` can allocate more than `max_server_memory_usage`, and the
container is killed by the OOM killer (seen on arm with 64 KiB pages). The test
keeps checking the behavior with the correction disabled.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=85c3bde0916bfd25994ff4636169741f354d5fd9&name_0=MasterCI&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%203%2F4%29

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ted`

The memory worker corrected the tracker to the resident memory, which does not include memory that is
allocated but not touched yet. Concurrent queries were admitted past `max_server_memory_usage`, and in
`test_memory_limit/test.py::test_multiple_queries` the container was killed by the OOM killer instead
of the server throwing `MEMORY_LIMIT_EXCEEDED`.

Correct to the maximum of the resident memory and jemalloc `stats.allocated`. All allocations go
through jemalloc, so phantom drift (tracked bytes without an allocation behind them) is still removed,
while allocated-but-untouched memory stays accounted. Revert the override in the test, which now runs
with the correction enabled.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=85c3bde0916bfd25994ff4636169741f354d5fd9&name_0=MasterCI&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%203%2F4%29
Review: #126176 (review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Do not correct the global memory tracker below jemalloc `stats.allocated`
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request labels Nov 15, 2026
@robot-clickhouse-ci-2

Copy link
Copy Markdown
Contributor

Dear @alexey-milovidov, this cherry-pick PR has not been updated for 3d0h4m28s. Please resolve the conflicts to backport #126176, or close this PR if the backport is no longer needed. This PR will be automatically closed after 7 days of inactivity.

Resolve the conflicts in `MemoryWorker.cpp` and `ServerSettings.cpp`. 26.8 lacks
#118094: `getMemoryUsage` returns a plain
resident value (no `MemoryUsage` struct) and `memory_worker_correct_memory_tracker` is
off by default. The fix is adapted inline: whenever the memory worker corrects the
global memory tracker in a jemalloc build, it uses the maximum of the measured resident
memory and jemalloc `stats.allocated`, refreshing the jemalloc `epoch` when the
measurement came from cgroups. The setting description gets the same note as in the
original PR.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Resolved the conflicts by merging backport/26.8/126176. 26.8 lacks #118094 (no MemoryUsage struct, memory_worker_correct_memory_tracker off by default), so the fix is adapted inline: whenever the memory worker corrects the global memory tracker in a jemalloc build, it uses max(resident, stats.allocated). It refreshes the jemalloc epoch when the measurement came from cgroups. I syntax-checked MemoryWorker.cpp against the 26.8 tree. The change in ServerSettings.cpp only edits a doc string.

@robot-clickhouse
robot-clickhouse merged commit 677c199 into backport/26.8/126176 Nov 18, 2026
2 checks passed
@robot-clickhouse
robot-clickhouse deleted the cherrypick/26.8/126176 branch November 18, 2026 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants