Expand description
The memory watchdog (see archive/PROJECT.md, Worker memory protection and crash recovery): every task shares the pod’s memory, and the kernel’s out-of-memory killer would take every task and the agent with it, so the agent measures each task and kills only the one over its budget.
- The limit is the smallest cgroup v2
memory.maxfrom the agent’s own cgroup up to the root (/proc/self/cgroup), so it is found in a pod and on a host alike. None found (max, cgroup v1): no task is killed but one asking for its own budget, peak memory is still measured. No/proc: nothing is measured and nothing is killed. - The budget per task is its own (
memory=, decision 436), else[worker] memory_budget, else (limit − 10 %) ÷ slots. A task asking for more than the limit less the reserve is turned away (decision 437); its cleanup, moved here, gets at most that. - A task’s memory is the PSS (
/proc/<pid>/smaps_rollup) of every process in its process group (what SIGTERM and SIGKILL reach), RSS where PSS can’t be read: PSS splits shared pages between the processes sharing them, so a tree isn’t counted many times. Not for a forked task: its RSS counts the pages it shares with its fork server, so a sample without every PSS is skipped (no kill on it). - Sampling every
memory_check_interval(1 s); over the budget the group is killed at once (SIGKILL: a spike can’t wait for a grace period), and the attempt endsoom_killed. The highest sample is the attempt’s peak memory.
Structs§
- Group
Watch - A group’s watch, running until it is dropped (so a process group ID the kernel gives to someone else later is never watched, let alone killed).
- Memory
Seen - What the watchdog saw of one attempt.
- Memory
Watch - How the watchdog watches.
- Running
Memory - The running tasks’ memory, each named, as their watchdogs last measured it (decision 463): what the heartbeat reports (cheap to clone; clones share it).
- Watched
- A task in
RunningMemoryuntil it is dropped.
Enums§
- Reserve
- The part of the pod’s memory limit kept out of the task budgets: for schedr’s own process (the agent, and in standalone the master and the API too).
Constants§
- MIN_
BUDGET - The smallest
[worker] memory_budgetaccepted: below it no Python process starts. - STANDALONE_
RESERVE - The reserve of
schedr standalone(its process also runs the master and the API) when[worker] memory_reserveisn’t set. - WORKER_
RESERVE - The reserve of
schedr workerwhen[worker] memory_reserveisn’t set.
Functions§
- budget
- Each task’s budget:
configured, else (limit−reserve) ÷slots;Nonewithout either. - ceiling
- The most one task may take of
limit: whatreserveleaves (decision 437). - cgroup_
current - The memory of the agent’s own cgroup v2 now (its
memory.current, from its line in<proc_root>/self/cgroup);Noneoutside a cgroup v2 or where it can’t be read. - cgroup_
limit - The smallest cgroup v2
memory.maxon the way from the agent’s cgroup (in<proc_root>/self/cgroup) up tocgroup_root;Nonewhen there is none (unlimited, cgroup v1). - group_
memory - The memory of the processes in group
pgid, in bytes (PSS, else RSS whererss_fallback); 0 when none is left. A zombie counts as nothing.Nonewhen a process’s PSS can’t be read and RSS mustn’t stand in: a forked process’s RSS counts the pages it shares with its fork server (most of the server’s), so it would look far bigger than it is. - node_
usage - This process’s memory and CPU from
proc_root(self/stat,self/statm), in pages ofpagebytes andticksa second, and its container’s fromcgroup_root(decision 463);Nonewithout/proc. - over_
budget - Samples group
pgideverywatch.interval, recording the peak inseen; completes with the sample once one is over the budget (never without a budget). A sample that can’t be read (seegroup_memory) is skipped: no kill on a guess. - over_
budget_ message - The message of an attempt killed for its memory.
- process_
group - The process group in a
/proc/<pid>/statline (field 5; the command, field 2, is in parentheses and may hold spaces or parentheses itself). - show_
size bytesas people read sizes:512 B,64 KiB,1.5 GiB.- this_
node node_usageof this process, from/procand/sys/fs/cgroup.- watch_
group - Watches group
pgid(recording inseen) from now until the returned watch is dropped: over the budget it tellsstop(StopReason::OomKilled), kills the group at once (SIGKILL) and counts it inkills. The reason goes first, so the supervisor has it before the process’s end. Started as soon as the process is, it covers a runner’s start and a stopped task’s grace period too.forked: the group’s processes share pages with a fork server, so RSS never stands in for PSS (seegroup_memory).
Type Aliases§
- Shared
Seen - The watchdog’s record of one attempt, shared with whoever reports it.