cgroups.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package cgroups
  2. import (
  3. "fmt"
  4. "github.com/docker/libcontainer/devices"
  5. )
  6. type FreezerState string
  7. const (
  8. Undefined FreezerState = ""
  9. Frozen FreezerState = "FROZEN"
  10. Thawed FreezerState = "THAWED"
  11. )
  12. type NotFoundError struct {
  13. Subsystem string
  14. }
  15. func (e *NotFoundError) Error() string {
  16. return fmt.Sprintf("mountpoint for %s not found", e.Subsystem)
  17. }
  18. func NewNotFoundError(sub string) error {
  19. return &NotFoundError{
  20. Subsystem: sub,
  21. }
  22. }
  23. func IsNotFound(err error) bool {
  24. if err == nil {
  25. return false
  26. }
  27. _, ok := err.(*NotFoundError)
  28. return ok
  29. }
  30. type Cgroup struct {
  31. Name string `json:"name,omitempty"`
  32. Parent string `json:"parent,omitempty"` // name of parent cgroup or slice
  33. AllowAllDevices bool `json:"allow_all_devices,omitempty"` // If this is true allow access to any kind of device within the container. If false, allow access only to devices explicitly listed in the allowed_devices list.
  34. AllowedDevices []*devices.Device `json:"allowed_devices,omitempty"`
  35. Memory int64 `json:"memory,omitempty"` // Memory limit (in bytes)
  36. MemoryReservation int64 `json:"memory_reservation,omitempty"` // Memory reservation or soft_limit (in bytes)
  37. MemorySwap int64 `json:"memory_swap,omitempty"` // Total memory usage (memory + swap); set `-1' to disable swap
  38. CpuShares int64 `json:"cpu_shares,omitempty"` // CPU shares (relative weight vs. other containers)
  39. CpuQuota int64 `json:"cpu_quota,omitempty"` // CPU hardcap limit (in usecs). Allowed cpu time in a given period.
  40. CpuPeriod int64 `json:"cpu_period,omitempty"` // CPU period to be used for hardcapping (in usecs). 0 to use system default.
  41. CpusetCpus string `json:"cpuset_cpus,omitempty"` // CPU to use
  42. Freezer FreezerState `json:"freezer,omitempty"` // set the freeze value for the process
  43. Slice string `json:"slice,omitempty"` // Parent slice to use for systemd
  44. }