Documentation ¶
Overview ¶
Package limits provides resource limits.
Index ¶
Constants ¶
const ( // CtxLimits is a Context.Value key for a LimitSet. CtxLimits contextID = iota )
const Infinity = ^uint64(0)
Infinity is a constant representing a resource with no limit.
Variables ¶
var AllLimitTypes = []LimitType{ CPU, FileSize, Data, Stack, Core, Rss, ProcessCount, NumberOfFiles, MemoryLocked, AS, Locks, SignalsPending, MessageQueueBytes, Nice, RealTimePriority, Rttime, }
AllLimitTypes contains all types in the order how they are presented in /proc/pid/limits.
var FromLinuxResource = map[int]LimitType{ linux.RLIMIT_CPU: CPU, linux.RLIMIT_FSIZE: FileSize, linux.RLIMIT_DATA: Data, linux.RLIMIT_STACK: Stack, linux.RLIMIT_CORE: Core, linux.RLIMIT_RSS: Rss, linux.RLIMIT_NPROC: ProcessCount, linux.RLIMIT_NOFILE: NumberOfFiles, linux.RLIMIT_MEMLOCK: MemoryLocked, linux.RLIMIT_AS: AS, linux.RLIMIT_LOCKS: Locks, linux.RLIMIT_SIGPENDING: SignalsPending, linux.RLIMIT_MSGQUEUE: MessageQueueBytes, linux.RLIMIT_NICE: Nice, linux.RLIMIT_RTPRIO: RealTimePriority, linux.RLIMIT_RTTIME: Rttime, }
FromLinuxResource maps linux resources to LimitTypes.
var FromLinuxResourceName = map[string]LimitType{ "RLIMIT_AS": AS, "RLIMIT_CORE": Core, "RLIMIT_CPU": CPU, "RLIMIT_DATA": Data, "RLIMIT_FSIZE": FileSize, "RLIMIT_LOCKS": Locks, "RLIMIT_MEMLOCK": MemoryLocked, "RLIMIT_MSGQUEUE": MessageQueueBytes, "RLIMIT_NICE": Nice, "RLIMIT_NOFILE": NumberOfFiles, "RLIMIT_NPROC": ProcessCount, "RLIMIT_RSS": Rss, "RLIMIT_RTPRIO": RealTimePriority, "RLIMIT_RTTIME": Rttime, "RLIMIT_SIGPENDING": SignalsPending, "RLIMIT_STACK": Stack, }
FromLinuxResourceName maps from linux resource names to LimitTypes.
Functions ¶
Types ¶
type Limit ¶
type Limit struct { // Cur specifies the current limit. Cur uint64 `json:"cur,omitempty"` // Max specifies the maximum settable limit. Max uint64 `json:"max,omitempty"` }
Limit specifies a system limit.
+stateify savable
type LimitSet ¶
type LimitSet struct {
// contains filtered or unexported fields
}
LimitSet represents the Limits that correspond to each LimitType.
+stateify savable
func FromContext ¶
FromContext returns the limits that apply to ctx.
func FromContextOrDie ¶
FromContextOrDie returns FromContext(ctx) if the latter is not nil. Otherwise, panic is triggered.
func NewLinuxDistroLimitSet ¶
NewLinuxDistroLimitSet returns a new LimitSet whose values are typical for a booted Linux distro.
Many Linux init systems adjust the default Linux limits to values more expected by the rest of the userspace. NewLinuxDistroLimitSet returns a LimitSet with sensible defaults for applications that aren't starting their own init system.
func NewLinuxLimitSet ¶
NewLinuxLimitSet returns a LimitSet whose values match the default rlimits in Linux.
func (*LimitSet) Get ¶
Get returns the resource limit associated with LimitType t. If no limit is provided, it defaults to an infinite limit.Infinity.
func (*LimitSet) GetCapped ¶
GetCapped returns the current value for the limit, capped as specified.
func (*LimitSet) Set ¶
Set assigns value v to resource of LimitType t and returns the old value. privileged should be true only when either the caller has CAP_SYS_RESOURCE or when creating limits for a new kernel.
func (*LimitSet) SetUnchecked ¶
SetUnchecked assigns value v to resource of LimitType t.
type LimitType ¶
type LimitType int
LimitType defines a type of resource limit.