admit

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 25 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package admit decides when a command may start (spec 6.2, 6.6).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Aged added in v0.1.6

func Aged(e *config.Effective, now time.Time, t Ticket) bool

Aged reports whether t is a normal ticket that has waited priority.aging as of now (aging scaled by [test] time_scale; 0 turns aging off). An aged ticket queues as a high one does.

func FlockSlotPath added in v0.1.6

func FlockSlotPath(fl config.Flock, slot int) string

FlockSlotPath is the slot file i of a [compat.flock] pool: the one place the template lives, used by admission. Status does not call it: status and doctor do not show shell holders of a flock pool (spec 12.2).

func IsHigh

func IsHigh(e *config.Effective) bool

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

func LegacyHolders(c *config.Compat) []string

LegacyHolders lists held legacy locks for status and doctor. It only observes (lock.Inspect): a legacy `flock -n` racing it never finds a free lock busy. A lock it cannot inspect (no /proc/locks, #24) is not listed: doctor says so once, and status shows the pool slot as unknown.

func LegacySlotLock added in v0.1.2

func LegacySlotLock(c *config.Compat, stem string, n int) string

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).

func PruneDead

func PruneDead(l state.Layout, pool string, ticket func(name string), reaped func(job string))

PruneDead prunes pool's dead tickets under admit.lock. It calls reaped(job) for each dead hold whose process group prune killed (spec 3.3) and ticket(name) for each removed ticket.

func QueueBefore added in v0.1.6

func QueueBefore(e *config.Effective, now time.Time, a, b TicketFile) bool

QueueBefore reports whether a queues ahead of b as of now: the order is (effective class, WaitStarted, name). Admission and status both order tickets by it.

func ReadMemory

func ReadMemory(root string) (avail int64, readable bool, source string)

ReadMemory returns min(MemAvailable, tightest cgroup v2 headroom) in bytes.

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)
	// HasFlock reports whether [compat.flock] names pool (spec 12.2).
	HasFlock(pool string) bool
	// FlockExclusive reports the pool's [compat.flock.<pool>] exclusive key (default false).
	FlockExclusive(pool string) bool
	// FlockSlotFile is the path of the pool's slot file i.
	FlockSlotFile(pool string, slot int) string
	// TryFlock takes the shared pool's gate and lock without blocking: gate shared, then lock
	// shared (the gate is let go once the lock is held), or gate and lock exclusive. busy names the
	// file that was not free.
	TryFlock(pool string, exclusive bool) (release func(), busy string, 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).

func NewCompat

func NewCompat(c *config.Compat, _ state.Layout) CompatLocks

NewCompat returns nil when compat mode is off.

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
	Counts  map[string]int // units held per group (the ticket's Units; nil when none)
	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

func Acquire(ctx context.Context, r Request) (*Hold, error)

Acquire queues for a slot of r.Pool and returns the hold, or exit.Starved at the deadline.

func (*Hold) EnvValue

func (h *Hold) EnvValue() string

EnvValue is BITC_HOLD: "<pool>:<ticket>:<token>" (spec 6.3).

func (*Hold) Release

func (h *Hold) Release()

Release ends the hold; it is idempotent.

func (*Hold) SetProcess

func (h *Hold) SetProcess(pid, pgid int, leaderStart uint64) error

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

func (g *MemoryGate) Check(now time.Time) (bool, string, error)

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.

func (*MemoryGate) Reserve

func (g *MemoryGate) Reserve(now time.Time, ticket string, bytes int64) error

Reserve records bytes for ticket at admission.

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"`
	Units       map[string]int   `json:"units,omitempty"`            // units asked for per group (held once running); inherited groups omitted
	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

type TicketFile struct {
	Name string
	Pool string
	T    Ticket
}

TicketFile is a ticket read from disk with its name.

func ReadTickets

func ReadTickets(l state.Layout, pool string) []TicketFile

ReadTickets returns the tickets of pool in ticket-name order (the class digit, then the wait-start time); admission orders them by effective class (see attempt and ticketBefore in admit.go). 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.

Jump to

Keyboard shortcuts

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