gentle.sh#
Run commands with limited system resources to prevent builds from hammering system responsiveness.
Table of Contents#
Background#
When running large builds or heavy computational workloads, system responsiveness can suffer. gentle.sh wraps any command in a systemd-run scope with aggressive resource limits to keep your system usable while the build runs.
Install#
No installation required - the script is in the repository root:
chmod +x gentle.sh
Usage#
./gentle.sh <command> [args...]
Resource Limits#
The following resource controls are applied to all commands run through gentle.sh:
CPU Limits#
- CPU Affinity: All CPUs except first 2 (keeps cores 0-1 free for system), specified as range
2-15 - CPU Scheduling:
SCHED_BATCHviachrt -b 0- batch scheduling for non-interactive workloads - CPU Weight:
1- minimum weight (1-10000 range) - CPU Quota Period:
300ms- period for quota measurement - Nice Level:
19- lowest nice priority
I/O Limits#
- IO Weight:
1(default 1) - minimum weight (1-10000 range), set post-launch via cgroup - IO Priority Class:
idle- lowest IO priority class, set post-launch via cgroup - IO Device Latency:
60sapplied to all detected block devices
Memory Limits#
- MemoryMax:
80%- cap at 80% of system memory - TasksMax:
infinity- unlimited processes
Examples#
Build a large project without freezing your system:
./gentle.sh make -j8
Run a compilation:
./gentle.sh ./build.sh
Run with multiple arguments:
./gentle.sh ninja -C build all
Run a CMake configuration:
./gentle.sh cmake -B build -DCMAKE_BUILD_TYPE=Release
Notes#
- The script uses
systemd-run --scope --user, which runs commands in the foreground - CPU scheduling policy is set to
SCHED_BATCHviachrt -b 0wrapper - IO properties (
io.weightandio.prio.class) are set post-launch via direct cgroup writes - Block devices are auto-detected using
lsblkand IO latency targets are set for all drives - Temporary files use
XDG_RUNTIME_DIR(or$HOME/.tmpas fallback) for user-isolated storage - All resource limits are applied to the process and its children