fix: size the model pool from the cgroup memory limit - #6
Merged
Conversation
Inside a container sysinfo's available_memory() reports the host, so a service started with --memory=1g on a large machine sized its pool for the whole machine, loaded several instances, was OOM-killed and restart-looped at full CPU. Take the smaller of host-available and cgroup-free memory for both the pool and sub-batch budgets, and warn when even a single instance is estimated to exceed the budget.
Greptile SummaryThis PR makes model-pool and request sub-batch sizing respect cgroup memory availability rather than relying solely on host-reported memory.
Confidence Score: 5/5The PR appears safe to merge; the previously reported low-memory batching issue is resolved and no new actionable failures were identified. The current implementation derives both pool and sub-batch capacity from the lower of host-available and cgroup-free memory, and zero or very small reported budgets now produce the minimum sub-batch of one instead of the unsafe fallback of 32. The previous thread was manually resolved after this correction. Important Files Changed
Reviews (5): Last reviewed commit: "fix: treat zero available memory as exha..." | Re-trigger Greptile |
loks0n
approved these changes
Sep 4, 2026
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The pool sizer and sub-batch sizer read
System::available_memory(), which inside a container reports the host, not the cgroup. Runningappwrite/embedding:0.1.0with--memory=1gon a 20 GB Docker host logsavailable_mb=10945, pickspool_size=2, loads ~1.6 GB of model instances, gets OOM-killed, and withrestart: unless-stoppedloops at ~100% CPU (8 restarts in 30 s in my repro). Anymem_limitan operator sets in Compose is therefore ignored by the sizer.This surfaced in a self-hosted Appwrite report where a 4 GB Hetzner box ran out of memory and the kernel OOM-killed
mysqldduring a function build.Fix
Take the minimum of host-available and
cgroup_limits().free_memory(sysinfo already honoursmemory.max/memory.limit_in_bytes, falling back to host total when unlimited) for both the pool budget and the sub-batch budget. Also emit a warning when a single instance is estimated to exceed the budget, since that is the case where the container can still be killed under load, and let the sub-batch shrink to one text so a small budget is never exceeded by the batch floor.Verification
Patched image under
--memory=1g:0 restarts, 854 MiB steady. The same run on 0.1.0 reports
available_mb=10770.Unit tests cover the budget function for no cgroup, cgroup below host, and unlimited cgroup above host.
cargo clippy --all-targets -- -D warningsandcargo testpass on rustc 1.95.