agents: always write the memory cap, infinity for none
The cap file was removed for a cap of `infinity` or a RAM percentage, so the boot check warned on every start of such an agent, for a legitimate config. The file is now written on every start: - a size: its byte count, as before; - `infinity`: the literal `infinity`. The generators set no JSC heap ceiling and no subagent MemoryHigh=, and the boot check is quiet; - a percentage: resolved on the host the way systemd resolves MemoryMax=N% for the container@ unit. That is permyriad (at most two decimals, at most 100%) of sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE), rounded down to a page; - a value systemd ignores (zero, over 100%, more than two decimals, unparseable) leaves the unit uncapped, so it is `infinity`. The file is missing only when hive-c0re can't tell the cap: the limits file and the kept drop-in are both unreadable, or a percentage meets an unknown host memory size. The boot check now warns only for a missing file or a first line that is neither a byte count nor `infinity`. Part of #5081 (slice S0-2).
This commit is contained in:
parent
57955a6c53
commit
eaca3c4eb3
5 changed files with 253 additions and 67 deletions
|
|
@ -3,10 +3,11 @@
|
|||
#
|
||||
# The cap is `MemoryMax=` on the host's `container@` unit, which nothing in
|
||||
# here can read: `/sys/fs/cgroup/memory.max` reads `max` at every level from
|
||||
# inside. hive-c0re writes its byte count to `/run/hive/memory-max-bytes`
|
||||
# before every start (`lifecycle::host_config`), and removes the file when the
|
||||
# cap is `infinity` or a RAM percentage. Two values are derived from it, and
|
||||
# neither is set without the file; `hyperhive-memory-cap-check` then logs a
|
||||
# inside. Before every start hive-c0re (`lifecycle::host_config`) writes it to
|
||||
# `/run/hive/memory-max-bytes` as a byte count, a percentage resolved against
|
||||
# the host's RAM as systemd resolves it, or `infinity` for no cap. Two values
|
||||
# are derived from a byte count, and neither is set for `infinity`. A missing
|
||||
# or malformed file sets neither too, and `hyperhive-memory-cap-check` logs a
|
||||
# warning at boot:
|
||||
#
|
||||
# - `BUN_JSC_forceRAMSize`, 75% of the cap. Bun/JavaScriptCore, the runtime
|
||||
|
|
@ -29,13 +30,15 @@
|
|||
# `checks.module-eval-agent-memory`.
|
||||
{ pkgs, ... }:
|
||||
let
|
||||
# Sets `bytes`, or runs `noCap` when there is no file or its first line is
|
||||
# not a plain byte count. A leading zero would read as octal, and 16 digits
|
||||
# or more could overflow `bytes * 75`. Shell builtins only.
|
||||
# Sets `bytes`. Exits for `infinity`, and runs `noCap` when there is no file
|
||||
# or its first line is neither `infinity` nor a plain byte count. A leading
|
||||
# zero would read as octal, and 16 digits or more could overflow
|
||||
# `bytes * 75`. Shell builtins only.
|
||||
readCap = noCap: ''
|
||||
bytes=
|
||||
[ -r /run/hive/memory-max-bytes ] && read -r bytes < /run/hive/memory-max-bytes
|
||||
case "$bytes" in
|
||||
infinity) exit 0 ;;
|
||||
"" | 0* | *[!0-9]* | ????????????????*) ${noCap} ;;
|
||||
esac
|
||||
'';
|
||||
|
|
@ -55,16 +58,16 @@ let
|
|||
'';
|
||||
|
||||
# The generators run before the container's journal starts and an nspawn
|
||||
# container has no /dev/kmsg, so the boot warning for an unusable cap comes
|
||||
# from a unit. `<4>` is the journal's warning priority.
|
||||
# container has no /dev/kmsg, so the boot warning for a missing or malformed
|
||||
# cap file comes from a unit. `<4>` is the journal's warning priority.
|
||||
check = pkgs.writeShellScript "hyperhive-memory-cap-check" ''
|
||||
${readCap ''
|
||||
if [ -e /run/hive/memory-max-bytes ]; then
|
||||
why="does not start with a plain byte count"
|
||||
why="holds neither a byte count nor infinity"
|
||||
else
|
||||
why="is missing"
|
||||
fi
|
||||
echo "<4>/run/hive/memory-max-bytes $why: no BUN_JSC_forceRAMSize heap ceiling and no MemoryHigh= on hive-subagent-daemon; the host's MemoryMax= on the container still applies. hive-c0re writes no file for a cap of infinity or a RAM percentage." >&2
|
||||
echo "<4>/run/hive/memory-max-bytes $why: no BUN_JSC_forceRAMSize heap ceiling and no MemoryHigh= on hive-subagent-daemon; the host's MemoryMax= on the container still applies." >&2
|
||||
exit 0
|
||||
''}
|
||||
'';
|
||||
|
|
|
|||
Loading…
Reference in a new issue