Skip to content

Cherry pick #83607 to 24.8: Fix incorrect memory around max_untracked_memory - #83666

Merged
robot-ch-test-poll4 merged 3 commits into
backport/24.8/83607from
cherrypick/24.8/83607
Jul 14, 2025
Merged

robot-ch-test-poll4 merged 3 commits into
backport/24.8/83607from
cherrypick/24.8/83607

Conversation

@robot-clickhouse-ci-1

Copy link
Copy Markdown
Contributor

Original pull-request #83607

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.

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

azat added 2 commits July 11, 2025 19:29
The problem is one tiny allocation inside MemoryTracker, due to which we
can call CurrentMemoryTracker recursively, which will lead to double
accounting of `untracked_memory`, after #81694.

But incorrect memory tracking was there even w/o this PR, since w/o it
will ignore inner allocations in `untracked_memory`.

Note, that this is the simplest possible fix for now (that will be easy
to backport), I will do some refactoring and cleanup later.

Basically any accounting of per-thread `untracked_memory` should be done
**before** going into `MemoryTracker`.

Thanks to @filimonov for the provided test - horizontal merges for wide
tables with wide parts (`system.metric_log`) for copule of minute (3-5)
will lead to ~3GiB of memory drift.

v2: proper accounting in case of exception

Fixes: #82036
Fixes: #83352
Fixes: #82627
Fix incorrect memory around max_untracked_memory
@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 pr-bugfix Pull request with bugfix, not backported by default labels Jul 13, 2025
@robot-ch-test-poll4
robot-ch-test-poll4 merged this pull request into backport/24.8/83607 Jul 14, 2025
@robot-ch-test-poll4
robot-ch-test-poll4 deleted the cherrypick/24.8/83607 branch July 14, 2025 14:11
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-bugfix Pull request with bugfix, not backported by default 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