Documentation
¶
Overview ¶
Package admit decides when a command may start (spec 6.2, 6.6).
Index ¶
- func IsHigh(e *config.Effective) bool
- func LegacyHolders(c *config.Compat) []string
- func LegacySlotLock(c *config.Compat, stem string, n int) string
- func PruneDead(l state.Layout, pool string, ticket func(name string), reaped func(job string))
- func ReadMemory(root string) (avail int64, readable bool, source string)
- type CompatLocks
- type Hold
- type MemoryGate
- type Request
- type Ticket
- type TicketFile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsHigh ¶
IsHigh reports whether the caller is high priority: a high_cwd_contains entry is a literal substring of the logical or canonical cwd, or a high_cwd glob matches either (spec 6.2).
func LegacyHolders ¶
LegacyHolders lists held legacy locks for status and doctor. It only observes (HeldRO): a legacy `flock -n` racing it never finds a free lock busy.
func LegacySlotLock ¶ added in v0.1.2
LegacySlotLock is <legacy_dir>/locks/<stem>.<n>.lock: the one place that format lives, shared by admission (pool slots and group units) and status (legacy holders).
Types ¶
type CompatLocks ¶
type CompatLocks interface {
TrySlot(pool string, slot int) (release func(), ok bool, err error)
TryUnit(group string, unit int, supervisorPid int) (release func(), ok bool, err error)
MirrorHigh(pool string, pid int) (remove func(), err error)
RemoveMirror(pool string, pid int)
LegacyHigh(pool string) bool
VerifiedClaim(env []string) (group string, ok bool)
HoldEnv(units map[string][]int) string
}
CompatLocks makes bitc and a legacy flock pool exclude each other (spec 12).
type Hold ¶
type Hold struct {
Pool string
Slot int // 1..N
Ticket string
Token string // 32 hex
Nested bool
Depth int // 0 for a top-level hold
Units map[string][]int
WaitMS int64
Started time.Time
ExtraEnv []string // extra KEY=VALUE for the command ([compat] hold_env)
// contains filtered or unexported fields
}
Hold is an admitted ticket: slot and group units taken, command about to run.
func Acquire ¶
Acquire queues for a slot of r.Pool and returns the hold, or exit.Starved at the deadline.
func (*Hold) SetProcess ¶
SetProcess records the command in the ticket for orphan reaping: its pid and start time, and its process group (0 when the command shares the caller's group, a TTY run: then only the command and its descendants may be reaped, never the caller's group).
type MemoryGate ¶
type MemoryGate struct {
ProcfsRoot string // stands in for "/" ("" = "/")
Floor int64 // bytes; 0 disables
Window time.Duration
ReservationsPath string
Warn io.Writer
// contains filtered or unexported fields
}
MemoryGate is the memory step of an attempt (spec 6.2); it runs under admit.lock.
func (*MemoryGate) Check ¶
Check: admit iff available - reservations within the window >= floor (spec 6.2).
func (*MemoryGate) Drop ¶
func (g *MemoryGate) Drop(ticket string) error
Drop removes ticket's reservation at the end of its hold.
type Request ¶
type Request struct {
Layout state.Layout
Eff *config.Effective
Pool *config.Pool
Argv []string
Job string
CallerHold string // the caller's BITC_HOLD ("" if unset)
CallerEnv []string // for compat claims (12)
Stderr io.Writer // warnings and reap notes
Now func() time.Time
OnReap func(pool, job string) // called after a dead hold's group is reaped (history "reaped")
}
Request is one admission attempt loop for one pool.
type Ticket ¶
type Ticket struct {
Pid int `json:"pid"`
Start uint64 `json:"start"` // /proc/<pid>/stat field 22
Argv []string `json:"argv"`
Cwd string `json:"cwd"`
Job string `json:"job"`
Class int `json:"class"` // 0 high, 1 normal
Nested bool `json:"nested"`
Depth int `json:"depth"`
State string `json:"state"` // "waiting" | "running"
GroupWait []string `json:"group_wait,omitempty"`
Slot int `json:"slot,omitempty"`
Groups map[string][]int `json:"groups,omitempty"`
Inherited []string `json:"inherited_groups,omitempty"` // groups an ancestor holds; never unlocked here
Token string `json:"token"`
Leader int `json:"leader,omitempty"` // the command's pid
Pgid int `json:"pgid,omitempty"` // 0: the command shares the caller's group (TTY)
LeaderStart uint64 `json:"leader_start,omitempty"`
HoldStarted int64 `json:"hold_started,omitempty"` // unix ns
WaitStarted int64 `json:"wait_started"` // unix ns
}
Ticket is a waiter's file, flocked by its owner for its whole life (spec 6.2).
type TicketFile ¶
TicketFile is a ticket read from disk with its name.
func ReadTickets ¶
func ReadTickets(l state.Layout, pool string) []TicketFile
ReadTickets returns the live tickets of pool in (class, time) order, pruning dead ones is not done here (callers hold admit.lock and call prune first).
func VerifyHold ¶
func VerifyHold(l state.Layout, value string) (*TicketFile, bool)
VerifyHold checks a BITC_HOLD claim (spec 6.6): the ticket exists in this state dir under a bare name, is flocked now, holds the same token, and its (pid, start) is an ancestor of this process. Anything else is ignored silently.