Skip to content

Commit

Permalink
kubelet/cm: speed up cgroup creation
Browse files Browse the repository at this point in the history
There's no need to call m.Update (which will create another instance of
libcontainer cgroup manager, convert all the resources and then set
them). All this is already done here, except for Set().

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>

pkg/kubelet/cm: rm dup code

Commit ecd6361 added setting PidsLimit to Create and Update.

Commit bce9d5f added setting PidsLimit to m.toResources.

Now, PidsLimit is assigned twice.

Remove the duplicate.

Fixes: bce9d5f
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>

pkg/kubelet/cm: ToSystemd: nit

Remove the second condition as it can't ever be true (this was obviously
written by a C programmer).

Fixes: b230fb8
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>

pkg/kubelet/cm/cgroup_manager: simplify setting hugetlb

Commit 79be8be made hugetlb settings optional if cgroup v2 is used and
hugetlb is not available, fixing issue 92933. Note at that time this was only
needed for v2, because for v1 the resources were set one-by-one, and only for
supported resources.

Commit d312ef7 switched the code to using Set from runc/libcontainer
cgroups manager, and expanded the check to cgroup v1 as well.

Move this check earlier, to inside m.toResources, so instead of
converting all hugetlb resources from ResourceConfig to libcontainers's
Resources.HugetlbLimit, and then setting it to nil, we can skip the
conversion entirely if hugetlb is not supported, thus not doing the work
that is not needed.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>

pkg/kubelet/cm: move common code to libctCgroupConfig

Instead of doing (almost) the same thing from the three different
methods (Create, Update, Destroy), move the functionality to
libctCgroupConfig, replacing updateSystemdCgroupInfo.

The needResources bool is needed because we do not need resources
during Destroy, so we skip the unneeded resource conversion.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>

pkg/kubelet/cm: simplify enforceExistingCgroup

1. Move the rl == nil check to before we dereference it.

2. Remove Exists check before Update, since it is complicated, and
   Update will return a meaningful error anyway in case the cgroup
   does not exist.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>

deps: update runc to 1.1.0

