Enhance sysinfo for cgroup memory and disk I/O statistics#1925
Merged
Conversation
- Bump `sysinfo` dependency from 0.32.1 to 0.38.0 - Remove outdated comments about AppArmor container restrictions - No functional logic changes, only version and comment cleanup Signed-off-by: Gaius <gaius.qi@gmail.com>
- Replace `new()` with `nothing()` for all refresh kind constructors to avoid enabling unwanted metrics by default - Add explicit `.with_ram()` to `MemoryRefreshKind` in `get_stats()` to ensure RAM data is actually collected - Update `networks.refresh()` to `networks.refresh(true)` to match updated API signature Signed-off-by: Gaius <gaius.qi@gmail.com>
- `rss` is absent in cgroup v2 `memory.stat`; use `inactive_anon + active_anon` instead - Both metrics exclude page cache, keeping semantics consistent across cgroup versions - Update debug log and returned `CgroupMemoryStats` to use the unified `memory_usage` value Signed-off-by: Gaius <gaius.qi@gmail.com>
- Replace `inactive_anon + active_anon` sum with the `anon` raw counter (NR_ANON_MAPPED) for accurate cgroup v2 memory usage - Fall back to the LRU-based sum only when `anon` key is absent - Improve comment explaining why the LRU approach is inaccurate (shmem/tmpfs inclusion, mlocked/MADV_FREE exclusion) Signed-off-by: Gaius <gaius.qi@gmail.com>
- Add `CgroupDiskStats` struct to track cgroup-level block-device I/O bandwidth - Implement `get_cgroup_stats` measuring read/write bandwidth via cgroup v1 blkio or cgroup v2 io.stat over a sampling interval (Linux only) - Add parsers for both cgroup v1 IoService entries and v2 io.stat format, with unit tests covering both - Expose cgroup disk stats via `CgroupDisk` proto field in announcer when running inside a container - Bump `dragonfly-api` to 2.2.31 for the new `CgroupDisk` type Signed-off-by: Gaius <gaius.qi@gmail.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1925 +/- ##
==========================================
+ Coverage 46.11% 46.13% +0.02%
==========================================
Files 93 93
Lines 23532 23637 +105
==========================================
+ Hits 10851 10906 +55
- Misses 12681 12731 +50
🚀 New features to boost your workflow:
|
- Replace explicit `return` with implicit return expression - Follows Rust idiomatic style for function tail expressions Signed-off-by: Gaius <gaius.qi@gmail.com>
Fixes implicit unit return `()` instead of `Option<CgroupDiskStats>` by removing the erroneous semicolon from the `Some(...)` expression. Signed-off-by: Gaius <gaius.qi@gmail.com>
hhhhsdxxxx
approved these changes
Jul 13, 2026
CormickKneey
approved these changes
Jul 13, 2026
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.
Description
This pull request adds support for reporting cgroup-level disk I/O statistics (read/write bandwidth) on Linux systems, in addition to existing process-level and filesystem-level disk stats. It introduces a new
CgroupDiskStatsstruct and methods for extracting cgroup I/O metrics for both cgroup v1 and v2, and updates the announcer to include these stats when running in a container environment. Additionally, it improves cgroup memory usage reporting to correctly handle cgroup v2.Disk I/O statistics improvements:
CgroupDiskStatsstruct and implemented theDisk::get_cgroup_statsasync method to retrieve cgroup-level disk I/O bandwidth by reading cgroup v1/v2 block device counters on Linux. This includes helper methods for parsing and summing I/O stats from both cgroup versions, with tests. [1] [2]Diskstruct and its methods to clarify the distinction between path-level, process-level, and cgroup-level disk statistics. [1] [2]Announcer integration:
Disk.cgroupfield with cgroup disk stats (using the newCgroupDiskproto message) when running in a container environment. [1] [2] [3]Memory statistics fix:
anonfor cgroup v2,rssfor v1) for resident set size, ensuring accurate memory percent calculation in both cgroup versions.Dependency update:
dragonfly-apidependency version to2.2.31to support the new cgroup disk proto.Related Issue
Motivation and Context
Screenshots (if appropriate)