Answer architecture round 1: 0 🔴, 3 🟡 (0 misread); keep the slot's share beside ROOM_SHARE in machine_load, move the rule's predicate into rule_hook, and have capped set both limits itself instead of leaning on docker taking the last option

This commit is contained in:
2026-10-24 11:24:21 +02:00
parent 4c1ab3f185
commit 52641079b7
7 changed files with 60 additions and 31 deletions
+5 -1
View File
@@ -1,4 +1,4 @@
"""How much of the machine's memory is available, as /proc/meminfo's MemAvailable and MemTotal state it, and whether at least ROOM_SHARE of it is available, which leaves room for a worker."""
"""How much of the machine's memory is available, as /proc/meminfo's MemAvailable and MemTotal state it, whether at least ROOM_SHARE of it is available, which leaves room for a worker, and each heavy slot's share of the rest."""
import dataclasses
import pathlib
import re
@@ -17,6 +17,10 @@ class Memory:
def has_room(self) -> bool:
return self.available >= ROOM_SHARE * self.total
def slot_share(self, slots: int) -> str:
"""The memory each heavy slot's containers may take, as docker writes a size: what ROOM_SHARE leaves, split evenly across the slots."""
return f"{int(self.total * (1 - ROOM_SHARE)) // slots // 1024}m"
def parsed(meminfo: str) -> Memory | None:
"""The memory a /proc/meminfo text states; None where it lacks MemAvailable or MemTotal."""