cgroup_linux.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package configs
  2. import (
  3. systemdDbus "github.com/coreos/go-systemd/v22/dbus"
  4. "github.com/opencontainers/runc/libcontainer/devices"
  5. )
  6. type FreezerState string
  7. const (
  8. Undefined FreezerState = ""
  9. Frozen FreezerState = "FROZEN"
  10. Thawed FreezerState = "THAWED"
  11. )
  12. // Cgroup holds properties of a cgroup on Linux.
  13. type Cgroup struct {
  14. // Name specifies the name of the cgroup
  15. Name string `json:"name,omitempty"`
  16. // Parent specifies the name of parent of cgroup or slice
  17. Parent string `json:"parent,omitempty"`
  18. // Path specifies the path to cgroups that are created and/or joined by the container.
  19. // The path is assumed to be relative to the host system cgroup mountpoint.
  20. Path string `json:"path"`
  21. // ScopePrefix describes prefix for the scope name
  22. ScopePrefix string `json:"scope_prefix"`
  23. // Resources contains various cgroups settings to apply
  24. *Resources
  25. // Systemd tells if systemd should be used to manage cgroups.
  26. Systemd bool
  27. // SystemdProps are any additional properties for systemd,
  28. // derived from org.systemd.property.xxx annotations.
  29. // Ignored unless systemd is used for managing cgroups.
  30. SystemdProps []systemdDbus.Property `json:"-"`
  31. // Rootless tells if rootless cgroups should be used.
  32. Rootless bool
  33. // The host UID that should own the cgroup, or nil to accept
  34. // the default ownership. This should only be set when the
  35. // cgroupfs is to be mounted read/write.
  36. // Not all cgroup manager implementations support changing
  37. // the ownership.
  38. OwnerUID *int `json:"owner_uid,omitempty"`
  39. }
  40. type Resources struct {
  41. // Devices is the set of access rules for devices in the container.
  42. Devices []*devices.Rule `json:"devices"`
  43. // Memory limit (in bytes)
  44. Memory int64 `json:"memory"`
  45. // Memory reservation or soft_limit (in bytes)
  46. MemoryReservation int64 `json:"memory_reservation"`
  47. // Total memory usage (memory + swap); set `-1` to enable unlimited swap
  48. MemorySwap int64 `json:"memory_swap"`
  49. // CPU shares (relative weight vs. other containers)
  50. CpuShares uint64 `json:"cpu_shares"`
  51. // CPU hardcap limit (in usecs). Allowed cpu time in a given period.
  52. CpuQuota int64 `json:"cpu_quota"`
  53. // CPU period to be used for hardcapping (in usecs). 0 to use system default.
  54. CpuPeriod uint64 `json:"cpu_period"`
  55. // How many time CPU will use in realtime scheduling (in usecs).
  56. CpuRtRuntime int64 `json:"cpu_rt_quota"`
  57. // CPU period to be used for realtime scheduling (in usecs).
  58. CpuRtPeriod uint64 `json:"cpu_rt_period"`
  59. // CPU to use
  60. CpusetCpus string `json:"cpuset_cpus"`
  61. // MEM to use
  62. CpusetMems string `json:"cpuset_mems"`
  63. // Process limit; set <= `0' to disable limit.
  64. PidsLimit int64 `json:"pids_limit"`
  65. // Specifies per cgroup weight, range is from 10 to 1000.
  66. BlkioWeight uint16 `json:"blkio_weight"`
  67. // Specifies tasks' weight in the given cgroup while competing with the cgroup's child cgroups, range is from 10 to 1000, cfq scheduler only
  68. BlkioLeafWeight uint16 `json:"blkio_leaf_weight"`
  69. // Weight per cgroup per device, can override BlkioWeight.
  70. BlkioWeightDevice []*WeightDevice `json:"blkio_weight_device"`
  71. // IO read rate limit per cgroup per device, bytes per second.
  72. BlkioThrottleReadBpsDevice []*ThrottleDevice `json:"blkio_throttle_read_bps_device"`
  73. // IO write rate limit per cgroup per device, bytes per second.
  74. BlkioThrottleWriteBpsDevice []*ThrottleDevice `json:"blkio_throttle_write_bps_device"`
  75. // IO read rate limit per cgroup per device, IO per second.
  76. BlkioThrottleReadIOPSDevice []*ThrottleDevice `json:"blkio_throttle_read_iops_device"`
  77. // IO write rate limit per cgroup per device, IO per second.
  78. BlkioThrottleWriteIOPSDevice []*ThrottleDevice `json:"blkio_throttle_write_iops_device"`
  79. // set the freeze value for the process
  80. Freezer FreezerState `json:"freezer"`
  81. // Hugetlb limit (in bytes)
  82. HugetlbLimit []*HugepageLimit `json:"hugetlb_limit"`
  83. // Whether to disable OOM Killer
  84. OomKillDisable bool `json:"oom_kill_disable"`
  85. // Tuning swappiness behaviour per cgroup
  86. MemorySwappiness *uint64 `json:"memory_swappiness"`
  87. // Set priority of network traffic for container
  88. NetPrioIfpriomap []*IfPrioMap `json:"net_prio_ifpriomap"`
  89. // Set class identifier for container's network packets
  90. NetClsClassid uint32 `json:"net_cls_classid_u"`
  91. // Rdma resource restriction configuration
  92. Rdma map[string]LinuxRdma `json:"rdma"`
  93. // Used on cgroups v2:
  94. // CpuWeight sets a proportional bandwidth limit.
  95. CpuWeight uint64 `json:"cpu_weight"`
  96. // Unified is cgroupv2-only key-value map.
  97. Unified map[string]string `json:"unified"`
  98. // SkipDevices allows to skip configuring device permissions.
  99. // Used by e.g. kubelet while creating a parent cgroup (kubepods)
  100. // common for many containers, and by runc update.
  101. //
  102. // NOTE it is impossible to start a container which has this flag set.
  103. SkipDevices bool `json:"-"`
  104. // SkipFreezeOnSet is a flag for cgroup manager to skip the cgroup
  105. // freeze when setting resources. Only applicable to systemd legacy
  106. // (i.e. cgroup v1) manager (which uses freeze by default to avoid
  107. // spurious permission errors caused by systemd inability to update
  108. // device rules in a non-disruptive manner).
  109. //
  110. // If not set, a few methods (such as looking into cgroup's
  111. // devices.list and querying the systemd unit properties) are used
  112. // during Set() to figure out whether the freeze is required. Those
  113. // methods may be relatively slow, thus this flag.
  114. SkipFreezeOnSet bool `json:"-"`
  115. }