Merge pull request #7783 from inspektor-gadget/qasim/cri-disable-swap
cri: make swapping disabled with memory limit
This commit is contained in:
@@ -236,6 +236,13 @@ func TestUpdateContainerResources_MemoryLimit(t *testing.T) {
|
||||
pauseImage := images.Get(images.Pause)
|
||||
EnsureImageExists(t, pauseImage)
|
||||
|
||||
expectedSwapLimit := func(memoryLimit int64) *int64 {
|
||||
if cgroups.Mode() == cgroups.Unified {
|
||||
memoryLimit = 0
|
||||
}
|
||||
return &memoryLimit
|
||||
}
|
||||
|
||||
t.Log("Create a container with memory limit")
|
||||
cnConfig := ContainerConfig(
|
||||
"container",
|
||||
@@ -253,6 +260,7 @@ func TestUpdateContainerResources_MemoryLimit(t *testing.T) {
|
||||
spec, err := container.Spec(context.Background())
|
||||
require.NoError(t, err)
|
||||
checkMemoryLimit(t, spec, 200*1024*1024)
|
||||
checkMemorySwapLimit(t, spec, expectedSwapLimit(200*1024*1024))
|
||||
|
||||
t.Log("Update container memory limit after created")
|
||||
err = runtimeService.UpdateContainerResources(cn, &runtime.LinuxContainerResources{
|
||||
@@ -264,6 +272,7 @@ func TestUpdateContainerResources_MemoryLimit(t *testing.T) {
|
||||
spec, err = container.Spec(context.Background())
|
||||
require.NoError(t, err)
|
||||
checkMemoryLimit(t, spec, 400*1024*1024)
|
||||
checkMemorySwapLimit(t, spec, expectedSwapLimit(400*1024*1024))
|
||||
|
||||
t.Log("Start the container")
|
||||
require.NoError(t, runtimeService.StartContainer(cn))
|
||||
@@ -273,6 +282,8 @@ func TestUpdateContainerResources_MemoryLimit(t *testing.T) {
|
||||
t.Log("Check memory limit in cgroup")
|
||||
memLimit := getCgroupMemoryLimitForTask(t, task)
|
||||
assert.Equal(t, uint64(400*1024*1024), memLimit)
|
||||
swapLimit := getCgroupSwapLimitForTask(t, task)
|
||||
assert.Equal(t, uint64(400*1024*1024), swapLimit)
|
||||
|
||||
t.Log("Update container memory limit after started")
|
||||
err = runtimeService.UpdateContainerResources(cn, &runtime.LinuxContainerResources{
|
||||
@@ -284,10 +295,14 @@ func TestUpdateContainerResources_MemoryLimit(t *testing.T) {
|
||||
spec, err = container.Spec(context.Background())
|
||||
require.NoError(t, err)
|
||||
checkMemoryLimit(t, spec, 800*1024*1024)
|
||||
checkMemorySwapLimit(t, spec, expectedSwapLimit(800*1024*1024))
|
||||
|
||||
t.Log("Check memory limit in cgroup")
|
||||
memLimit = getCgroupMemoryLimitForTask(t, task)
|
||||
assert.Equal(t, uint64(800*1024*1024), memLimit)
|
||||
swapLimit = getCgroupSwapLimitForTask(t, task)
|
||||
assert.Equal(t, uint64(800*1024*1024), swapLimit)
|
||||
|
||||
}
|
||||
|
||||
func TestUpdateContainerResources_StatusUpdated(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user