limits

package
v0.0.0-...-036c9d4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2024 License: Apache-2.0, MIT Imports: 5 Imported by: 38

Documentation

Overview

Package limits provides resource limits.

Index

Constants

View Source
const (
	// CtxLimits is a Context.Value key for a LimitSet.
	CtxLimits contextID = iota
)
View Source
const Infinity = ^uint64(0)

Infinity is a constant representing a resource with no limit.

Variables

AllLimitTypes contains all types in the order how they are presented in /proc/pid/limits.

FromLinuxResource maps linux resources to LimitTypes.

View Source
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

func FromLinux

func FromLinux(rl uint64) uint64

FromLinux maps linux rlimit values to sentry Limits, being careful to handle infinities.

func ToLinux

func ToLinux(l uint64) uint64

ToLinux maps sentry Limits to linux rlimit values, being careful to handle infinities.

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

func FromContext(ctx context.Context) *LimitSet

FromContext returns the limits that apply to ctx.

func FromContextOrDie

func FromContextOrDie(ctx context.Context) *LimitSet

FromContextOrDie returns FromContext(ctx) if the latter is not nil. Otherwise, panic is triggered.

func NewLimitSet

func NewLimitSet() *LimitSet

NewLimitSet creates a new, empty LimitSet.

func NewLinuxDistroLimitSet

func NewLinuxDistroLimitSet() (*LimitSet, error)

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

func NewLinuxLimitSet() (*LimitSet, error)

NewLinuxLimitSet returns a LimitSet whose values match the default rlimits in Linux.

func (*LimitSet) Get

func (l *LimitSet) Get(t LimitType) Limit

Get returns the resource limit associated with LimitType t. If no limit is provided, it defaults to an infinite limit.Infinity.

func (*LimitSet) GetCapped

func (l *LimitSet) GetCapped(t LimitType, max uint64) uint64

GetCapped returns the current value for the limit, capped as specified.

func (*LimitSet) GetCopy

func (l *LimitSet) GetCopy() *LimitSet

GetCopy returns a clone of the LimitSet.

func (*LimitSet) Set

func (l *LimitSet) Set(t LimitType, v Limit, privileged bool) (Limit, error)

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

func (l *LimitSet) SetUnchecked(t LimitType, v Limit)

SetUnchecked assigns value v to resource of LimitType t.

type LimitType

type LimitType int

LimitType defines a type of resource limit.

const (
	CPU LimitType = iota
	FileSize
	Data
	Stack
	Core
	Rss
	ProcessCount
	NumberOfFiles
	MemoryLocked
	AS
	Locks
	SignalsPending
	MessageQueueBytes
	Nice
	RealTimePriority
	Rttime
)

Set of constants defining the different types of resource limits.

func (LimitType) Name

func (lt LimitType) Name() string

Name returns the kernel name of the limit

func (LimitType) Unit

func (lt LimitType) Unit() string

Unit returns the unit string for a limit

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL