mirror of
https://github.com/containers/podman.git
synced 2025-11-14 01:57:58 +08:00
currently, setting any sort of resource limit in a pod does nothing. With the newly refactored creation process in c/common, podman ca now set resources at a pod level meaning that resource related flags can now be exposed to podman pod create. cgroupfs and systemd are both supported with varying completion. cgroupfs is a much simpler process and one that is virtually complete for all resource types, the flags now just need to be added. systemd on the other hand has to be handeled via the dbus api meaning that the limits need to be passed as recognized properties to systemd. The properties added so far are the ones that podman pod create supports as well as `cpuset-mems` as this will be the next flag I work on. Signed-off-by: Charlie Doern <cdoern@redhat.com>
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
package fs
|
|
|
|
import (
|
|
"math"
|
|
"strconv"
|
|
|
|
"github.com/opencontainers/runc/libcontainer/cgroups"
|
|
"github.com/opencontainers/runc/libcontainer/cgroups/fscommon"
|
|
"github.com/opencontainers/runc/libcontainer/configs"
|
|
)
|
|
|
|
type PidsGroup struct{}
|
|
|
|
func (s *PidsGroup) Name() string {
|
|
return "pids"
|
|
}
|
|
|
|
func (s *PidsGroup) Apply(path string, _ *configs.Resources, pid int) error {
|
|
return apply(path, pid)
|
|
}
|
|
|
|
func (s *PidsGroup) Set(path string, r *configs.Resources) error {
|
|
if r.PidsLimit != 0 {
|
|
// "max" is the fallback value.
|
|
limit := "max"
|
|
|
|
if r.PidsLimit > 0 {
|
|
limit = strconv.FormatInt(r.PidsLimit, 10)
|
|
}
|
|
|
|
if err := cgroups.WriteFile(path, "pids.max", limit); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (s *PidsGroup) GetStats(path string, stats *cgroups.Stats) error {
|
|
if !cgroups.PathExists(path) {
|
|
return nil
|
|
}
|
|
current, err := fscommon.GetCgroupParamUint(path, "pids.current")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
max, err := fscommon.GetCgroupParamUint(path, "pids.max")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// If no limit is set, read from pids.max returns "max", which is
|
|
// converted to MaxUint64 by GetCgroupParamUint. Historically, we
|
|
// represent "no limit" for pids as 0, thus this conversion.
|
|
if max == math.MaxUint64 {
|
|
max = 0
|
|
}
|
|
|
|
stats.PidsStats.Current = current
|
|
stats.PidsStats.Limit = max
|
|
return nil
|
|
}
|