MCPcopy Create free account
hub / github.com/baidu/EasyFaaS / getMemoryCapacity

Method getMemoryCapacity

pkg/funclet/runtime/resource.go:179–205  ·  view source on GitHub ↗
(totalMemory string)

Source from the content-addressed store, hash-verified

177}
178
179func (rc *ResourceControl) getMemoryCapacity(totalMemory string) (mem int64, err error) {
180 // memory capacity
181 // parse the configuration of total memory
182 var memoryQuotaConfiguration uint64
183 if totalMemory != "" {
184 memoryQuotaConfiguration, err = bytefmt.ToBytes(totalMemory)
185 if err != nil {
186 return 0, err
187 }
188 }
189
190 // parse memory limits from the cgroup
191 cgroupMemoryPath, err := rc.cgroupManager.GetCgroupSubsysPath("memory")
192 if err != nil {
193 return 0, err
194 }
195 totalMemoryQuota, err := cgroup.GetCgroupParamUint(cgroupMemoryPath, cgroup.MemoryLimitsFile)
196 if err != nil {
197 return 0, err
198 }
199
200 // the final total memory equals to the configuration of total memory, when memory cgroup had no limits.
201 if totalMemoryQuota == cgroup.MemoryNoLimits && memoryQuotaConfiguration != 0 {
202 totalMemoryQuota = memoryQuotaConfiguration
203 }
204 return int64(totalMemoryQuota), nil
205}
206
207func (rc *ResourceControl) getMilliCPUCapacity(totalCPU float64) (cpu int64, err error) {
208 // cpu capacity

Callers 1

Calls 3

ToBytesFunction · 0.92
GetCgroupParamUintFunction · 0.92
GetCgroupSubsysPathMethod · 0.65

Tested by

no test coverage detected