Skip to content

Commit e8d0135

Browse files
fix(memlimit): use memory.stat instead of memory.stats (#30)
1 parent b2c01e8 commit e8d0135

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

memlimit/cgroups.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func getMemoryLimitV1(chs []cgroupHierarchy, mis []mountInfo) (uint64, error) {
157157
return 0, err
158158
}
159159

160-
// retrieve the memory limit from the memory.stats and memory.limit_in_bytes files.
160+
// retrieve the memory limit from the memory.stat and memory.limit_in_bytes files.
161161
return readMemoryLimitV1FromPath(cgroupPath)
162162
}
163163

@@ -173,7 +173,7 @@ func getCgroupV1NoLimit() uint64 {
173173
func readMemoryLimitV1FromPath(cgroupPath string) (uint64, error) {
174174
// read hierarchical_memory_limit and memory.limit_in_bytes files.
175175
// but if hierarchical_memory_limit is not available, then use the max value as a fallback.
176-
hml, err := readHierarchicalMemoryLimit(filepath.Join(cgroupPath, "memory.stats"))
176+
hml, err := readHierarchicalMemoryLimit(filepath.Join(cgroupPath, "memory.stat"))
177177
if err != nil && !errors.Is(err, os.ErrNotExist) {
178178
return 0, fmt.Errorf("failed to read hierarchical_memory_limit: %w", err)
179179
} else if hml == 0 {
@@ -202,8 +202,8 @@ func readMemoryLimitV1FromPath(cgroupPath string) (uint64, error) {
202202
return limit, nil
203203
}
204204

205-
// readHierarchicalMemoryLimit extracts hierarchical_memory_limit from memory.stats.
206-
// this function expects the path to be memory.stats file.
205+
// readHierarchicalMemoryLimit extracts hierarchical_memory_limit from memory.stat.
206+
// this function expects the path to be memory.stat file.
207207
func readHierarchicalMemoryLimit(path string) (uint64, error) {
208208
file, err := os.Open(path)
209209
if err != nil {
@@ -217,12 +217,12 @@ func readHierarchicalMemoryLimit(path string) (uint64, error) {
217217

218218
fields := strings.Split(line, " ")
219219
if len(fields) < 2 {
220-
return 0, fmt.Errorf("failed to parse memory.stats %q: not enough fields", line)
220+
return 0, fmt.Errorf("failed to parse memory.stat %q: not enough fields", line)
221221
}
222222

223223
if fields[0] == "hierarchical_memory_limit" {
224224
if len(fields) > 2 {
225-
return 0, fmt.Errorf("failed to parse memory.stats %q: too many fields for hierarchical_memory_limit", line)
225+
return 0, fmt.Errorf("failed to parse memory.stat %q: too many fields for hierarchical_memory_limit", line)
226226
}
227227
return strconv.ParseUint(fields[1], 10, 64)
228228
}

0 commit comments

Comments
 (0)