diff --git a/internal/cgroups/cgroup.go b/internal/cgroups/cgroup.go index bceb68b9e3b..95f4f7cbf7a 100644 --- a/internal/cgroups/cgroup.go +++ b/internal/cgroups/cgroup.go @@ -86,10 +86,10 @@ func (cg *CGroup) readFirstLine(param string) (string, error) { } // readInt parses the first line from a cgroup param file as int. -func (cg *CGroup) readInt(param string) (int, error) { +func (cg *CGroup) readInt(param string) (int64, error) { text, err := cg.readFirstLine(param) if err != nil { return 0, err } - return strconv.Atoi(text) + return strconv.ParseInt(text, 10, 64) } diff --git a/internal/cgroups/cgroup_test.go b/internal/cgroups/cgroup_test.go index 96530f18ada..8a4b9b844c7 100644 --- a/internal/cgroups/cgroup_test.go +++ b/internal/cgroups/cgroup_test.go @@ -98,7 +98,7 @@ func TestCGroupReadInt(t *testing.T) { testTable := []struct { name string paramName string - expectedValue int + expectedValue int64 shouldHaveError bool }{ { diff --git a/internal/cgroups/cgroups.go b/internal/cgroups/cgroups.go index f6bf71afe18..ed9e46104ae 100644 --- a/internal/cgroups/cgroups.go +++ b/internal/cgroups/cgroups.go @@ -135,7 +135,7 @@ func (cg CGroups) MemoryQuota() (int64, bool, error) { if defined := memLimitBytes > 0; err != nil || !defined { return -1, defined, err } - return int64(memLimitBytes), true, nil + return memLimitBytes, true, nil } // IsCGroupV2 returns true if the system supports and uses cgroup2. diff --git a/internal/cgroups/cgroups_test.go b/internal/cgroups/cgroups_test.go index d809c7098b2..a8d3d838a1a 100644 --- a/internal/cgroups/cgroups_test.go +++ b/internal/cgroups/cgroups_test.go @@ -99,7 +99,7 @@ func TestNewCGroupsWithErrors(t *testing.T) { } } -func TestCGroupsCPUQuota(t *testing.T) { +func TestCGroupsMemoryQuota(t *testing.T) { testTable := []struct { name string expectedQuota int64 @@ -110,6 +110,12 @@ func TestCGroupsCPUQuota(t *testing.T) { name: "undefined", expectedQuota: int64(-1.0), expectedDefined: false, + shouldHaveError: true, + }, + { + name: "memory", + expectedQuota: int64(8796093018112), + expectedDefined: true, shouldHaveError: false, }, } @@ -123,7 +129,7 @@ func TestCGroupsCPUQuota(t *testing.T) { for _, tt := range testTable { cgroupPath := filepath.Join(testDataCGroupsPath, tt.name) - cgroups[_cgroupSubsysCPU] = NewCGroup(cgroupPath) + cgroups[_cgroupSubsysMemory] = NewCGroup(cgroupPath) quota, defined, err := cgroups.MemoryQuota() assert.Equal(t, tt.expectedQuota, quota, tt.name) diff --git a/internal/cgroups/testdata/cgroups/memory/memory.limit_in_bytes b/internal/cgroups/testdata/cgroups/memory/memory.limit_in_bytes new file mode 100644 index 00000000000..83a3919f681 --- /dev/null +++ b/internal/cgroups/testdata/cgroups/memory/memory.limit_in_bytes @@ -0,0 +1 @@ +8796093018112