Container Memory Support - #1
Open
luochenglcs wants to merge 7 commits into
Open
Conversation
Added a stype field to the struct meminfo_info to explicitly store the source type of meminfo data. Additionally, extracted the meminfo buffer reading logic into a dedicated procps_meminfo_read_buf. Signed-off-by: Chunsheng Luo <luffyluo@tencent.com>
Introduces comprehensive cgroup memory information support, enabling the library to read memory limits, usage, swap, and cache statistics from cgroup v1 and v2 hierarchies. The implementation includes automatic cgroup version detection, path traversal to locate the memory controller, and parsing of memory statistics including active/inactive memory, slab information, and swap usage. The module provides a unified interface to access container memory metrics while maintaining compatibility with traditional /proc/meminfo format。 Signed-off-by: Chunsheng Luo <luffyluo@tencent.com>
Introduces cgroup-aware memory information to the meminfo, enabling applications to read memory statistics from cgroup controllers instead of the traditional /proc/meminfo. This enhancement allows applications to access accurate memory limits and usage that reflect container constraints rather than host-wide system resources. The implementation adds a new CGROUP_MEMINFO_TYPE source type that leverages the existing cgmeminfo module to provide container-aware memory reporting. Changes: - adding the cgroup_meminfo_new() public API function Signed-off-by: Chunsheng Luo <luffyluo@tencent.com>
Introduces container-aware memory reporting to the free command by adding a new --container option. When specified, the command uses cgroup_meminfo_new() instead of procps_meminfo_new() to retrieve memory information from cgroup controllers rather than /proc/meminfo. This enhancement allows users to view memory statistics that reflect container limits and usage in containerized environments, providing more accurate resource information for applications running within containers. Signed-off-by: Chunsheng Luo <luffyluo@tencent.com>
Introduces container-aware memory reporting to the vmstat command by adding a new --container (-C) option. When specified, the command uses cgroup_meminfo_new() instead of procps_meminfo_new() to retrieve memory information from cgroup controllers rather than /proc/meminfo. This enhancement enables vmstat to display memory statistics that reflect container limits and usage in containerized environments, providing more accurate resource information for vmstat memory output. Signed-off-by: Chunsheng Luo <luffyluo@tencent.com>
Introduces detailed documentation for the new container memory support feature in procps project. The documentation covers the implementation of cgroup-aware memory reporting for free and vmstat commands, enabling accurate resource information display within containerized environments. Signed-off-by: Chunsheng Luo <luffyluo@tencent.com>
Test suite for cgmeminfo module: - Basic tests: Cgroup memory info creation, cleanup - Parsing tests: cgroup v1/v2 memory statistics parsing Signed-off-by: Chunsheng Luo <luffyluo@tencent.com>
luochenglcs
force-pushed
the
master
branch
2 times, most recently
from
April 29, 2026 02:59
d5d6ed4 to
f5525c9
Compare
github-actions
Bot
force-pushed
the
master
branch
from
April 29, 2026 03:00
f5525c9 to
1dff30b
Compare
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.
Currently, containers do not have isolated resource views. As a result, commands such as free, vmstat executed within a container reflect the host's global memory state rather than the container's actual constrained resources. This behavior is inherently misleading—especially when memory limits are imposed on the container, since the output does not represent the resources truly available to it.
To resolve this discrepancy, we now extract memory usage data directly from the container's corresponding cgroup. This enhancement enables free, vmstat to report container-specific memory information. When run inside a container, these commands can utilize dedicated parameters to display memory usage based on cgroup limits, providing an accurate view of the container's resource context instead of inheriting the host's memory statistics.
https://gitlab.com/procps-ng/procps/-/issues/389