memguard
Skill0 starsChanged 46 days agoMITView on GitHub
Prevent memory-overload freezes when STARTING memory-heavy apps on a unified-memory box (DGX Spark / GB10, Jetson). Use before launching/restarting any model, finetune, transcription job, or dev server; when "the box froze when I started X"; when wiring a new service's ExecStart or a cron line on such a host; or when asked to "wrap this so it can't freeze the machine" / "preflight this heavy job" / "is there room to start vLLM". Wrap launches as `memguard run -- CMD`. Pairs with system-performance-remediation, if installed (recovery, when the box is ALREADY thrashing).
1 other project uses a version of this.
Adopted by
Most recently taken up by
- liuhengyuan666/memguardtheir own version, first seen Aug 13, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- liuhengyuan666/memguard★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository51 other files it gives its agents.
- advisor-councilSkill
- advisor-persona-buildSkill
- agent-exploit-pathsSkill
- agentic-loopsSkill
- ai-receptionist-tenant-onboardingSkill
- audit-lensSkill
- beadsmithSkill
- bug-sweepSkill
- bug-zeroSkill
- build-in-public-scope-guardSkill
- consulting-sales-playbookSkill
- deepenSkill
- deposit-first-shippingSkill
- design-intelSkill
- dueling-idea-forgeSkill
- forgeSkill
- hotspot-scoutSkill
- idea-forgeSkill
- incident-zeroSkill
- kickstartSkill
- local-llm-opsSkill
- memory-forgeSkill
- migrate-proofSkill
- no-slop-bug-hunterSkill
- optimize-proofSkill
- perf-maxSkill
- polish-passSkill
- problem-breakthroughSkill
- project-autopilotSkill
- qwen-bug-zeroSkill
- qwen-forgeSkill
- qwen-kickstartSkill
- qwen-perf-maxSkill
- qwen-project-autopilotSkill
- qwen-ship-itSkill
- qwen-ux-maximizerSkill
- readme-realSkill
- reality-checkSkill
- recallSkill
- security-sweepSkill
- session-mineSkill
- ship-itSkill
- simplify-proofSkill
- skillifySkill
- stream-demo-prepSkill
- swarm-runSkill
- test-maxSkill
- trace-itSkill
- unslopSkill
- ux-maximizerSkill
- ux-scanSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 28
Start a heavy app on a near-full pool → the kernel can't reclaim the GPU pages → it drags the slow disk swapfile in → PSI full climbs → …
- Very specific: line 77
Add a profile for a new app before wrapping it.
- Very specific: line 108
If the box is ALREADY thrashing, memguard won't save you: Run /system-performance-remediation (if installed.
- Distinctive: line 113
gpu-heavy mutex: stop one big model server before starting another (e.g.
- Very specific: line 116
Keep vm.swappiness=10 and keep swap present.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
memguard: the memory-overload guardian
Core insight: On a unified-memory box the GPU and system RAM are ONE pool, and a GPU model load is charged through the driver where the cgroup can't see it (a verified 8GiB cudaMalloc moved
memory.currentby only 87MiB). So you can't cap your way to safety; you have to not start the launch that won't fit. The load-bearing defense is a preflight admission gate plus a one-GPU-heavy-app-at-a-time mutex; the cgroup cap and earlyoom are nets underneath, not the primary guard.
The failure mode in three lines
- GPU/unified allocations count against host RAM but are invisible to memcg and to
nvidia-smi(reportsN/Aon UMA; there's no tegrastats on the GB10). - Start a heavy app on a near-full pool → the kernel can't reclaim the GPU pages →
it drags the slow disk swapfile in → PSI
fullclimbs → livelock before any clean GPU-OOM ever fires. The whole box freezes. - The only gauge that tells the truth is
/proc/meminfoMemAvailable+SwapFree(and/proc/pressure/memoryfor early warning). Trust those, nevernvidia-smi.
The one rule
Never launch a memory-heavy app bare on this box. Wrap it:
memguard run --profile my-api -- ./api/start.sh
memguard run --peak 40 -- python train.py # ad-hoc, no profile
memguard check --profile llm-server # dry-run: exit 0/10/20/30
memguard status # mem, PSI, gate, live scopesmemguard run preflights, enforces the gpu-heavy mutex, then launches CMD inside a
rootless cgroup scope (MemoryHigh/MemoryMax, and MemorySwapMax=0 by default; a
per-profile override is allowed, e.g. 8G for a host-swap-tolerant app) with a
raised oom_score so a runaway dies in its own scope, not box-wide. It blocks for CMD's
life (drop-in for a terminal, an ExecStart=, or a cron line). Exit codes: check
returns 0/10/20/30 (run/degrade/queue/abort); run returns the child's exit code on
admit, 20 on queue-expired, 30 on hard abort.
Automatic enforcement (so nobody has to remember the prefix)
memguard install-shell adds a hook to ~/.bashrc that auto-wraps known-heavy
commands you type (ledger apps + ollama run/serve, vLLM, finetune, uvicorn,
pnpm dev, */start.sh, python …train/finetune/serve). Light commands, and anything
with a pipe/redirect/list, run untouched. Bypass one launch with MG=0 <cmd>. This
closes the opt-in hole; the watchdog + earlyoom still cover anything unwrapped.
Integration per launch style
# systemd unit: ExecStart=%h/bin/memguard run --profile X -- /path/to/app
# cron: * * * * * %h/bin/memguard run --profile X -- /path/to/job
# shell / NTM: memguard run --profile X -- <cmd> (or just rely on install-shell)
# agent (gate): memguard check --profile X --json # branch on .decision before launchingAny agent runtime launching heavy work on the box MUST route through
memguard run, or gate with memguard check first. Record this as authoritative
in your shared cross-agent memory file.
The footprint ledger (~/.config/memguard/apps.conf)
One row per app: app|class|peak_gb|low_gb|mutex_group|swapmax|oom_adj|low_env|note.
Add a profile for a new app before wrapping it. Estimate peak_gb generously. It's
the admission gate's only knob, and the GPU side is invisible, so under-guessing is the
one way to defeat the guard. Unprofiled launches fall to [default] (8G, conservative).
class: protected (counted in the math, never auto-killed) vs kill-safe (capped,
may be shed under RED) vs warn (capped, never auto-killed). memguard profiles lists it.
The 3+1 layer model
| Layer | Mechanism | Reliable? |
| L1 preflight admission + gpu-heavy mutex | refuse/queue/degrade before launch on MemAvailable+SwapFree; only one of {vLLM, big-Ollama, finetune} GPU-resident | primary: this is what prevents the freeze |
L2 per-app cgroup scope, MemorySwapMax=0 (default; per-profile override) | runaway dies in its own scope, no box-wide swap thrash | catches HOST-side runaway only (Python heap, dataloaders, mmap); GPU loads are invisible to it |
watchdog memguard monitor | PSI poller; at RED flips the admission-freeze gate (non-destructive, catches unwrapped pressure too) + best-effort sheds largest kill-safe scope | gate-flip reliable; kill best-effort (a userspace reaper can be scheduled out under the very livelock it guards) |
| L3 earlyoom | the one kernel-adjacent reaper; hard floor for anything launched unwrapped | last resort |
Decision reference
- Thresholds (env-overridable): projected-free
≥ SOFT=16G→ RUN_NORMAL;≥ HARD=8G→ DEGRADE;MemAvailable < FLOOR=4G→ ABORT;SwapFree < SWAP_MIN=4G→ never RUN_NORMAL. - PSI watchdog: WARN at
some avg10>15/full>5; RED atfull>40sustained 3 ticks (orMemAvailable<HARD AND SwapFree<SWAP_MIN) → freeze admissions; RECOVER after 8 calm ticks (calm =MemAvailable>SOFT AND SwapFree>SWAP_MIN AND full PSI ≤ WARN, decoupled from the noisysomesignal so the gate actually auto-thaws). - DEGRADE applies the profile's
low_env(e.g.<APP>_FORCE_CPU=1) and caps the scope atlow_gb: smaller footprint instead of refusing outright. A profile withlow_gb=0(e.g. finetune, which can't shrink) keeps its full cap rather than degrading. memguard pause [reason]/resume: manually freeze admissions before a known-huge job (e.g. a finetune) or while debugging.
Composition + hard rules
- If the box is ALREADY thrashing, memguard won't save you. Run
/system-performance-remediation(if installed; otherwise stop the heaviest process by hand) to recover, then relaunch under memguard. - Exactly one reaper. earlyoom only. Do NOT add nohang or systemd-oomd alongside it (double-kills). systemd-oomd is a future swap-not-stack upgrade, not an addition.
- gpu-heavy mutex: stop one big model server before starting another (e.g. stop Ollama to free its memory before vLLM comes up). memguard enforces it; don't run two big models.
- Keep
vm.swappiness=10and keep swap present; add modest zram (seememguard setup) to widen the watchdog/earlyoom reaction window.
First-time setup
memguard setup # installs the user watchdog (rootless); prints the root steps:
# earlyoom retune (-m 8,4 -s 5,2 + avoid/prefer) and zram
memguard verify # smoke-test the primitivesAnti-patterns
- Launching a heavy app bare "just this once". That's the one that freezes the box.
- Trusting
nvidia-smi/cudaMemGetInfofor headroom (N/A / underreports on UMA). - Setting
peak_gbtight to "fit more". The GPU side is uncounted; generous is safe. - Relying on
MemoryMaxto stop a GPU OOM; it can't see the GPU allocation. - Running two gpu-heavy models at once because "there's RAM free right now."
- Adding a second OOM daemon for "extra safety". It double-kills.
References
- system-performance-remediation, if installed: the RECOVERY counterpart (use when already thrashing)
~/bin/memguard: the CLI ·~/.config/memguard/apps.conf: the ledger
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

