Skip to content

Commit

Permalink
Makefile: disable kernel memory accounting on RHEL 7 3.10 kernels
Browse files Browse the repository at this point in the history
Kernel-memory accounting is known to be broken on RHEL 7 kernels.
This patch automatically disables kernel-memory accounting when
building on a 3.10 kernel.

The original behavior is preserved if a custom BUILDTAGS is passed;

    make BUILDTAGS='seccomp selinux' ...

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
thaJeztah authored and kolyshkin committed Mar 4, 2021
1 parent 3113c63 commit 0b2de07
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ ifeq ($(shell $(GO) env GOOS),linux)
endif
endif
endif

# Disable kmem if building on RHEL7 (kernel 3.10.0 el7)
ifneq ($(shell uname -r | grep '^3\.10\.0.*\.el7\.'),)
BUILDTAGS += nokmem
endif

GO_BUILD := $(GO) build -trimpath $(MOD_VENDOR) $(GO_BUILDMODE) $(EXTRA_FLAGS) -tags "$(BUILDTAGS)" \
-ldflags "-X main.gitCommit=$(COMMIT) -X main.version=$(VERSION) $(EXTRA_LDFLAGS)"
GO_BUILD_STATIC := CGO_ENABLED=1 $(GO) build -trimpath $(MOD_VENDOR) $(EXTRA_FLAGS) -tags "$(BUILDTAGS) netgo osusergo" \
Expand Down
5 changes: 4 additions & 1 deletion libcontainer/cgroups/fs/kmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import (
"golang.org/x/sys/unix"
)

const cgroupKernelMemoryLimit = "memory.kmem.limit_in_bytes"
const (
kmemDisabled = false
cgroupKernelMemoryLimit = "memory.kmem.limit_in_bytes"
)

func EnableKernelMemoryAccounting(path string) error {
// Ensure that kernel memory is available in this kernel build. If it
Expand Down
2 changes: 2 additions & 0 deletions libcontainer/cgroups/fs/kmem_disabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"errors"
)

const kmemDisabled = true

func EnableKernelMemoryAccounting(path string) error {
return nil
}
Expand Down
6 changes: 6 additions & 0 deletions libcontainer/cgroups/fs/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ func TestMemorySetSwapSmallerThanMemory(t *testing.T) {
}

func TestMemorySetKernelMemory(t *testing.T) {
if kmemDisabled {
t.Skip("kernel memory limits are disabled")
}
helper := NewCgroupTestUtil("memory", t)
defer helper.cleanup()

Expand Down Expand Up @@ -219,6 +222,9 @@ func TestMemorySetKernelMemory(t *testing.T) {
}

func TestMemorySetKernelMemoryTCP(t *testing.T) {
if kmemDisabled {
t.Skip("kernel memory limits are disabled")
}
helper := NewCgroupTestUtil("memory", t)
defer helper.cleanup()

Expand Down

0 comments on commit 0b2de07

Please sign in to comment.