diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-06-26 15:25:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-26 15:25:19 +0200 |
commit | 58a1777f518657ff12744bb69ccf2dab3d429625 (patch) | |
tree | a2264182e122e0d0cf29c609bb4856ac5beca7c6 /pkg/cgroups/memory.go | |
parent | da1ef2bdfd52e666a2561e0a012cc3a824938e65 (diff) | |
parent | e27fef335a4a0d2666542028986100a2f60b3e18 (diff) | |
download | podman-58a1777f518657ff12744bb69ccf2dab3d429625.tar.gz podman-58a1777f518657ff12744bb69ccf2dab3d429625.tar.bz2 podman-58a1777f518657ff12744bb69ccf2dab3d429625.zip |
Merge pull request #3374 from giuseppe/cgroups
cgroups: add initial support for cgroups v2
Diffstat (limited to 'pkg/cgroups/memory.go')
-rw-r--r-- | pkg/cgroups/memory.go | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/pkg/cgroups/memory.go b/pkg/cgroups/memory.go new file mode 100644 index 000000000..0505eac40 --- /dev/null +++ b/pkg/cgroups/memory.go @@ -0,0 +1,67 @@ +package cgroups + +import ( + "fmt" + "os" + "path/filepath" + + spec "github.com/opencontainers/runtime-spec/specs-go" +) + +type memHandler struct { +} + +func getMemoryHandler() *memHandler { + return &memHandler{} +} + +// Apply set the specified constraints +func (c *memHandler) Apply(ctr *CgroupControl, res *spec.LinuxResources) error { + if res.Memory == nil { + return nil + } + return fmt.Errorf("memory apply not implemented yet") +} + +// Create the cgroup +func (c *memHandler) Create(ctr *CgroupControl) (bool, error) { + if ctr.cgroup2 { + return false, fmt.Errorf("memory create not implemented for cgroup v2") + } + return ctr.createCgroupDirectory(Memory) +} + +// Destroy the cgroup +func (c *memHandler) Destroy(ctr *CgroupControl) error { + return os.Remove(ctr.getCgroupv1Path(Memory)) +} + +// Stat fills a metrics structure with usage stats for the controller +func (c *memHandler) Stat(ctr *CgroupControl, m *Metrics) error { + var err error + usage := MemoryUsage{} + + var memoryRoot string + filenames := map[string]string{} + + if ctr.cgroup2 { + memoryRoot = filepath.Join(cgroupRoot, ctr.path) + filenames["usage"] = "memory.current" + filenames["limit"] = "memory.max" + } else { + memoryRoot = ctr.getCgroupv1Path(Memory) + filenames["usage"] = "memory.usage_in_bytes" + filenames["limit"] = "memory.limit_in_bytes" + } + usage.Usage, err = readFileAsUint64(filepath.Join(memoryRoot, filenames["usage"])) + if err != nil { + return err + } + usage.Limit, err = readFileAsUint64(filepath.Join(memoryRoot, filenames["limit"])) + if err != nil { + return err + } + + m.Memory = MemoryMetrics{Usage: usage} + return nil +} |