2014-05-15 06:21:44 +08:00
package cgroups
import (
2014-08-21 01:32:01 +08:00
"fmt"
2014-02-18 07:14:30 +08:00
2014-06-10 23:14:16 +08:00
"github.com/docker/libcontainer/devices"
2014-05-15 06:21:44 +08:00
)
2015-01-13 05:54:00 +08:00
type Manager interface {
2015-01-14 23:23:42 +08:00
// Apply cgroup configuration to the process with the specified pid
2015-01-13 05:54:00 +08:00
Apply ( pid int ) error
2015-01-14 23:23:42 +08:00
// Returns the PIDs inside the cgroup set
2015-01-13 05:54:00 +08:00
GetPids ( ) ( [ ] int , error )
2015-01-14 23:23:42 +08:00
// Returns statistics for the cgroup set
2015-01-13 05:54:00 +08:00
GetStats ( ) ( * Stats , error )
2015-01-14 23:23:42 +08:00
// Toggles the freezer cgroup according with specified state
2015-01-13 19:52:14 +08:00
Freeze ( state FreezerState ) error
2015-01-14 23:23:42 +08:00
// Destroys the cgroup set
Destroy ( ) error
// NewCgroupManager() and LoadCgroupManager() require following attributes:
// Paths map[string]string
// Cgroups *cgroups.Cgroup
// Paths maps cgroup subsystem to path at which it is mounted.
// Cgroups specifies specific cgroup settings for the various subsystems
// Returns cgroup paths to save in a state file and to be able to
// restore the object later.
2015-01-13 05:54:00 +08:00
GetPaths ( ) map [ string ] string
}
2014-05-31 06:09:07 +08:00
type FreezerState string
const (
Undefined FreezerState = ""
Frozen FreezerState = "FROZEN"
Thawed FreezerState = "THAWED"
)
2014-08-21 01:32:01 +08:00
type NotFoundError struct {
Subsystem string
}
func ( e * NotFoundError ) Error ( ) string {
return fmt . Sprintf ( "mountpoint for %s not found" , e . Subsystem )
}
func NewNotFoundError ( sub string ) error {
return & NotFoundError {
Subsystem : sub ,
}
}
func IsNotFound ( err error ) bool {
if err == nil {
return false
}
_ , ok := err . ( * NotFoundError )
return ok
}
2014-05-15 06:21:44 +08:00
type Cgroup struct {
Name string ` json:"name,omitempty" `
2014-02-18 07:14:30 +08:00
Parent string ` json:"parent,omitempty" ` // name of parent cgroup or slice
2014-05-15 06:21:44 +08:00
2014-05-31 09:30:27 +08:00
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.
AllowedDevices [ ] * devices . Device ` json:"allowed_devices,omitempty" `
Memory int64 ` json:"memory,omitempty" ` // Memory limit (in bytes)
MemoryReservation int64 ` json:"memory_reservation,omitempty" ` // Memory reservation or soft_limit (in bytes)
MemorySwap int64 ` json:"memory_swap,omitempty" ` // Total memory usage (memory + swap); set `-1' to disable swap
CpuShares int64 ` json:"cpu_shares,omitempty" ` // CPU shares (relative weight vs. other containers)
CpuQuota int64 ` json:"cpu_quota,omitempty" ` // CPU hardcap limit (in usecs). Allowed cpu time in a given period.
CpuPeriod int64 ` json:"cpu_period,omitempty" ` // CPU period to be used for hardcapping (in usecs). 0 to use system default.
CpusetCpus string ` json:"cpuset_cpus,omitempty" ` // CPU to use
2015-01-27 20:54:19 +08:00
CpusetMems string ` json:"cpuset_mems,omitempty" ` // MEM to use
BlkioWeight int64 ` json:"blkio_weight,omitempty" ` // Specifies per cgroup weight, range is from 10 to 1000.
2014-05-31 06:09:07 +08:00
Freezer FreezerState ` json:"freezer,omitempty" ` // set the freeze value for the process
Slice string ` json:"slice,omitempty" ` // Parent slice to use for systemd
2014-05-15 06:21:44 +08:00
}