De-prioritizing a systemd-run job
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Shell 100.0%
3 1 0

Clone this repository

https://tangled.org/jauntywk.bsky.social/gentle-run https://tangled.org/did:plc:zjbq26wybii5ojoypkso2mso/gentle-run
git@tangled.org:jauntywk.bsky.social/gentle-run git@tangled.org:did:plc:zjbq26wybii5ojoypkso2mso/gentle-run

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

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_BATCH via chrt -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: 60s applied 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_BATCH via chrt -b 0 wrapper
  • IO properties (io.weight and io.prio.class) are set post-launch via direct cgroup writes
  • Block devices are auto-detected using lsblk and IO latency targets are set for all drives
  • Temporary files use XDG_RUNTIME_DIR (or $HOME/.tmp as fallback) for user-isolated storage
  • All resource limits are applied to the process and its children