This updates vendored runc/libcontainer to 1.1.0,
and google/cadvisor to a version updated to runc 1.1.0-rc1
(google/cadvisor#3031).

Changes in vendor are generated by (roughly):

	./hack/pin-dependency.sh github.com/google/cadvisor a3b5f4f6c501d5a4ac67530bc973a05c1ebd7d8c
	./hack/pin-dependency.sh github.com/opencontainers/runc v1.1.0
	./hack/update-vendor.sh
	./hack/lint-dependencies.sh # And follow all its recommendations.
	./hack/update-vendor.sh
	./hack/update-internal-modules.sh
	./hack/lint-dependencies.sh # Re-check everything again.

The changes (mostly in pkg/kubelet/cm) are there to adopt changed
runc 1.1 API, and simplify things a bit. In particular:

1. simplify cgroup manager instantiation, using a new, easier way of
   libcontainers/cgroups/manager.New;

2. replace libcontainerAdapter with a boolean variable (all it did
   was passing on whether systemd manager should be used);

3. trivial change due to removed cgroupfs.HugePageSizes and added
    cgroups.HugePageSizes();

4. do not calculate cgroup paths in update / destroy, since libcontainer
   cgroup managers now calculate the paths upon creation (previously,
   they were doing that only in Apply, so using e.g. Set or Destroy right
   after creation was impossible without specifying paths).

We currently still calculate cgroup paths in Exists -- this is to be
addressed separately.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin authored and ehashman committed Feb 10, 2022
1 parent 469c4c4 commit 8b9dc69
Show file tree
Hide file tree
Showing 261 changed files with 6,605 additions and 5,452 deletions.
31 changes: 0 additions & 31 deletions LICENSES/vendor/github.com/bits-and-blooms/bitset/LICENSE

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/kubelet/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ func run(ctx context.Context, s *options.KubeletServer, kubeDeps *kubelet.Depend
}

var cgroupRoots []string
nodeAllocatableRoot := cm.NodeAllocatableRoot(s.CgroupRoot, s.CgroupsPerQOS, s.CgroupDriver)
nodeAllocatableRoot := cm.NodeAllocatableRoot(s.CgroupRoot, s.CgroupsPerQOS, s.CgroupDriver == "systemd")
cgroupRoots = append(cgroupRoots, nodeAllocatableRoot)
kubeletCgroup, err := cm.GetKubeletContainer(s.KubeletCgroups)
if err != nil {
Expand Down
31 changes: 15 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ require (
github.com/fsnotify/fsnotify v1.4.9
github.com/go-logr/logr v1.2.0
github.com/go-ozzo/ozzo-validation v3.5.0+incompatible // indirect
github.com/godbus/dbus/v5 v5.0.4
github.com/godbus/dbus/v5 v5.0.6
github.com/gogo/protobuf v1.3.2
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
github.com/golang/mock v1.5.0
github.com/golang/protobuf v1.5.2
github.com/google/cadvisor v0.43.0
github.com/google/cadvisor v0.43.1-0.20220111033110-a3b5f4f6c501
github.com/google/go-cmp v0.5.5
github.com/google/gofuzz v1.1.0
github.com/google/uuid v1.1.2
Expand All @@ -62,8 +62,8 @@ require (
github.com/mvdan/xurls v1.1.0
github.com/onsi/ginkgo v1.14.0
github.com/onsi/gomega v1.10.1
github.com/opencontainers/runc v1.0.3
github.com/opencontainers/selinux v1.8.2
github.com/opencontainers/runc v1.1.0
github.com/opencontainers/selinux v1.10.0
github.com/pkg/errors v0.9.1
github.com/pmezard/go-difflib v1.0.0
github.com/prometheus/client_golang v1.12.0
Expand Down Expand Up @@ -181,7 +181,6 @@ replace (
github.com/benbjohnson/clock => github.com/benbjohnson/clock v1.1.0
github.com/beorn7/perks => github.com/beorn7/perks v1.0.1
github.com/bgentry/speakeasy => github.com/bgentry/speakeasy v0.1.0
github.com/bits-and-blooms/bitset => github.com/bits-and-blooms/bitset v1.2.0
github.com/bketelsen/crypt => github.com/bketelsen/crypt v0.0.4
github.com/blang/semver => github.com/blang/semver v3.5.1+incompatible
github.com/boltdb/bolt => github.com/boltdb/bolt v1.3.1
Expand All @@ -190,11 +189,11 @@ replace (
github.com/cespare/xxhash => github.com/cespare/xxhash v1.1.0
github.com/cespare/xxhash/v2 => github.com/cespare/xxhash/v2 v2.1.2
github.com/chai2010/gettext-go => github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5
github.com/checkpoint-restore/go-criu/v5 => github.com/checkpoint-restore/go-criu/v5 v5.0.0
github.com/checkpoint-restore/go-criu/v5 => github.com/checkpoint-restore/go-criu/v5 v5.3.0
github.com/chzyer/logex => github.com/chzyer/logex v1.1.10
github.com/chzyer/readline => github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e
github.com/chzyer/test => github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1
github.com/cilium/ebpf => github.com/cilium/ebpf v0.6.2
github.com/cilium/ebpf => github.com/cilium/ebpf v0.7.0
github.com/clusterhq/flocker-go => github.com/clusterhq/flocker-go v0.0.0-20160920122132-2b8b7259d313
github.com/cncf/udpa/go => github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403
github.com/cncf/xds/go => github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed
Expand All @@ -203,8 +202,8 @@ replace (
github.com/cockroachdb/logtags => github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f
github.com/container-storage-interface/spec => github.com/container-storage-interface/spec v1.5.0
github.com/containerd/cgroups => github.com/containerd/cgroups v1.0.1
github.com/containerd/console => github.com/containerd/console v1.0.2
github.com/containerd/containerd => github.com/containerd/containerd v1.4.11
github.com/containerd/console => github.com/containerd/console v1.0.3
github.com/containerd/containerd => github.com/containerd/containerd v1.4.12
github.com/containerd/continuity => github.com/containerd/continuity v0.1.0
github.com/containerd/fifo => github.com/containerd/fifo v1.0.0
github.com/containerd/go-runc => github.com/containerd/go-runc v1.0.0
Expand All @@ -217,7 +216,7 @@ replace (
github.com/coreos/go-systemd/v22 => github.com/coreos/go-systemd/v22 v22.3.2
github.com/cpuguy83/go-md2man/v2 => github.com/cpuguy83/go-md2man/v2 v2.0.0
github.com/creack/pty => github.com/creack/pty v1.1.11
github.com/cyphar/filepath-securejoin => github.com/cyphar/filepath-securejoin v0.2.2
github.com/cyphar/filepath-securejoin => github.com/cyphar/filepath-securejoin v0.2.3
github.com/davecgh/go-spew => github.com/davecgh/go-spew v1.1.1
github.com/daviddengcn/go-colortext => github.com/daviddengcn/go-colortext v0.0.0-20160507010035-511bcaf42ccd
github.com/dnaeon/go-vcr => github.com/dnaeon/go-vcr v1.0.1
Expand Down Expand Up @@ -258,7 +257,7 @@ replace (
github.com/go-openapi/swag => github.com/go-openapi/swag v0.19.14
github.com/go-ozzo/ozzo-validation => github.com/go-ozzo/ozzo-validation v3.5.0+incompatible
github.com/go-stack/stack => github.com/go-stack/stack v1.8.0
github.com/godbus/dbus/v5 => github.com/godbus/dbus/v5 v5.0.4
github.com/godbus/dbus/v5 => github.com/godbus/dbus/v5 v5.0.6
github.com/gofrs/uuid => github.com/gofrs/uuid v4.0.0+incompatible
github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.2
github.com/golang/freetype => github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
Expand All @@ -268,7 +267,7 @@ replace (
github.com/golang/protobuf => github.com/golang/protobuf v1.5.2
github.com/golangplus/testing => github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e
github.com/google/btree => github.com/google/btree v1.0.1
github.com/google/cadvisor => github.com/google/cadvisor v0.43.0
github.com/google/cadvisor => github.com/google/cadvisor v0.43.1-0.20220111033110-a3b5f4f6c501
github.com/google/cel-go => github.com/google/cel-go v0.9.0
github.com/google/cel-spec => github.com/google/cel-spec v0.6.0
github.com/google/go-cmp => github.com/google/go-cmp v0.5.5
Expand Down Expand Up @@ -350,7 +349,7 @@ replace (
github.com/mitchellh/mapstructure => github.com/mitchellh/mapstructure v1.4.1
github.com/moby/ipvs => github.com/moby/ipvs v1.0.1
github.com/moby/spdystream => github.com/moby/spdystream v0.2.0
github.com/moby/sys/mountinfo => github.com/moby/sys/mountinfo v0.4.1
github.com/moby/sys/mountinfo => github.com/moby/sys/mountinfo v0.5.0
github.com/moby/term => github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
github.com/modern-go/concurrent => github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
github.com/modern-go/reflect2 => github.com/modern-go/reflect2 v1.0.2
Expand All @@ -369,9 +368,9 @@ replace (
github.com/onsi/gomega => github.com/onsi/gomega v1.10.1
github.com/opencontainers/go-digest => github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec => github.com/opencontainers/image-spec v1.0.1
github.com/opencontainers/runc => github.com/opencontainers/runc v1.0.3
github.com/opencontainers/runc => github.com/opencontainers/runc v1.1.0
github.com/opencontainers/runtime-spec => github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
github.com/opencontainers/selinux => github.com/opencontainers/selinux v1.8.2
github.com/opencontainers/selinux => github.com/opencontainers/selinux v1.10.0
github.com/opentracing/opentracing-go => github.com/opentracing/opentracing-go v1.1.0
github.com/pascaldekloe/goe => github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c
github.com/pelletier/go-toml => github.com/pelletier/go-toml v1.9.3
Expand All @@ -395,7 +394,7 @@ replace (
github.com/russross/blackfriday/v2 => github.com/russross/blackfriday/v2 v2.0.1
github.com/ryanuber/columnize => github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f
github.com/sean-/seed => github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529
github.com/seccomp/libseccomp-golang => github.com/seccomp/libseccomp-golang v0.9.1
github.com/seccomp/libseccomp-golang => github.com/seccomp/libseccomp-golang v0.9.2-0.20210429002308-3879420cc921
github.com/sergi/go-diff => github.com/sergi/go-diff v1.1.0
github.com/shurcooL/sanitized_anchor_name => github.com/shurcooL/sanitized_anchor_name v1.0.0
github.com/sirupsen/logrus => github.com/sirupsen/logrus v1.8.1
Expand Down
Loading

0 comments on commit 8b9dc69

Please sign in to comment.