package fs2 import ( "errors" "path/filepath" "linkfog.com/public/lib/cgroup/fs" "linkfog.com/public/lib/cgroup/fscommon" "linkfog.com/public/lib/l" ) func GetMemoryLimit(cgroupDir string, defaultLimit float64) float64 { contents, err := fscommon.GetCgroupParamString(filepath.Join(cgroupDir, "memory.max")) if err != nil { l.Errorf("read memory.max error:%v, use default value", err) return defaultLimit } if contents == "max" { l.Warn("memory.max is max, use default value") return defaultLimit } memLimit, err := fscommon.ParseUint(contents, 10, 64) if err != nil { l.Errorf("parse memory.max error:%v, contents:%s, use default value", err, contents) return defaultLimit } if memLimit == 0 { l.Warn("memory.max is 0, use default value") return defaultLimit } return float64(memLimit) } func GetMemoryUsage(cgroupDir string) (usage uint64, workingSet uint64, err error) { var stats map[string]uint64 stats, err = fs.ParseMemoryStat(filepath.Join(cgroupDir, "memory.stat")) if err != nil { return } usage, err = fscommon.GetCgroupParamUint(filepath.Join(cgroupDir, "memory.current")) if err != nil { return } workingSet = usage if v, ok := stats["inactive_file"]; ok { if workingSet < v { workingSet = 0 } else { workingSet -= v } } return } func GetKernelMemoryUsage(cgroupDir string) (usage uint64, err error) { return 0, errors.New("cgroup2: get kmem usage not implemented") } func GetKernelMemorySlabInfo(cgroupDir string) (slabInfo fs.SlabInfo, err error) { return fs.SlabInfo{}, errors.New("cgroup2: get kmem slabinfo not implemented") }