skills/linux/linux-cgroups/SKILL.md
cgroups v2: memory limits per OpenClaw instance, CPU quotas, OOM protection, systemd slices
npx skillsauth add alphaonedev/openclaw-graph linux-cgroupsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill enables precise resource management for OpenClaw instances using Linux cgroups v2, focusing on memory limits, CPU quotas, OOM (Out-Of-Memory) protection, and systemd slices to prevent resource exhaustion and optimize performance on multi-process systems.
Use this skill when running multiple OpenClaw instances on a Linux server to isolate resources, enforce limits on high-demand tasks, or protect against OOM kills in production environments. Apply it in scenarios with shared hosts, like containers or virtualized setups, to ensure fair CPU and memory allocation.
memory.max to prevent swapping.cpu.max for bandwidth control, limiting CPU time slices.memory.oom.group to prioritize processes and avoid abrupt terminations.To apply cgroups, create a cgroup hierarchy, set limits, and assign processes. Always run as root or with sufficient privileges. For OpenClaw, wrap instance launches in cgroup contexts to enforce per-instance limits. Example: Create a slice for OpenClaw, then assign processes to it. Use Bash scripts for automation, checking cgroup paths under /sys/fs/cgroup/ for v2.
Interact with cgroups via CLI tools or directly via filesystem. No API keys needed; use system-level access.
sudo cgcreate -g memory,cpu:/openclaw_slicesudo cgset -r memory.max=512M /openclaw_slice (limits to 512 MB)sudo cgset -r cpu.max=100000 50000 /openclaw_slice (limits to 1 CPU core at 50% usage)sudo cgexec -g memory,cpu:/openclaw_slice openclaw --run task# Bash example to set and apply memory limit
sudo cgcreate -g memory:/openclaw
sudo cgset -r memory.max=1G /openclaw
sudo cgexec -g memory:/openclaw openclaw --instance id1
# Python snippet using subprocess (requires root)
import subprocess
subprocess.run(['cgcreate', '-g', 'memory:/openclaw'])
subprocess.run(['cgset', '-r', 'memory.max=1G', '/openclaw'])
subprocess.run(['cgexec', '-g', 'memory:/openclaw', 'openclaw', '--instance', 'id1'])
/sys/fs/cgroup/your_slice/memory.max. For systemd, define slices in .slice files under /etc/systemd/system/, like [Slice]\nMemoryMax=512M.Integrate with OpenClaw by wrapping commands in cgroup execution, e.g., modify startup scripts to include cgexec. Ensure the host uses cgroups v2 (check with stat /sys/fs/cgroup/unified); if v1, migrate via systemctl. For multi-instance setups, use environment variables like OPENCLAW_CGROUP_PATH=/openclaw_slice to pass cgroup details. Monitor usage with systemd-cgtop or cat /sys/fs/cgroup/your_slice/memory.current.
Common errors include permission denials (fix with sudo), invalid cgroup paths (verify with ls /sys/fs/cgroup/), or OOM events (check logs with dmesg | grep -i oom). Handle by:
if [ $? -ne 0 ]; then echo "Cgroup creation failed"; ficat /sys/fs/cgroup/your_slice/memory.oom_control and alert if OOM is triggered.systemctl status your_slice for systemd slices; parse errors in code like:
try:
subprocess.run(['cgset', '-r', 'memory.max=1G', '/openclaw'], check=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e.returncode} - {e.output}")
sudo cgcreate -g memory:/openclaw_inst1; sudo cgset -r memory.max=2G /openclaw_inst1; sudo cgexec -g memory:/openclaw_inst1 openclaw --instance inst1 --task process_data. This prevents the instance from exceeding 2GB, avoiding OOM for other processes.sudo cgcreate -g cpu:/openclaw_group; sudo cgset -r cpu.max=200000 100000 /openclaw_group; sudo cgexec -g cpu:/openclaw_group openclaw --instance inst2 --task compute_loop. This enforces a quota of 2 CPU cores at 50% each, ensuring balanced performance across instances.tools
Root web development: project structure, tooling selection, deployment decisions
development
WebAssembly: Rust/Go/C to WASM, wasm-bindgen, Emscripten, WASM Component Model
development
Vue 3: Composition API script setup, Pinia, Vue Router 4, SFCs, Vite, Nuxt 3
tools
Tailwind CSS 4: utility classes, config, JIT, arbitrary values, darkMode, plugins, shadcn/ui