From 910dfcd727371578550edd2d5356f82c6c174228 Mon Sep 17 00:00:00 2001 From: Maksym Pavlenko Date: Mon, 13 Apr 2020 16:07:48 -0700 Subject: [PATCH] Vendor containerd/cgroups 9f1c62dddf4bc7cc72822ebe353bae7006141b1b Backport cgroups fix: https://github.com/containerd/cgroups/pull/147 Signed-off-by: Maksym Pavlenko --- vendor.conf | 2 +- vendor/github.com/containerd/cgroups/blkio.go | 58 ++++++++++++------- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/vendor.conf b/vendor.conf index b1f5b793a4..3288f53b10 100644 --- a/vendor.conf +++ b/vendor.conf @@ -1,7 +1,7 @@ github.com/beorn7/perks 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9 github.com/BurntSushi/toml v0.3.1 github.com/containerd/btrfs af5082808c833de0e79c1e72eea9fea239364877 -github.com/containerd/cgroups c4b9ac5c7601384c965b9646fc515884e091ebb9 +github.com/containerd/cgroups 9f1c62dddf4bc7cc72822ebe353bae7006141b1b github.com/containerd/console v1.0.0 github.com/containerd/continuity f2a389ac0a02ce21c09edd7344677a601970f41c github.com/containerd/fifo bda0ff6ed73c67bfb5e62bc9c697f146b7fd7f13 diff --git a/vendor/github.com/containerd/cgroups/blkio.go b/vendor/github.com/containerd/cgroups/blkio.go index 7c498def65..f0e2a596b3 100644 --- a/vendor/github.com/containerd/cgroups/blkio.go +++ b/vendor/github.com/containerd/cgroups/blkio.go @@ -74,54 +74,47 @@ func (b *blkioController) Update(path string, resources *specs.LinuxResources) e func (b *blkioController) Stat(path string, stats *Metrics) error { stats.Blkio = &BlkIOStat{} - settings := []blkioStatSettings{ - { - name: "throttle.io_serviced", - entry: &stats.Blkio.IoServicedRecursive, - }, - { - name: "throttle.io_service_bytes", - entry: &stats.Blkio.IoServiceBytesRecursive, - }, - } + + var settings []blkioStatSettings + // Try to read CFQ stats available on all CFQ enabled kernels first if _, err := os.Lstat(filepath.Join(b.Path(path), fmt.Sprintf("blkio.io_serviced_recursive"))); err == nil { - settings = []blkioStatSettings{} - settings = append(settings, - blkioStatSettings{ + settings = []blkioStatSettings{ + { name: "sectors_recursive", entry: &stats.Blkio.SectorsRecursive, }, - blkioStatSettings{ + { name: "io_service_bytes_recursive", entry: &stats.Blkio.IoServiceBytesRecursive, }, - blkioStatSettings{ + { name: "io_serviced_recursive", entry: &stats.Blkio.IoServicedRecursive, }, - blkioStatSettings{ + { name: "io_queued_recursive", entry: &stats.Blkio.IoQueuedRecursive, }, - blkioStatSettings{ + { name: "io_service_time_recursive", entry: &stats.Blkio.IoServiceTimeRecursive, }, - blkioStatSettings{ + { name: "io_wait_time_recursive", entry: &stats.Blkio.IoWaitTimeRecursive, }, - blkioStatSettings{ + { name: "io_merged_recursive", entry: &stats.Blkio.IoMergedRecursive, }, - blkioStatSettings{ + { name: "time_recursive", entry: &stats.Blkio.IoTimeRecursive, }, - ) + } } + f, err := os.Open("/proc/diskstats") if err != nil { return err @@ -133,6 +126,29 @@ func (b *blkioController) Stat(path string, stats *Metrics) error { return err } + var size int + for _, t := range settings { + if err := b.readEntry(devices, path, t.name, t.entry); err != nil { + return err + } + size += len(*t.entry) + } + if size > 0 { + return nil + } + + // Even the kernel is compiled with the CFQ scheduler, the cgroup may not use + // block devices with the CFQ scheduler. If so, we should fallback to throttle.* files. + settings = []blkioStatSettings{ + { + name: "throttle.io_serviced", + entry: &stats.Blkio.IoServicedRecursive, + }, + { + name: "throttle.io_service_bytes", + entry: &stats.Blkio.IoServiceBytesRecursive, + }, + } for _, t := range settings { if err := b.readEntry(devices, path, t.name, t.entry); err != nil { return err