package limit import ( "linkfog.com/public/lib/cgroup" "linkfog.com/public/lib/cgroup/fs" "linkfog.com/public/lib/cgroup/fs2" "linkfog.com/public/lib/l" ) var ( DefaultMemLimit = float64(3 * 1024 * 1024 * 1024) ) func GetSelfMemoryLimit(defaultLimit float64) float64 { return GetMemoryLimit(-1, defaultLimit) } func GetMemoryLimit(pid int, defaultLimit float64) float64 { cgroupDir, err := cgroup.GetContainerMemoryCgroupPath(pid) if err != nil { l.Errorf("read self cgroup memory path error:%v, use default value", err) return defaultLimit } if cgroup.IsCgroup2() { return fs2.GetMemoryLimit(cgroupDir, defaultLimit) } else { return fs.GetMemoryLimit(cgroupDir, defaultLimit) } }