mirror of
https://github.com/criyle/go-sandbox.git
synced 2025-11-04 14:49:53 +08:00
cgroup: add pids.peak for cgroup v2 kernel >= 6.1
This commit is contained in:
parent
4154f44d83
commit
0b6b557947
@ -183,8 +183,9 @@ type Environment interface {
|
|||||||
|
|
||||||
## Kernel Versions
|
## Kernel Versions
|
||||||
|
|
||||||
|
- 6.1: `pids.peak` in cgroup v2
|
||||||
- 5.19: `memory.peak` in cgroup v2
|
- 5.19: `memory.peak` in cgroup v2
|
||||||
- 4.15: cgroup v2
|
- 4.15: cgroup v2 (also need support in the Linux distribution)
|
||||||
- 4.14: SECCOMP_RET_KILL_PROCESS
|
- 4.14: SECCOMP_RET_KILL_PROCESS
|
||||||
- 4.6: CLONE_NEWCGROUP
|
- 4.6: CLONE_NEWCGROUP
|
||||||
- 3.19: execveat()
|
- 3.19: execveat()
|
||||||
|
|||||||
@ -417,7 +417,11 @@ func start() (*runner.Result, error) {
|
|||||||
if err != nil && !errors.Is(err, os.ErrNotExist) {
|
if err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||||
return nil, fmt.Errorf("cgroup memory: %v", err)
|
return nil, fmt.Errorf("cgroup memory: %v", err)
|
||||||
}
|
}
|
||||||
debug("cgroup: cpu: ", cpu, " memory: ", memory)
|
procPeak, err := cg.ProcessPeak()
|
||||||
|
if err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||||
|
return nil, fmt.Errorf("cgroup pid: %v", err)
|
||||||
|
}
|
||||||
|
debug("cgroup: cpu: ", cpu, " memory: ", memory, " procPeak: ", procPeak)
|
||||||
rt.Time = time.Duration(cpu)
|
rt.Time = time.Duration(cpu)
|
||||||
if memory > 0 {
|
if memory > 0 {
|
||||||
rt.Memory = runner.Size(memory)
|
rt.Memory = runner.Size(memory)
|
||||||
|
|||||||
@ -33,6 +33,9 @@ type Cgroup interface {
|
|||||||
// MemoryMaxUsageInBytes reads max total memory usage. Not exist in cgroup v2 with kernel version < 5.19
|
// MemoryMaxUsageInBytes reads max total memory usage. Not exist in cgroup v2 with kernel version < 5.19
|
||||||
MemoryMaxUsage() (uint64, error)
|
MemoryMaxUsage() (uint64, error)
|
||||||
|
|
||||||
|
// ProcessPeak reads maximum number of process ever existed in cgroup. Not exist in cgroup v1 or kernel < 6.1
|
||||||
|
ProcessPeak() (uint64, error)
|
||||||
|
|
||||||
// SetCPUBandwidth sets the cpu bandwidth. Times in ns
|
// SetCPUBandwidth sets the cpu bandwidth. Times in ns
|
||||||
SetCPUBandwidth(quota, period uint64) error
|
SetCPUBandwidth(quota, period uint64) error
|
||||||
|
|
||||||
|
|||||||
@ -181,6 +181,11 @@ func (c *V1) MemoryMaxUsage() (uint64, error) {
|
|||||||
return c.memory.ReadUint("memory.max_usage_in_bytes")
|
return c.memory.ReadUint("memory.max_usage_in_bytes")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProcessPeak implements Cgroup.
|
||||||
|
func (c *V1) ProcessPeak() (uint64, error) {
|
||||||
|
return 0, ErrNotInitialized
|
||||||
|
}
|
||||||
|
|
||||||
// SetMemoryLimit write memory.limit_in_bytes
|
// SetMemoryLimit write memory.limit_in_bytes
|
||||||
func (c *V1) SetMemoryLimit(i uint64) error {
|
func (c *V1) SetMemoryLimit(i uint64) error {
|
||||||
return c.memory.WriteUint("memory.limit_in_bytes", i)
|
return c.memory.WriteUint("memory.limit_in_bytes", i)
|
||||||
|
|||||||
@ -155,6 +155,14 @@ func (c *V2) MemoryMaxUsage() (uint64, error) {
|
|||||||
return c.ReadUint("memory.peak")
|
return c.ReadUint("memory.peak")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProcessPeak reads pids.peak
|
||||||
|
func (c *V2) ProcessPeak() (uint64, error) {
|
||||||
|
if !c.control.Pids {
|
||||||
|
return 0, ErrNotInitialized
|
||||||
|
}
|
||||||
|
return c.ReadUint("pids.peak")
|
||||||
|
}
|
||||||
|
|
||||||
// SetCPUBandwidth set cpu.max quota period
|
// SetCPUBandwidth set cpu.max quota period
|
||||||
func (c *V2) SetCPUBandwidth(quota, period uint64) error {
|
func (c *V2) SetCPUBandwidth(quota, period uint64) error {
|
||||||
if !c.control.CPU {
|
if !c.control.CPU {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user