Answer principles round 1: 0 🔴, 4 🟡 (0 misread); exempt only a bare docker under run-heavy with no PATH of its own, drop the stale item citation, unit-test the slot share in MiB, place the limits by the subcommand's index; also a named Option, exit 126, clearer names and the launcher's import order

This commit is contained in:
2026-10-24 11:31:10 +02:00
parent 2eb6fc828f
commit 2fa328a406
16 changed files with 144 additions and 72 deletions
+17 -10
View File
@@ -9,12 +9,17 @@ $XDG_STATE_HOME/run-heavy (default ~/.local/state/run-heavy). While every slot i
says so once on stderr and waits. It then replaces itself with the command. The slot's lock stays held
until the command, and every process that inherited the lock, exits. Its exit code is the command's.
Each container the command makes with docker run or docker create gets a memory limit and a swap limit,
both the slot's share, where it sets neither: three quarters of the machine's memory, split across the
slots. A docker first on the command's PATH adds them, and passes every other call on unchanged. A
container that sets one of the two limits keeps it, and gets the other as large; an unlimited
swap, --memory-swap -1, gives way. The share is in RUN_HEAVY_MEMORY. A docker compose service,
or a docker named by its full path, gets no limit.
On Linux, run-heavy also caps the memory of each container the command makes with docker run or
docker create. The cap is the slot's share: three quarters of the machine's memory, split evenly
across the slots, handed to the command in RUN_HEAVY_MEMORY, in MiB. run-heavy puts its own docker
first on the command's PATH. That docker adds the limits a container lacks, then runs the real one:
- A container that sets neither limit gets a memory limit and a swap limit, both the share.
- A container that sets one of them keeps it, and gets the other at the same size.
- A --memory-swap of -1, unlimited swap, is dropped and replaced.
Every other docker call goes through unchanged. A docker compose service, and a docker named by its
full path, get no cap: give those containers their own limits.
A command it runs carries the slot's number in RUN_HEAVY_SLOT, and run-heavy called with that set
runs its command at once, so a gate that wraps its own steps cannot wait on itself.
@@ -24,12 +29,13 @@ folder or a slot file cannot be made or locked; 126 when the command is found bu
"""
import os
import pathlib
import shutil
import sys
import typing
from failure import Failure
from run_heavy.capped_docker import FOLDER, SHARE
from machine_load.memory import Memory
from run_heavy.capped_docker import PATH_ENTRY, SHARE_VARIABLE, without_path_entry
from machine_load.slots import slot_count, slot_folder, waited_slot
OWN_FAILURE = 125
@@ -56,10 +62,11 @@ def main(argv: list[str], env: typing.Mapping[str, str], cpus: int | None, memor
def capping(memory: Memory | None, slots: int, env: typing.Mapping[str, str]) -> dict[str, str]:
"""What the command's environment needs for its docker to cap each container it makes at the slot's share of memory; nothing where the memory is unknown, as off Linux."""
if memory is None:
"""What the command's environment needs for its docker to cap each container it makes at the slot's share of memory; nothing where the memory is unknown, as off Linux, or where PATH finds no docker to cap."""
path = env.get("PATH", "")
if memory is None or shutil.which("docker", path=without_path_entry(path)) is None:
return {}
return {SHARE: memory.slot_share(slots), "PATH": os.pathsep.join([str(FOLDER), env.get("PATH", "")])}
return {SHARE_VARIABLE: str(memory.slot_share(slots)), "PATH": os.pathsep.join([str(PATH_ENTRY), path])}
def held_slot(folder: pathlib.Path, slots: int) -> int | Failure: