Bump cgroups to c0710c92e8b3a44681d1321dcfd1360fc5

This fixes performance issues with walking `/dev` to get device paths.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2018-02-01 11:43:42 -05:00
parent 7e1d8aafee
commit 5915c9ab5e
3 changed files with 31 additions and 44 deletions

View File

@ -1,7 +1,7 @@
github.com/coreos/go-systemd 48702e0da86bd25e76cfef347e2adeb434a0d0a6 github.com/coreos/go-systemd 48702e0da86bd25e76cfef347e2adeb434a0d0a6
github.com/containerd/go-runc 4f6e87ae043f859a38255247b49c9abc262d002f github.com/containerd/go-runc 4f6e87ae043f859a38255247b49c9abc262d002f
github.com/containerd/console 84eeaae905fa414d03e07bcd6c8d3f19e7cf180e github.com/containerd/console 84eeaae905fa414d03e07bcd6c8d3f19e7cf180e
github.com/containerd/cgroups 29da22c6171a4316169f9205ab6c49f59b5b852f github.com/containerd/cgroups c0710c92e8b3a44681d1321dcfd1360fc5c6c089
github.com/containerd/typeurl f6943554a7e7e88b3c14aad190bf05932da84788 github.com/containerd/typeurl f6943554a7e7e88b3c14aad190bf05932da84788
github.com/docker/go-metrics 4ea375f7759c82740c893fc030bc37088d2ec098 github.com/docker/go-metrics 4ea375f7759c82740c893fc030bc37088d2ec098
github.com/docker/go-events 9461782956ad83b30282bf90e31fa6a70c255ba9 github.com/docker/go-events 9461782956ad83b30282bf90e31fa6a70c255ba9

View File

@ -3,12 +3,12 @@ package cgroups
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"syscall"
specs "github.com/opencontainers/runtime-spec/specs-go" specs "github.com/opencontainers/runtime-spec/specs-go"
) )
@ -105,8 +105,13 @@ func (b *blkioController) Stat(path string, stats *Metrics) error {
}, },
) )
} }
f, err := os.Open("/proc/diskstats")
if err != nil {
return err
}
defer f.Close()
devices, err := getDevices("/dev") devices, err := getDevices(f)
if err != nil { if err != nil {
return err return err
} }
@ -268,50 +273,32 @@ type deviceKey struct {
// getDevices makes a best effort attempt to read all the devices into a map // getDevices makes a best effort attempt to read all the devices into a map
// keyed by major and minor number. Since devices may be mapped multiple times, // keyed by major and minor number. Since devices may be mapped multiple times,
// we err on taking the first occurrence. // we err on taking the first occurrence.
func getDevices(path string) (map[deviceKey]string, error) { func getDevices(r io.Reader) (map[deviceKey]string, error) {
// TODO(stevvooe): We are ignoring lots of errors. It might be kind of
// challenging to debug this if we aren't mapping devices correctly. var (
// Consider logging these errors. s = bufio.NewScanner(r)
devices := map[deviceKey]string{} devices = make(map[deviceKey]string)
if err := filepath.Walk(path, func(p string, fi os.FileInfo, err error) error { )
for s.Scan() {
fields := strings.Fields(s.Text())
major, err := strconv.Atoi(fields[0])
if err != nil { if err != nil {
return err return nil, err
} }
switch { minor, err := strconv.Atoi(fields[1])
case fi.IsDir(): if err != nil {
switch fi.Name() { return nil, err
case "pts", "shm", "fd", "mqueue", ".lxc", ".lxd-mounts":
return filepath.SkipDir
default:
return nil
}
case fi.Name() == "console":
return nil
default:
if fi.Mode()&os.ModeDevice == 0 {
// skip non-devices
return nil
}
st, ok := fi.Sys().(*syscall.Stat_t)
if !ok {
return fmt.Errorf("%s: unable to convert to system stat", p)
}
key := deviceKey{major(st.Rdev), minor(st.Rdev)}
if _, ok := devices[key]; ok {
return nil // skip it if we have already populated the path.
}
devices[key] = p
} }
key := deviceKey{
return nil major: uint64(major),
}); err != nil { minor: uint64(minor),
return nil, err }
if _, ok := devices[key]; ok {
continue
}
devices[key] = filepath.Join("/dev", fields[2])
} }
return devices, s.Err()
return devices, nil
} }
func major(devNumber uint64) uint64 { func major(devNumber uint64) uint64 {

View File

@ -12,7 +12,7 @@ var (
ErrFreezerNotSupported = errors.New("cgroups: freezer cgroup not supported on this system") ErrFreezerNotSupported = errors.New("cgroups: freezer cgroup not supported on this system")
ErrMemoryNotSupported = errors.New("cgroups: memory cgroup not supported on this system") ErrMemoryNotSupported = errors.New("cgroups: memory cgroup not supported on this system")
ErrCgroupDeleted = errors.New("cgroups: cgroup deleted") ErrCgroupDeleted = errors.New("cgroups: cgroup deleted")
ErrNoCgroupMountDestination = errors.New("cgroups: cannot found cgroup mount destination") ErrNoCgroupMountDestination = errors.New("cgroups: cannot find cgroup mount destination")
) )
// ErrorHandler is a function that handles and acts on errors // ErrorHandler is a function that handles and acts on errors