Skip to content

Enhance sysinfo for cgroup memory and disk I/O statistics#1925

Merged
gaius-qi merged 9 commits into
mainfrom
feature/cgroup
Jul 13, 2026
Merged

Enhance sysinfo for cgroup memory and disk I/O statistics#1925
gaius-qi merged 9 commits into
mainfrom
feature/cgroup

Conversation

@gaius-qi

Copy link
Copy Markdown
Member

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 CgroupDiskStats struct 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:

  • Added the CgroupDiskStats struct and implemented the Disk::get_cgroup_stats async 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]
  • Updated the documentation for the Disk struct and its methods to clarify the distinction between path-level, process-level, and cgroup-level disk statistics. [1] [2]

Announcer integration:

  • Updated the announcer to populate the Disk.cgroup field with cgroup disk stats (using the new CgroupDisk proto message) when running in a container environment. [1] [2] [3]

Memory statistics fix:

  • Improved cgroup memory usage reporting to use the correct field (anon for cgroup v2, rss for v1) for resident set size, ensuring accurate memory percent calculation in both cgroup versions.

Dependency update:

  • Bumped the dragonfly-api dependency version to 2.2.31 to support the new cgroup disk proto.

Related Issue

Motivation and Context

Screenshots (if appropriate)

Copilot AI and others added 7 commits July 13, 2026 05:53
- 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>
@gaius-qi gaius-qi added this to the v2.6.0 milestone Jul 13, 2026
@gaius-qi gaius-qi self-assigned this Jul 13, 2026
@gaius-qi gaius-qi requested review from a team as code owners July 13, 2026 12:57
@gaius-qi gaius-qi added the enhancement New feature or request label Jul 13, 2026
@gaius-qi gaius-qi requested review from Zephyrcf and hhhhsdxxxx July 13, 2026 12:57
@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 45.87156% with 59 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.13%. Comparing base (d5a5199) to head (adc23a2).

Files with missing lines Patch % Lines
dragonfly-client-util/src/sysinfo/disk.rs 50.00% 50 Missing ⚠️
dragonfly-client-util/src/sysinfo/memory.rs 0.00% 6 Missing ⚠️
dragonfly-client/src/announcer/mod.rs 0.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Files with missing lines Coverage Δ
dragonfly-client/src/announcer/mod.rs 0.00% <0.00%> (ø)
dragonfly-client-util/src/sysinfo/memory.rs 24.56% <0.00%> (-0.90%) ⬇️
dragonfly-client-util/src/sysinfo/disk.rs 35.46% <50.00%> (+35.46%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

gaius-qi added 2 commits July 13, 2026 21:13
- 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>
@gaius-qi gaius-qi enabled auto-merge (squash) July 13, 2026 13:20
@gaius-qi gaius-qi merged commit 211ad93 into main Jul 13, 2026
7 checks passed
@gaius-qi gaius-qi deleted the feature/cgroup branch July 13, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants