Repository navigation
Conversation
Allow callers that only need CPU and memory metrics to skip other controllers, including blkio and its reads of /proc/partitions. Expose a package-level StatFiltered helper backed by an optional method on the concrete cgroup. This preserves the existing Cgroup interface and Stat behavior while allowing third-party implementations to opt in. Retain the existing error handlers and metrics initialization, and treat an empty filter as full collection, consistent with Add's filtering. Add regression tests for skipped I/O and path resolution, CPU controller selection, error handling and cgroup lifecycle behavior, plus a benchmark using regular-file fixtures. Fixes containerd#370 Assisted-by: OpenAI Codex Signed-off-by: linrunlong <linrunlong@bytedance.com>
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.
cgroup v1 stats collection visits every loaded subsystem, even when a caller only needs CPU and memory metrics. In particular, blkio opens
/proc/partitionson every collection, contributing to the contention reported in #370.Add
cgroup1.StatFiltered(control, subsystems, handlers...)to skip unselected subsystems before path resolution or I/O. It reuses the existing collection and error-handling logic; an empty list preserves full collection. CPU throttling and usage remain separately selectable throughCpuandCpuacct.Keep the
Cgroupinterface and existingStatbehavior compatible. The helper dispatches to an optionalStatFilteredmethod, including on third-party implementations, and reportserrors.ErrUnsupportedwhen unavailable. Existing callers must opt into the new helper to benefit.Tests cover selected metrics, skipped blkio I/O and path lookups, duplicate/inactive names, error handlers, loaded/child/deleted cgroups, and custom implementations. A fixture-based benchmark compares full collection with CPU and memory subsets.
Fixes #370.
Validation on Linux arm64 with Go 1.22.12:
go test -exec sudo -race -coverprofile=/tmp/cgroups-370-coverage.txt -covermode=atomic ./...passed.golangci-lint v2.6.2 run -D errcheckpassed with 0 issues, matching the CI linter configuration.go vet ./...passed on the macOS host.The Linux guest runs cgroup v2; the new v1 tests exercise real controller parsers against regular-file fixtures, without requiring a live v1 mount.
go test ./cgroup1 -run '^$' -bench '^BenchmarkStatFiltered$' -benchmem -count=3(median of three runs, 2 vCPUs):These fixture results show reduced work when controllers are excluded; they do not measure kernel
/proc/partitionscontention or end-to-end CRI performance.AI assistance: implementation, tests, and documentation were developed with OpenAI Codex.