Repository navigation
Fix incorrect memory around max_untracked_memory - #83607
Merged
Merged
Conversation
Contributor
|
Workflow [PR], commit [bc66425] Summary: ❌
|
azat
force-pushed
the
memory-untracked_memory-fix
branch
from
July 10, 2025 21:07
09015bc to
20c018a
Compare
This was referenced Jul 10, 2025
azat
force-pushed
the
memory-untracked_memory-fix
branch
from
July 10, 2025 21:55
20c018a to
36f7747
Compare
al13n321
reviewed
Jul 10, 2025
Member
Author
|
azat
force-pushed
the
memory-untracked_memory-fix
branch
from
July 11, 2025 06:39
36f7747 to
8c07726
Compare
azat
force-pushed
the
memory-untracked_memory-fix
branch
from
July 11, 2025 08:28
8c07726 to
6d2c6e6
Compare
This was referenced Jul 11, 2025
azat
force-pushed
the
memory-untracked_memory-fix
branch
from
July 11, 2025 16:38
6d2c6e6 to
5a5aad7
Compare
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 ClickHouse#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: ClickHouse#82036 Fixes: ClickHouse#83352 Fixes: ClickHouse#82627
azat
force-pushed
the
memory-untracked_memory-fix
branch
from
July 11, 2025 17:29
5a5aad7 to
bc66425
Compare
al13n321
approved these changes
Jul 11, 2025
Member
Author
|
azat
enabled auto-merge
July 12, 2025 22:26
Member
Author
|
|
azat
force-pushed
the
memory-untracked_memory-fix
branch
from
July 12, 2025 22:56
3fd3c13 to
bc66425
Compare
azat
enabled auto-merge
July 13, 2025 17:20
This was referenced Jul 13, 2025
robot-clickhouse
added a commit
that referenced
this pull request
Jul 13, 2025
This was referenced Jul 13, 2025
robot-clickhouse
added a commit
that referenced
this pull request
Jul 13, 2025
clickhouse-gh Bot
added a commit
that referenced
this pull request
Jul 13, 2025
Backport #83607 to 25.6: Fix incorrect memory around max_untracked_memory
azat
added a commit
that referenced
this pull request
Jul 14, 2025
Backport #83607 to 25.3: Fix incorrect memory around max_untracked_memory
azat
added a commit
that referenced
this pull request
Jul 14, 2025
Backport #83607 to 25.4: Fix incorrect memory around max_untracked_memory
azat
added a commit
that referenced
this pull request
Jul 14, 2025
Backport #83607 to 25.5: Fix incorrect memory around max_untracked_memory
zvonand
pushed a commit
to Altinity/ClickHouse
that referenced
this pull request
Jul 14, 2025
…-fix Fix incorrect memory around max_untracked_memory
Closed
5 of 13 tasks
robot-clickhouse
added a commit
that referenced
this pull request
Jul 14, 2025
azat
added a commit
that referenced
this pull request
Jul 15, 2025
Backport #83607 to 24.8: Fix incorrect memory around max_untracked_memory
Contributor
This was referenced Aug 2, 2025
Closed
8 of 27 tasks
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix incorrect memory around max_untracked_memory
Changelog category (leave one):
Due to one tiny allocation inside
MemoryTrackerfor logs, recursive allocation fromCurrentMemoryTracker->MemoryTracker->CurrentMemoryTrackeris possible, which will lead to double accounting ofuntracked_memory(this is happens after #81694, before the problem was also there, but it just ignores the inner allocation).Thanks to @filimonov for the provided test - horizontal merges for wide tables with wide parts (
system.metric_log) for a few minute (3-5) will lead to ~3GiB of memory drift.And the rule of thumb is - any accounting of per-thread
untracked_memoryshould be done before going intoMemoryTracker.Note, that this is the simplest possible fix for now (that will be easy to backport), I will do some refactoring and cleanup later.
Fixes: #82036
Fixes: #83352
Fixes: #82627
Refs: