-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Add memory.kernelTCP support for linux #37043
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
10BC0
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -329,6 +329,7 @@ type Resources struct { | |
DeviceCgroupRules []string // List of rule to be added to the device cgroup | ||
DiskQuota int64 // Disk limit (in bytes) | ||
KernelMemory int64 // Kernel memory limit (in bytes) | ||
KernelMemoryTCP int64 // Sets hard limit for kernel TCP buffer memory | ||
|
||
MemoryReservation int64 // Memory soft limit (in bytes) | ||
MemorySwap int64 // Total memory usage (memory + swap); set `-1` to enable unlimited swap | ||
MemorySwappiness *int64 // Tuning container memory swappiness behaviour | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,10 @@ func getMemoryResources(config containertypes.Resources) *specs.LinuxMemory { | |
memory.Kernel = &config.KernelMemory | ||
} | ||
|
||
if config.KernelMemoryTCP != 0 { | ||
|
||
memory.KernelTCP = &config.KernelMemoryTCP | ||
} | ||
|
||
return &memory | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package container // import "github.com/docker/docker/integration/container" | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
containertypes "github.com/docker/docker/api/types/container" | ||
"github.com/docker/docker/api/types/versions" | ||
"github.com/docker/docker/integration/internal/container" | ||
"github.com/docker/docker/internal/test/request" | ||
"gotest.tools/assert" | ||
is "gotest.tools/assert/cmp" | ||
"gotest.tools/poll" | ||
"gotest.tools/skip" | ||
) | ||
|
||
func TestKernelTCPMemory(t *testing.T) { | ||
skip.If(t, testEnv.DaemonInfo.OSType != "linux") | ||
|
||
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.40"), "skip test from new feature") | ||
skip.If(t, !testEnv.DaemonInfo.KernelMemoryTCP) | ||
|
||
defer setupTest(t)() | ||
client := request.NewAPIClient(t) | ||
ctx := context.Background() | ||
|
||
const ( | ||
kernelMemoryTCP int64 = 200 * 1024 * 1024 | ||
) | ||
|
||
cID := container.Run(t, ctx, client, func(c *container.TestContainerConfig) { | ||
c.HostConfig.Resources = containertypes.Resources{ | ||
KernelMemoryTCP: kernelMemoryTCP, | ||
} | ||
}) | ||
|
||
poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond)) | ||
|
||
inspect, err := client.ContainerInspect(ctx, cID) | ||
assert.NilError(t, err) | ||
assert.Check(t, is.Equal(kernelMemoryTCP, inspect.HostConfig.KernelMemoryTCP)) | ||
|
||
res, err := container.Exec(ctx, client, cID, | ||
[]string{"cat", "/sys/fs/cgroup/memory/memory.kmem.tcp.limit_in_bytes"}) | ||
assert.NilError(t, err) | ||
assert.Assert(t, is.Len(res.Stderr(), 0)) | ||
assert.Equal(t, 0, res.ExitCode) | ||
assert.Check(t, is.Equal(strconv.FormatInt(kernelMemoryTCP, 10), strings.TrimSpace(res.Stdout()))) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
" in bytes" ?