Documentation
¶
Overview ¶
Package machineload reads the machine's load and process table and decides, from one snapshot, whether programs outside the running work are keeping the machine busy (itd-2609231434459890, spc-2609231542463113).
It is a leaf: it imports only the standard library, so the one new primitive the load check needs brings no dependency with it. Everything that decides is a pure function of a Snapshot, so a two-day burner is a fixture value, never a process a test has to leave running. The per-platform readers only fill a Snapshot: macOS through sysctl and /bin/ps, Linux through /proc alone, and every other platform reports ErrUnsupported so the caller can say it could not check (read_other.go).
Nothing here writes to stdout, signals a process or writes a file.
Index ¶
- Constants
- Variables
- func AbcdUnder(snap Snapshot, root int) []int
- func Descends(procs []Proc, pid, ancestor int) bool
- func FairShare(snap Snapshot) float64
- func GateCandidates(snap Snapshot, self Self) []int
- func GoCacheDir() string
- func GoEnvCache() (string, error)
- func GoTestParallelism(snap Snapshot, slots int) int
- func GoTestTimeout(snap Snapshot, base time.Duration) time.Duration
- func HoldsHome(dir, home string) bool
- func IsAbcdName(name string) bool
- func IsErrandName(name string) bool
- func IsLoadWaiter(args []string) bool
- func IsNarrowCommand(cmd []string) bool
- func IsRaceCommand(cmd []string) bool
- func JustOpened(snap Snapshot, self Self, args map[int][]string, window time.Duration, ...) []int
- func LooksLikeGoCache(dir string) bool
- func LooksLikeGoCacheFS(fsys fs.FS) bool
- func MemoryLevelRank(level string) int
- func NarrowAhead(snap Snapshot, self Self, args map[int][]string) (running, ahead, queued []int)
- func OverdueWhole(snap Snapshot, a Ahead, slots int, after time.Duration) []int
- func ParseLimits(data []byte, cores int) (Limits, *LimitsFault)
- func QueuedAt(snap Snapshot, self Self, args map[int][]string, race bool) []int
- func QueuedUnder(snap Snapshot, root int, args map[int][]string) []int
- func RaceAhead(snap Snapshot, self Self, args map[int][]string) (ahead, crossed []int)
- func RaceCommandWaiters(snap Snapshot, self Self, args map[int][]string) []int
- func RaceRuns(snap Snapshot, self Self, args map[int][]string) []int
- func ReadArgs(pids []int) (map[int][]string, error)
- func StandBackFrom(snap Snapshot, self Self, opened []int) []int
- func UngatedTests(snap Snapshot, self Self, args map[int][]string) []int
- type Ahead
- type CacheSize
- type Limits
- type LimitsFault
- type Memory
- type MemoryUnsupportedError
- type OtherStrays
- type OwnStray
- type Proc
- type Remedy
- type Self
- type Snapshot
- type Verdict
- type Volume
Constants ¶
const ( TriggerStray = "stray" TriggerExtreme = "extreme" )
The two triggers.
const ( // RemedyGroup: `pgrep -g <pgid>`, then `kill -- -<pgid>`. RemedyGroup = "group" // RemedyProcess: `ps -o pid=,comm= -p <pid>`, then `kill <pid>`. RemedyProcess = "process" // WhyMixedGroup: the stray's group holds a program the warning does not name. WhyMixedGroup = "mixed-group" // WhyCallersGroup: the stray's group is the check's own, or an ancestor's. WhyCallersGroup = "callers-group" )
The two remedy forms, and why a stray gets the process form.
const ( KeyStrayMinutes = "stray-minutes" KeyExtremeLoad = "extreme-load" KeyWaitLoad = "wait-load" // DefaultStrayMinutes is how long a process may run at nearly all the CPU it // could get before it reads as a stray. DefaultStrayMinutes = 30 // DefaultExtremeFactor times the online core count is the extreme load. DefaultExtremeFactor = 4 // DefaultWaitFactor times the online core count is the waiter's limit: the // waiter opens only while the one-minute load is strictly below twice the // core count. Once was too low: the baseline load of a busy multi-session // machine already sits around one core-count, so a limit of the cores kept // every waiter shut for hours (between 20 and 100 on 16 cores, 2026-10-11) // and sent sessions back to hand-written loops. Serialising the work is the // job of the race-run condition and the hold, not of the load number. One // race run adds about a core-count of load, so admitting below twice the // cores bounds the peak near three times them, under the extreme limit's // DefaultExtremeFactor of four. DefaultWaitFactor = 2 )
The three keys, and their bounds.
const ( MemoryDarwin = "darwin" MemoryLinux = "linux" )
The platforms a Memory reading comes from.
const ( MemoryNormal = "normal" MemoryWarn = "warn" MemoryUrgent = "urgent" MemoryCritical = "critical" )
macOS's pressure levels, as a Memory names them.
const GoCacheBudget = 1500 * time.Millisecond
GoCacheBudget bounds the walk GoCacheSize makes. A full walk is too slow to make before a refusal: on the machine that filed iss-2610281502581386 a 291 GiB cache held about 927,000 files and `du -sk` over it took 66 seconds. The cache spreads its entries over 256 subdirectories by the first byte of each entry's hash, so the entries are spread evenly, and a few subdirectories walked in full give the size to within a few percent.
const GoProgram = "go"
GoProgram is the base name of the go command's executable, as the process table names it (Proc.Name, the kernel's record of what was executed, never a word of a command line).
const LimitsFileName = "load-limits"
LimitsFileName is the settings file's name under ~/.abcd.noindex/.
const MaxNarrowPackages = 3
MaxNarrowPackages is the most packages a narrow run names. Three is a change's usual reach, its package, the caller that exercises it and the surface over that, and it is the most any builder's gated test named on the evening of 2026-11-04. go test runs packages side by side, so a run's weight grows with the count, and a longer list is the start of a sweep.
const MaxOwnNamed = 20
MaxOwnNamed caps how many of the caller's own strays a warning names; the rest are counted.
const NarrowMark = "--narrow"
NarrowMark is the flag, before `--`, that asks for the narrow gate. An abcd built before it skips any flag it does not know when it reads a waiter's words, so to that abcd a marked waiter is an ordinary one, and that abcd cannot itself be started with the mark.
NearFullShare is the part of its fair share (FairShare) at which a process is using nearly all the CPU it could get: on a machine loaded no higher than its cores, 0.9 of a core.
const StartTolerance = 2
StartTolerance is how far, in whole seconds, two start times read from the process table may differ and still be one moment as far as the table can tell: a start time is the read's moment less the process's age, and macOS reports an age in whole seconds and Linux in clock ticks against an uptime read a moment apart, so one process read twice can differ by a second. The session-name register (sessionname) judges a recorded host by it, and the load gate's queue (QueueAhead) orders two waiters within it by pid instead.
const TestTimeoutMaxFactor = 2
TestTimeoutMaxFactor is the most GoTestTimeout scales a stage's base package budget by. land's bound on a whole preflight run holds both test stages at it (internal/core/landing, TestRunBoundHoldsBothStagesAtTheTimeoutCap).
Variables ¶
var ErrUnsupported = errors.New("machineload: this platform's load and process table are not read")
ErrUnsupported is returned by Read on a platform the readers do not cover.
Functions ¶
func AbcdUnder ¶ added in v0.16.1
AbcdUnder returns, in pid order, the processes descended from root that execute abcd: the ones whose arguments QueuedUnder asks for. A runner reads it for the harness it started (iss-2611021751406429).
func Descends ¶ added in v0.14.0
Descends reports whether pid is a descendant of ancestor (a process is not its own descendant).
func FairShare ¶ added in v0.11.0
FairShare is the CPU, in cores, one runnable process can get on the machine as the snapshot finds it loaded: the online cores divided by the one-minute load, the runnable demand, and never more than one core. With no load reading, no core count, or a load no higher than the cores, it is one core. Forty busy loops on 16 cores each get 0.4 of a core, and each uses all of it.
func GateCandidates ¶ added in v0.14.1
GateCandidates returns, in pid order, the processes the gate asks for their arguments: those executing go (a race run), make (a preflight) or abcd (a waiter), outside self's process and its ancestors, and the ancestors executing abcd, so a waiter can tell that an ancestor is a waiter running the command this one is part of.
func GoCacheDir ¶ added in v0.16.0
func GoCacheDir() string
GoCacheDir is the Go build cache's directory as `go env GOCACHE` reports it, which honours both the GOCACHE variable and a value saved with `go env -w`; "" when caching is off or the directory does not exist yet. The go command runs in the temporary directory with GOTOOLCHAIN=local, so no repository's go.mod is read and no toolchain is fetched to answer. Where no go command can be run, the cache is where go would put it: GOCACHE, or go-build in the user cache directory.
func GoEnvCache ¶ added in v0.16.2
GoEnvCache is what `go env GOCACHE` reports, run as GoCacheDir runs it but with none of its fallbacks: an error where no go command can answer. A caller about to delete files from the path asks this, never a guess at it.
func GoTestParallelism ¶ added in v0.14.1
GoTestParallelism is the -p a `go test` run started now should take, so one run cannot saturate the machine (iss-2610102020442624): the cores the machine can still give, which is twice the online cores (the waiter's default limit, DefaultWaitFactor) less the one-minute load rounded up, never more than the cores divided among the preflights the first gate admits at once (load.preflights; zero or less reads as one, and one is go's own default of the cores) and never fewer than a quarter of the cores, or one, so a run on a loaded machine still makes progress. With n slots, n concurrent stages each take at most the cores divided by n (half at two, a quarter at four, where on most machines the share and the floor meet): the load a later stage starts under lags the earlier stages' real demand by up to a minute, so the load alone would give each the whole machine. A race stage may run beside n unit stages, since a preflight at its race gate takes no slot (Ahead.TakingSlots), so the load limit is what bounds that one extra stage. An unreadable load leaves the cores divided among the slots.
func GoTestTimeout ¶ added in v0.16.0
GoTestTimeout is the -timeout a `go test` stage started now should give each package, so a package slowed by the machine's load is not killed with no test hung (iss-2610241911052191): base while the one-minute load is at most one runnable process per online core, and TestTimeoutMaxFactor times base past that, since a package's tests take about as much longer as the runnable processes sharing each core. It takes those two values only, not one in proportion: go test hashes -timeout into its cache key, so a budget that moved with every reading would rerun every cached package on a busy machine. An unreadable load leaves the base. Like GoTestParallelism it reads the load as the stage starts, not as the stage runs.
func HoldsHome ¶ added in v0.16.2
HoldsHome reports whether dir is the home or a directory above it, so a caller deleting files from a directory the environment named can decline it.
func IsAbcdName ¶ added in v0.16.0
IsAbcdName reports whether a process's base name is abcd's, a plugin build's platform-suffixed name included.
func IsErrandName ¶ added in v0.16.0
IsErrandName reports whether a process's base name is one a waiter's own errands run under (errandPrograms): the ps it reads the machine with and the git and gh it renews reservations through.
func IsLoadWaiter ¶ added in v0.16.0
IsLoadWaiter reports whether args, abcd's arguments after the program name, run a waiter at either gate (isLoadWaiter).
func IsNarrowCommand ¶ added in v0.16.2
IsNarrowCommand reports whether cmd, a command a waiter gates (the words after `--`, its program first), is a narrow run: its program is the exact word go, as PATH finds it for everyone, its go command `test`, after `-C <dir>` at most, which a verifier's copy uses, every flag one of the few above (-count only as 1, since a repeat count is a soak), and at least one and at most MaxNarrowPackages explicit package paths, with no wildcard. Anything else is a whole run: a shell or a make is not read into, no package at all, `-args`, and a word holding whitespace, which another account's reading of the table on macOS would split differently.
func IsRaceCommand ¶ added in v0.15.1
IsRaceCommand reports whether cmd, a command a waiter gates (the words after `--`, its program first), is a race run: its program is go and its go command is `test` with -race, read as a race run's arguments are (isRaceTest). A shell or a make that runs one is not read into.
func JustOpened ¶ added in v0.15.1
func JustOpened(snap Snapshot, self Self, args map[int][]string, window time.Duration, race bool) []int
JustOpened returns, in pid order, the waiters at one gate, the race gate's when race is set and the first gate's otherwise, outside self's process and its ancestors, that are running their command and opened within window of the snapshot: a waiter with a child other than ps is running its command, and it opened when its oldest such child started. An opener reads it just before it starts its command (implement.WaitLoad): across accounts no hold keeps two waiters from opening in one moment, so each looks once more and stands back from the others StandBackFrom names. A waiter at the other gate did not open beside this one: a race waiter's preflight passed its first gate earlier, and a first gate's opener never stands back from it, as an abcd released before the race gate, which reads no race waiter at all, does not. A child under a second old on macOS reads an age of zero, which is within any window.
func LooksLikeGoCache ¶ added in v0.16.0
LooksLikeGoCache reports whether dir has the Go build cache's shape: the README the go command writes there, or all 256 of the subdirectories it creates (00 to ff). A directory named by GOCACHE that is not a cache (a project, or a home) is not one, so the gate prints no command that deletes files in it.
func LooksLikeGoCacheFS ¶ added in v0.16.2
LooksLikeGoCacheFS is LooksLikeGoCache for a directory already opened, such as an os.Root's FS.
func MemoryLevelRank ¶ added in v0.16.1
MemoryLevelRank orders macOS's pressure levels, normal lowest: a level is at or above another when its rank is. An unknown level ranks as critical, so a level abcd does not know never reads as below a floor.
func NarrowAhead ¶ added in v0.16.2
NarrowAhead reads the narrow runs from one snapshot and the candidates' arguments, outside self's process and its ancestors: those running their commands, those queued ahead of self by the queue's order (queueOrder), and every one queued, each in pid order.
func OverdueWhole ¶ added in v0.16.2
OverdueWhole returns, in pid order, the whole-run waiters in a (self's own reading, so each started before self) that have been queued for at least after, with a whole-run slot free now, against slots (load.preflights): a waiter whose slots are all taken is shut by them, and no narrow run is in its way.
Only a waiter that started earlier can be overdue. An older abcd counts a narrow waiter that started before it as ahead, so a narrow run that stood aside for a later start would wait on a waiter waiting on it; every wait here points at an earlier start, and such a chain has no cycle.
func ParseLimits ¶
func ParseLimits(data []byte, cores int) (Limits, *LimitsFault)
ParseLimits reads a settings file's bytes. Any fault makes the whole file unusable: it returns the defaults for BOTH limits, never a mix of the file's and the defaults, with the fault.
func QueuedAt ¶ added in v0.16.0
QueuedAt returns, in pid order, the waiters queued at one gate, the race gate's when race is set and the first gate's otherwise, outside self's process and its ancestors: every one not running its command, ahead of self or not. implement.WaitLoad reads it to tell a crossed waiter that has left the queue (exited, or opened) from one a tie read differently has moved behind self.
func QueuedUnder ¶ added in v0.16.1
QueuedUnder returns, in pid order, the waiters descended from root that are queued at either gate: an `implement load --wait` or `--race-gate` (args, keyed by pid, the program name dropped) with no child but its own errands, so it runs no command yet. A runner reads it to stop its clock while the role it started waits for its turn at the load gate (iss-2611021751406429): time spent queued behind other preflights is the machine's, not the role's.
func RaceAhead ¶ added in v0.15.1
RaceAhead returns, in pid order, the race waiters (isRaceWaiter) ahead of self at the race gate: those queued ahead of it, by the rule the first gate's queue keeps (ahead by start, queuedAhead), and those running their command, outside self's process and its ancestors; and, as crossed, those queued ahead of it with a higher pid (Ahead.Crossed). A waiter at a first gate, and a preflight in its unit stage, are not ahead of it there; the race runs that shut it are RaceRuns.
func RaceCommandWaiters ¶ added in v0.15.1
RaceCommandWaiters returns, in pid order, the first gate's waiters outside self's process and its ancestors that are running a command that is a race run (`--wait -- go test -race`, IsRaceCommand). Such a waiter is a race run for both gates from the moment it opens: its mark shows it running before the go test it starts is in the table, and once that go test is, RaceRuns names it too. A queued one is not.
func RaceRuns ¶ added in v0.14.0
RaceRuns returns, in pid order, the candidates whose arguments (args, keyed by pid, the program name dropped) start a race run. A candidate with no arguments read (gone by the time they were asked for) is not one.
func ReadArgs ¶ added in v0.14.0
ReadArgs reads the exact argv of each of pids, the program name dropped, from /proc/<pid>/cmdline. A pid that has exited is absent from the result.
func StandBackFrom ¶ added in v0.16.0
StandBackFrom returns, in pid order, the waiters of opened, read from snap beside self as having opened in the same moment (JustOpened), that self stands back from: every one but those self precedes both in the queue's order (queueOrder, from snap's ages) and by pid. So the later start stands back from the earlier whatever their pids, as the queue orders them; inside one tie, where the order is by pid, exactly one goes on.
The earlier start stands back from a lower pid that opened beside it too. That opener started later, so a waiter of this code would have stood back from it; an older abcd does not (v0.15.1 stands back only from a lower pid, and v0.15.0 takes no such look), and goes on. Were this one to go on as well, both would run their commands, and under `--wait -- make preflight` each preflight's own gate would wait on the other's waiter until its timeout.
So whenever the pair is crossed (the earlier start has the higher pid), the later start stands back, and so does the earlier start if it runs this code or v0.15.1, which stands back from the lower pid: both stand back and re-draw their jitters, at most implement.WaitBackoffCap times each. Only a later start of v0.15.1 or v0.15.0 goes on past a crossed pair, and then this code's earlier start standing back is what keeps the two from running at once. A pair that is not crossed agrees: exactly one goes on, unless the other runs v0.15.0. Two waiters of this code meet here seldom, since the later start waits on the earlier in the queue: only after a wrap, for a crossed pair, where a tie at the tolerance's edge reads differently to each (macOS reads ages in whole seconds) or the later has stopped counting the earlier past its cap (implement.WaitCrossedCap).
func UngatedTests ¶ added in v0.16.0
UngatedTests returns, in pid order, the candidates whose arguments start a go test run, with any flags, that no gate admitted (iss-2610241130157455): no ancestor of it is a make preflight or a waiter (`abcd implement load --wait`). Those are the gate's own work: a waiter runs its command once admitted, and a preflight waits at its gate once, as one whole run, before any of its stages. A records-only preflight's shorter rule waits at no gate, and its tests, beneath its make, are not named either. Any other run adds to the load the gate waits on without ever waiting itself, so the waiter names it beside the load. It shuts nothing.
Types ¶
type Ahead ¶ added in v0.14.1
type Ahead struct {
// Preflights are the make preflights running, not queued at their gate.
Preflights []int
// Waiters are the waiters queued ahead of this one (ahead by start: earlier,
// or in the same tie group with a lower pid; queueOrder) or running the
// command they gate, in pid order.
Waiters []int
// Busy is the work running past its first gate: each preflight in
// Preflights and each waiter in Waiters running its command, counted once
// where one runs beneath the other (`--wait -- make preflight` is one
// unit), in pid order.
Busy []int
// Queued is the waiters in Waiters queued ahead, not running a command.
Queued []int
// Crossed is the waiters in Queued with a higher pid than this one's:
// ahead by start across a pid wrap. A waiter built before the start order
// waits on every lower pid, so it may be waiting on this one in turn, and
// implement.WaitLoad stops counting crossed waiters once they alone have
// held the gate shut for implement.WaitCrossedCap (Uncrossed).
Crossed []int
// AtRaceGate is the preflights in Preflights and the units in Busy with a
// race waiter queued beneath them, not running its command: their tests
// are done and their race stage has not started, so they run nothing.
// Above one slot they take none (TakingSlots, iss-2610282016250805).
AtRaceGate []int
}
Ahead is what the process table holds ahead of a waiter at the gate.
func QueueAhead ¶ added in v0.14.1
QueueAhead reads what is ahead of self at the first gate from one snapshot and the candidates' arguments (args, keyed by pid, the program name dropped). A waiter with a child other than ps is running its command. A preflight with a first gate's waiter beneath it that is not running a command is queued at its gate, and that waiter is its place in the queue. A waiter beneath a waiter running its command takes that ancestor's place, ahead of every queued waiter. A race waiter (isRaceWaiter) is never in this queue: it waits at the race gate (RaceAhead), and a preflight whose waiter is one has passed its first gate. It stays in Preflights and Busy, and while its race waiter is queued it is in AtRaceGate too: idle, so above one slot it takes none (TakingSlots).
func (Ahead) Shut ¶ added in v0.15.1
Shut reports which of the queue's conditions hold the first gate shut when it admits slots units of work at once (the load.preflights setting; zero or less reads as one): every unit in Busy takes a slot, and the gate is shut on preflight or on waiter once they are all taken, by the kind of unit that takes them. A waiter queued ahead shuts it whatever slots is, so a free slot never lets a waiter jump the queue. With one slot this is the gate as it read before slots existed: any running preflight shuts it on preflight, and any waiter ahead or running its command on waiter. Above one, a unit at its race gate takes no slot (TakingSlots).
func (Ahead) TakingSlots ¶ added in v0.16.0
TakingSlots is a as the first gate counts it against slots units of work at once (the load.preflights setting; zero or less reads as one). Above one slot the units at their race gate (AtRaceGate) are dropped from Preflights, Busy and Waiters: each is idle until its race run starts, and then it is busy again, beneath its make or as its race waiter running its command. Race runs are kept apart by the race gate (RaceAhead, RaceRuns and the race gate's hold), never by this count, and the load limit still judges the machine as a whole. With one slot the race gate opens at once, so a preflight at it is about to start its race stage, and a stays as it is: the gate reads as it did before slots existed.
type CacheSize ¶ added in v0.16.0
type CacheSize struct {
// Bytes is the size: exact when Sampled equals Subdirs, else estimated
// from the subdirectories walked.
Bytes uint64
// Sampled is how many of the cache's subdirectories were walked, and
// Subdirs how many it has.
Sampled int
Subdirs int
}
CacheSize is a measure of the Go build cache's size.
func GoCacheSize ¶ added in v0.16.0
GoCacheSize measures the Go build cache at dir. The cache keeps its entries in 256 subdirectories named by the first byte of each entry's hash (00 to ff), so the size of the subdirectories walked within budget, scaled by how many there are, estimates the whole; a cache small enough to walk in full is measured exactly. At least one subdirectory is always walked, so there is always a figure. Files at the top of the cache (its README and trim stamp) are not counted.
type Limits ¶
type Limits struct {
// StrayMinutes: a process older than this at nearly all the CPU it could get
// is a stray.
StrayMinutes int
// ExtremeLoad: a one-minute load average strictly above this is extreme. It is
// an absolute load, in the online-core unit the LOAD rule's cap uses.
ExtremeLoad float64
// StrayFromFile and ExtremeFromFile say which limits the settings file set.
StrayFromFile bool
ExtremeFromFile bool
// WaitLoad: the waiter (`implement load --wait`) opens only while the
// one-minute load average is strictly below this.
WaitLoad float64
WaitFromFile bool
}
Limits are the two limits the classifier applies, and the waiter's.
func DefaultLimits ¶
DefaultLimits derives the defaults from the online core count: 30 minutes, four times the cores, and twice the cores.
type LimitsFault ¶
LimitsFault is why a settings file is unusable. It names the line (zero when the fault is the file's, not a line's) and the fault class, and never a value: a value is whatever the caller typed, and the report is printed and logged.
func (*LimitsFault) Error ¶
func (f *LimitsFault) Error() string
type Memory ¶ added in v0.16.1
type Memory struct {
// Platform is MemoryDarwin or MemoryLinux.
Platform string
// Level is macOS's pressure level: MemoryNormal, MemoryWarn, MemoryUrgent
// or MemoryCritical; "" on Linux.
Level string
// StallPct is Linux's share of the last ten seconds in which some task
// stalled waiting for memory, a percentage; zero on macOS.
StallPct float64
// Raw is the value as the system gave it, for the report.
Raw string
}
Memory is one reading of the machine's memory pressure.
func ReadMemory ¶ added in v0.16.1
ReadMemory reads this Linux machine's memory pressure from /proc/pressure/memory with one bounded read (readPressureFS).
type MemoryUnsupportedError ¶ added in v0.16.1
type MemoryUnsupportedError struct{ Why string }
MemoryUnsupportedError is a memory reading abcd cannot take on this machine: another platform, or a Linux kernel without the pressure stall information. It is errors.Is ErrUnsupported, and its message says why.
func (*MemoryUnsupportedError) Error ¶ added in v0.16.1
func (e *MemoryUnsupportedError) Error() string
func (*MemoryUnsupportedError) Unwrap ¶ added in v0.16.1
func (e *MemoryUnsupportedError) Unwrap() error
type OtherStrays ¶
OtherStrays is every other account's strays: how many, and how many cores they use between them. The type has no field that could hold a name, a command line, a uid or an account, so no renderer can leak one (TestOtherStraysTypeCarriesNoIdentity).
type Proc ¶
type Proc struct {
PID int
PPID int
PGID int
// UID is the effective uid.
UID uint32
// Age is how long the process has existed.
Age time.Duration
// CPU is the process's cumulative user plus system CPU time.
CPU time.Duration
// Name is the executable's base name: never a path, never a command line.
Name string
}
Proc is one process as the check sees it.
type Remedy ¶
type Remedy struct {
// Form is RemedyGroup or RemedyProcess.
Form string
// PGID and PIDs are the group form's group and the strays it holds.
PGID int
PIDs []int
// PID and Why are the process form's process and why it is not the group form.
PID int
Why string
}
Remedy is one way to stop some of the caller's own strays. It is a plan for the caller to carry out; nothing here signals anything.
type Self ¶
Self is the check's own invocation: its pid, whose parent chain is exempt, and its effective uid, which decides whose strays are the caller's own.
type Snapshot ¶
type Snapshot struct {
// Load1, Load5 and Load15 are the load averages over one, five and fifteen
// minutes. They are meaningful only when HasLoad is true.
Load1, Load5, Load15 float64
HasLoad bool
// Cores is the online core count, the unit the load averages are read in.
Cores int
// CoresFallback is true when the online count could not be read and Cores is
// runtime.NumCPU's count instead.
CoresFallback bool
// Procs is the process table. It is meaningful only when HasProcs is true: a
// load average that reads while the process table does not is still a reading.
Procs []Proc
HasProcs bool
}
Snapshot is one reading of the machine.
func Read ¶
Read reads this Linux machine from /proc and /sys alone, so a minimal or missing ps does not matter: the load averages from /proc/loadavg, the online core count from /sys/devices/system/cpu/online (what glibc's sysconf(_SC_NPROCESSORS_ONLN) reads; runtime.NumCPU counts the affinity mask and can be smaller), and every numeric /proc/<pid>. A load average that reads while the process table does not is returned with the error, so the extreme trigger can still apply.
type Verdict ¶
type Verdict struct {
// Triggers holds TriggerStray and TriggerExtreme, in that order, when they
// fire; empty is nothing to warn about.
Triggers []string
// Own is the caller's own strays, at most MaxOwnNamed, by pid; OwnMore counts
// the rest.
Own []OwnStray
OwnMore int
// Others is every other account's strays, anonymously.
Others OtherStrays
// Remedy covers every stray in Own.
Remedy []Remedy
}
Verdict is what one snapshot says.
func Classify ¶
Classify decides what a snapshot says under the limits, for the invocation self. It is a pure function.
A process is a stray when it is older than the stray limit, its lifetime share is at least NearFullShare of its FairShare, and it is not the invocation or one of its ancestors: busy for its share, it uses nearly all the CPU it could get on the machine as loaded, so forty loops each at a fortieth of the machine are all strays, as one loop at a full core of an idle machine is (the product thinker's ruling H1 of 2026-09-25). The one snapshot decides; there is no second sample. The share test applies before the uid split, so the caller's own processes and every other account's are judged alike. Nothing is exempt by name: abcd's own lanes are exempt by time, because everything they start (go, compile, link, vet, the package test binaries) lives for seconds to minutes, so a hung test binary reads as a stray, as the intent's third scope condition says it must. A stray whose effective uid is the caller's is the caller's own; any other uid, root included, is another account's.
The extreme trigger fires when the one-minute load average is strictly above the extreme limit. The five- and fifteen-minute averages remember work that finished long ago, so they are reported and never decide.
type Volume ¶ added in v0.16.0
type Volume struct {
// Path is the path read: the one asked for, or, when it does not exist,
// its nearest existing ancestor (nearestExisting).
Path string
// Free is the bytes an unprivileged writer can still use on the volume
// (the blocks available to a non-root user times the size they are
// counted in), the figure `df` reports as available.
Free uint64
// Total is the volume's size in bytes.
Total uint64
// ID tells two volumes apart: two paths on one volume read the same ID.
// It is "" when the volume reports no identity (volumeID), and a volume
// without one is never taken for another.
ID string
// Mount is where the volume is mounted, when the platform says so cheaply
// (macOS); "" otherwise.
Mount string
}
Volume is one reading of the volume holding a path.
func ReadVolume ¶ added in v0.16.0
ReadVolume reads the volume holding path, or, when path does not exist, the volume holding its nearest existing ancestor. On a platform other than macOS and Linux it reports ErrUnsupported.