1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//! What the host's memory leaves runners beside its other programs (ADR 0055): the slice's runners may hold what
//! they hold now without page cache plus the host's `MemAvailable`, less a margin kept for the host's page cache, so
//! reclaim stays cheap; and nothing starts while the host, short of memory, stalls for it. Each bound has
//! hysteresis, so a host at the edge does not start and hold runners by turns. A host whose memory can grow to a
//! ceiling, `[host] memory_ceiling` (ADR 0084), counts what it can still grow by as available and keeps the margin of
//! its ceiling; the stall rule reads the memory the host has now. Pure: the engine passes in the reading, with the ceiling,
//! and what it remembers of the last plan.
use crate;
/// Starts stop once every runnable task of the host waits for memory this share of the last 10 s, in hundredths of
/// a percent: 5%, while the host is short of memory (`stalls`).
pub const STALL_ENTER: u32 = 500;
/// Once stopped, starts resume when that share falls under this: 1%.
pub const STALL_LEAVE: u32 = 100;
/// The margin kept free at least: 2G.
const MARGIN_MIN: u64 = 2 << 30;
/// The margin as a share of the host's memory, as a divisor: a sixteenth, 4G of 64G.
const MARGIN_SHARE: u64 = 16;
/// What admission remembers of the host from the last plan.
/// The margin `MemAvailable` keeps beside the runners' predicted peaks for a host with `total` memory: the larger of
/// `MARGIN_MIN` and `total / MARGIN_SHARE`, half again as much while the host is `short`.
/// Whether `memory`'s stall shares say the host stalls for memory, given whether it did at the last plan. A stall
/// counts only while `MemAvailable` is under twice the margin: the shares are the whole host's, and a runner
/// reclaiming at its own cap raises them with memory to spare, which starts elsewhere do not make worse. A ceiling
/// changes nothing here (ADR 0084): what the host could still grow by is not available, and a stall while it is
/// short says the hypervisor is not giving it.
/// What `memory` lets the slice's runners hold in all: what the slice holds now without page cache plus
/// `MemAvailable` and what the host can still grow by (`HostMemory::growable`), less the margin of the host's memory
/// at its ceiling, larger while the host is `short`. Without a ceiling above `MemTotal`, the slice and
/// `MemAvailable` less the margin of `MemTotal`.
/// What `memory` leaves runners beside the `reserved` memory of what runs in the slice, given what the last plan
/// `remembered`.
/// What a host `limit` leaves new runners beside the `reserved` memory of what runs in the slice: negative by what
/// they reserve past it, none while the host is `stalled`. A runner that stops gives its reservation back to this,
/// so a deficit stays owed rather than hidden by `HostBudget::spare`, which stops at 0.
/// What `memory` leaves a new runner beside the `reserved` memory of what runs or is reserved for before it starts,
/// such as the mirror: `budget`'s `spare` with no wait or stall remembered and none now. Beside only the mirror's
/// cap, the room of the first runner into an empty slice, which `runnerd init` sizes a starter runner within and
/// `runnerd doctor` checks profiles against.