Skip to content

Conversation

@AKhozya
Copy link

@AKhozya AKhozya commented Dec 25, 2025

Summary

This PR adds a -C option to set a CPU quota on systemd-nspawn build containers, similar to the existing -M option for memory limits.

Motivation

When running rebuilderd on a shared server, it's useful to limit CPU usage to prevent resource contention with other services. The existing -M option provides memory limits, but there's no equivalent for CPU.

Changes

  • Added MAX_CPU environment variable support
  • Added -C <value> command-line option (e.g., -C 500% for 5 cores)
  • CPU quota is passed to systemd-nspawn via --property="CPUQuota=..."

Usage

# Command line
repro -C 500% package.pkg.tar.zst         # Limit to 5 CPU cores
repro -C 1200% -M 24G package.pkg.tar.zst # 12 cores, 24GB RAM

# Environment variable (useful for systemd services)
Environment=MAX_CPU=500%

Testing

Tested on Arch Linux with rebuilderd:

  • Verified nspawn containers receive the --property=CPUQuota=... argument
  • Verified cgroup cpu.max is correctly set (e.g., 500000 100000 for 500%)
  • Builds complete successfully with CPU limits applied
$ ps aux | grep nspawn
systemd-nspawn -q --as-pid2 --register=no --pipe --property=CPUQuota=500% ...
$ cat /sys/fs/cgroup/.../cpu.max
500000 100000

Similar to the existing -M option for memory limits, this adds a -C option
to set a CPU quota on the systemd-nspawn build containers.

This is useful for rebuilderd setups where you want to limit CPU usage
to prevent resource contention with other services on the same machine.

Usage:
  repro -C 500% package.pkg.tar.zst      # Limit to 5 CPU cores
  repro -C 1200% -M 24G package.pkg.tar.zst  # 12 cores, 24GB RAM

The CPU quota is passed to systemd-nspawn via --property="CPUQuota=...",
which sets the cgroup cpu.max limit on the container.

Environment variable MAX_CPU can also be used (e.g., in systemd service files):
  Environment=MAX_CPU=500%
@AKhozya
Copy link
Author

AKhozya commented Dec 25, 2025

@jelly @Foxboron please review, this one helps me to avoid all CPU consumed in my homelab so k8s resouces don't degrade in peaks :)

Copy link
Member

@Foxboron Foxboron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but generally I suspect we should figure out if naming the systemd-nspawn session and/or advicing people to run this under systemd-run is better then trying to include all the different systemd options into repro.sh.

@AKhozya
Copy link
Author

AKhozya commented Dec 25, 2025

Thanks! Yep, that makes sense for the future. If no other comments - would be great to have it merged and potential new release :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants