Repository navigation
Correct MemoryTracker with MemoryWorker - #75714
Merged
Merged
Conversation
Contributor
Contributor
|
LGTM, but since this is a critical core part of the code I think review of more experienced engineer is also required |
azat
reviewed
Feb 7, 2025
| /// resident memory can be much larger than the actual allocated memory | ||
| /// so we rather ignore the potential difference caused by allocated memory | ||
| /// before MemoryTracker initialization | ||
| if (unlikely(total_memory_tracker.get() < 0) || correct_tracker) |
Member
There was a problem hiding this comment.
I doubt that it makes any difference (updating for the first run or not), but anyway this is minor
azat
approved these changes
Feb 7, 2025
This was referenced Feb 10, 2025
robot-clickhouse
added a commit
that referenced
this pull request
Feb 10, 2025
robot-clickhouse
added a commit
that referenced
this pull request
Feb 10, 2025
robot-clickhouse
added a commit
that referenced
this pull request
Feb 10, 2025
robot-ch-test-poll
added a commit
that referenced
this pull request
Feb 10, 2025
Backport #75714 to 24.11: Correct `MemoryTracker` with `MemoryWorker`
1 task
antonio2368
added a commit
that referenced
this pull request
Feb 13, 2025
Backport #75714 to 25.1: Correct `MemoryTracker` with `MemoryWorker`
antonio2368
added a commit
that referenced
this pull request
Feb 13, 2025
Backport #75714 to 24.12: Correct `MemoryTracker` with `MemoryWorker`
1 task done
pull Bot
pushed a commit
to SINHASantos/ClickHouse
that referenced
this pull request
Sep 28, 2026
`memory_worker_correct_memory_tracker` has been `0` since it was introduced in ClickHouse#75714, which leaves the global `MemoryTracker` a pure counter: `MemoryWorker` refreshes only `rss` on its tick and rewrites `amount` on its first tick and whenever the tracker goes negative. An upward drift is therefore permanent for the lifetime of the process — the memory it describes has already been freed, so no later deallocation can work it off. Once the drift alone exceeds `max_server_memory_usage`, every allocation fails, down to the zero-byte `CurrentMemoryTracker::check` at the start of a connection, and the server rejects every query while using a fraction of its limit. That is not hypothetical: it accounts for 10 of the 21 hung-check failures carrying a memory-limit message in the last 30 days of `default.checks`, and for two open issues. In `Stress test (arm_release)` on master `75247055068ba70941661c930840ee625a991adc` the tracker read `164.75 GiB`, unchanged for the six minutes until the process was killed, while `current RSS` was `7.16 GiB` against a limit of `47.64 GiB`. The measurement the correction uses is the same quantity the hard-limit check already enforces through its `will_be_rss > current_hard_limit` branch, so making `amount` agree with it cannot reject an allocation that is accepted today; it can only stop rejecting allocations that no memory justifies. The drift stays observable: `MemoryTrackingUncorrected` keeps the uncorrected value, so its difference from `MemoryTracking` is the drift accumulated so far.
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 category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Add a config
memory_worker_correct_memory_trackerto enable correction of internal memory tracker with information from different source read in the background thread periodically.Documentation entry for user-facing changes