Use information from cgroup (if applicable) to adjust memory tracker#83981
Merged
azat merged 1 commit intoClickHouse:masterfrom Jul 19, 2025
Merged
Use information from cgroup (if applicable) to adjust memory tracker#83981azat merged 1 commit intoClickHouse:masterfrom
azat merged 1 commit intoClickHouse:masterfrom
Conversation
Right now `memory_worker_correct_memory_tracker` always uses information from jemalloc to update the `MemoryTracking`, but, this may be not good enough in some cases (i.e. when server requested more memory then it use) and may lead to `MEMORY_LIMIT_EXCEEDED` errors with `MemoryTracking` > `RSS`. So use information from cgroup if applicable, and if not, use information from `jemalloc.allocated`.
Contributor
|
Workflow [PR], commit [80888be] Summary: ❌
|
antonio2368
approved these changes
Jul 18, 2025
Member
Author
|
Merged
via the queue into
ClickHouse:master
with commit Jul 19, 2025
350c75b
118 of 125 checks passed
robot-ch-test-poll
added a commit
that referenced
this pull request
Jul 19, 2025
Cherry pick #83981 to 25.3: Use information from cgroup (if applicable) to adjust memory tracker
robot-clickhouse
added a commit
that referenced
this pull request
Jul 19, 2025
…to adjust memory tracker
robot-ch-test-poll
added a commit
that referenced
this pull request
Jul 19, 2025
Cherry pick #83981 to 25.4: Use information from cgroup (if applicable) to adjust memory tracker
robot-clickhouse
added a commit
that referenced
this pull request
Jul 19, 2025
…to adjust memory tracker
robot-ch-test-poll
added a commit
that referenced
this pull request
Jul 19, 2025
Cherry pick #83981 to 25.5: Use information from cgroup (if applicable) to adjust memory tracker
robot-clickhouse
added a commit
that referenced
this pull request
Jul 19, 2025
…to adjust memory tracker
robot-ch-test-poll
added a commit
that referenced
this pull request
Jul 19, 2025
Cherry pick #83981 to 25.6: Use information from cgroup (if applicable) to adjust memory tracker
robot-clickhouse
added a commit
that referenced
this pull request
Jul 19, 2025
…to adjust memory tracker
robot-ch-test-poll
added a commit
that referenced
this pull request
Jul 19, 2025
Cherry pick #83981 to 25.7: Use information from cgroup (if applicable) to adjust memory tracker
robot-clickhouse
added a commit
that referenced
this pull request
Jul 19, 2025
…to adjust memory tracker
clickhouse-gh bot
added a commit
that referenced
this pull request
Jul 19, 2025
Backport #83981 to 25.7: Use information from cgroup (if applicable) to adjust memory tracker
clickhouse-gh bot
added a commit
that referenced
this pull request
Jul 19, 2025
Backport #83981 to 25.6: Use information from cgroup (if applicable) to adjust memory tracker
azat
added a commit
that referenced
this pull request
Jul 19, 2025
Backport #83981 to 25.5: Use information from cgroup (if applicable) to adjust memory tracker
azat
added a commit
that referenced
this pull request
Jul 19, 2025
Backport #83981 to 25.4: Use information from cgroup (if applicable) to adjust memory tracker
azat
added a commit
that referenced
this pull request
Jul 19, 2025
Backport #83981 to 25.3: Use information from cgroup (if applicable) to adjust memory tracker
azat
added a commit
to azat/ClickHouse
that referenced
this pull request
Mar 27, 2026
The `CgroupsV2Reader` sums `anon + sock + kernel` from `memory.stat` to feed `MemoryTracking`. But `kernel` includes `slab_reclaimable` (dentry/inode cache) — a filesystem metadata cache the kernel drops under memory pressure, functionally equivalent to page cache. On one of instances I can see that it can take significant portion of memory: Process RSS: 8.47 GiB anon: 7.75 GiB kernel: 4.22 GiB (of which slab_reclaimable = 3.85 GiB) MemoryTracking: 11.99 GiB (inflated ~42% vs real RSS) The 3.85 GiB of reclaimable slab was dominated by `ext4_inode_cache` (with 56% usage only). This inflated tracker causes premature `MEMORY_LIMIT_EXCEEDED` errors. Cgroups v1 is not affected — its `rss` field excludes kernel memory. Refs: ClickHouse#82036, ClickHouse#83981
azat
added a commit
to azat/ClickHouse
that referenced
this pull request
Mar 27, 2026
The `CgroupsV2Reader` sums `anon + sock + kernel` from `memory.stat` to feed `MemoryTracking`. But `kernel` includes `slab_reclaimable` (dentry/inode cache) — a filesystem metadata cache the kernel drops under memory pressure, functionally equivalent to page cache. On one of instances I can see that it can take significant portion of memory: Process RSS: 8.47 GiB anon: 7.75 GiB kernel: 4.22 GiB (of which slab_reclaimable = 3.85 GiB) MemoryTracking: 11.99 GiB (inflated ~42% vs real RSS) The 3.85 GiB of reclaimable slab was dominated by `ext4_inode_cache` (with 56% usage only). This inflated tracker causes premature `MEMORY_LIMIT_EXCEEDED` errors. Cgroups v1 is not affected — its `rss` field excludes kernel memory. Refs: ClickHouse#82036, ClickHouse#83981
1 task
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.
Note, even though it is marked as improvement it can be considered as bug fix
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Use information from cgroup (if applicable, i.e.
memory_worker_use_cgroupand cgroups are available) to adjust memory tracker (memory_worker_correct_memory_tracker)Right now
memory_worker_correct_memory_trackeralways uses information from jemalloc to update theMemoryTracking, but, this may be not good enough in some cases (i.e. when server requested more memory then it use) and may lead toMEMORY_LIMIT_EXCEEDEDerrors withMemoryTracking>RSS.So use information from cgroup if applicable, and if not, use information from
jemalloc.allocated.Refs: #82036