Skip to main content

Module memory

Module memory 

Source
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.max from 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 ends oom_killed. The highest sample is the attempt’s peak memory.

Structs§

GroupWatch
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).
MemorySeen
What the watchdog saw of one attempt.
MemoryWatch
How the watchdog watches.
RunningMemory
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 RunningMemory until 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_budget accepted: 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_reserve isn’t set.
WORKER_RESERVE
The reserve of schedr worker when [worker] memory_reserve isn’t set.

Functions§

budget
Each task’s budget: configured, else (limit − reserve) ÷ slots; None without either.
ceiling
The most one task may take of limit: what reserve leaves (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); None outside a cgroup v2 or where it can’t be read.
cgroup_limit
The smallest cgroup v2 memory.max on the way from the agent’s cgroup (in <proc_root>/self/cgroup) up to cgroup_root; None when there is none (unlimited, cgroup v1).
group_memory
The memory of the processes in group pgid, in bytes (PSS, else RSS where rss_fallback); 0 when none is left. A zombie counts as nothing. None when 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 of page bytes and ticks a second, and its container’s from cgroup_root (decision 463); None without /proc.
over_budget
Samples group pgid every watch.interval, recording the peak in seen; completes with the sample once one is over the budget (never without a budget). A sample that can’t be read (see group_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>/stat line (field 5; the command, field 2, is in parentheses and may hold spaces or parentheses itself).
show_size
bytes as people read sizes: 512 B, 64 KiB, 1.5 GiB.
this_node
node_usage of this process, from /proc and /sys/fs/cgroup.
watch_group
Watches group pgid (recording in seen) from now until the returned watch is dropped: over the budget it tells stop (StopReason::OomKilled), kills the group at once (SIGKILL) and counts it in kills. 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 (see group_memory).

Type Aliases§

SharedSeen
The watchdog’s record of one attempt, shared with whoever reports it.