Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile: disable kernel memory accounting on RHEL 7 3.10 kernels #2594

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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 $(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 $(EXTRA_FLAGS) -tags "$(BUILDTAGS) netgo osusergo" \
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,19 @@ sudo make install
with some of them enabled by default (see `BUILDTAGS` in top-level `Makefile`).

To change build tags from the default, set the `BUILDTAGS` variable for make,
e.g.
e.g. to disable `seccomp` and enable `nokmem`, run:

```bash
make BUILDTAGS='seccomp'
make BUILDTAGS="nokmem"
Comment on lines +64 to +67
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should encourage keeping seccomp enabled; should we change to (e.g.);

Suggested change
e.g. to disable `seccomp` and enable `nokmem`, run:
```bash
make BUILDTAGS='seccomp'
make BUILDTAGS="nokmem"
e.g. to disable kernel memory limiting, but keep `seccomp`, run:
```bash
make BUILDTAGS="nokmem seccomp"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't matter much to me, it's just a usage example, not a recommendation about how to compile runc, so can be anything (and I sometimes find myself disabling seccomp so I can compile runc without having to install libseccomp-devel).

But yes, maybe yours is a better/fuller example.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree it's just an example. People love to copy/paste though, and hate to read 😓

```

| Build Tag | Feature | Enabled by default | Dependency |
|-----------|------------------------------------|--------------------|------------|
| seccomp | Syscall filtering | yes | libseccomp |
| nokmem | disable kernel memory accounting | no | <none> |
| nokmem | disable kernel memory accounting | usually not | _none_ |

**Note** `nokmem` build tag is now auto-set by the Makefile in case
the running kernel version looks like one from RHEL7 (3.10.0-\*.el7.)

The following build tags were used earlier, but are now obsoleted:
- **apparmor** (since runc v1.0.0-rc93 the feature is always enabled)
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
3 changes: 3 additions & 0 deletions libcontainer/integration/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,9 @@ func testRunWithKernelMemory(t *testing.T, systemd bool) {
if cgroups.IsCgroup2UnifiedMode() {
t.Skip("cgroup v2 does not support kernel memory limit")
}
if kmemDisabled {
t.Skip("kernel memory is disabled in this runc build")
}

rootfs, err := newRootfs()
ok(t, err)
Expand Down
5 changes: 5 additions & 0 deletions libcontainer/integration/kmem_disabled_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// +build linux,nokmem

package integration

const kmemDisabled = true
5 changes: 5 additions & 0 deletions libcontainer/integration/kmem_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// +build linux,!nokmem

package integration

const kmemDisabled = false
4 changes: 4 additions & 0 deletions tests/integration/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ function requires() {
if [ ! -e "${CGROUP_MEMORY_BASE_PATH}/memory.kmem.limit_in_bytes" ]; then
skip_me=1
fi
if uname -r | grep -q '^3\.10\.0.*\.el7\.'; then
# In RHEL7 kernel, kmem is broken so runc disables it.
skip_me=1
fi
;;
cgroups_rt)
init_cgroup_paths
Expand Down