makepkg-cg is a wrapper around makepkg that uses Control Groups via systemd.resource-control to manage resource usage during package building. It helps Arch users to build packages while keeping resource usage within reasonable limits.
- Limit CPU usage to a defined percentage of total available CPU resources
- Limit RAM usage to a defined percentage of total available memory
- Set I/O priority and CPU scheduling policy
- Configurable resource limits through a user configuration file
- systemd
- bash
Follow the instructions in the dist/arch/PKGBUILD file to build and install the makepkg-cg package.
It is recommended to also increase the priority of session.slice
to see the
most benefit to system stability:
diff --git a/usr/lib/systemd/user/session.slice b/usr/lib/systemd/user/session.slice
index aa12b7d..1a96695 100644
--- a/usr/lib/systemd/user/session.slice
+++ b/usr/lib/systemd/user/session.slice
@@ -12,4 +12,5 @@ Description=User Core Session Slice
Documentation=man:systemd.special(7)
[Slice]
-CPUWeight=100
+CPUWeight=1000
+IOWeight=1000
makepkg-cg provides a default configuration file located at doc/makepkg-cg.conf.
You can customize the resource limits by creating a new configuration file at
$HOME/.config/makepkg-cg.conf
.
The configuration options include:
CPU_PERCENT
: CPU usage quota (percentage, will be multiplied by nproc)RAM_PERCENT
: RAM usage considered high above (percentage)RAM_MAX
: RAM usage maximum (percentage)IO_LEVEL
: I/O priority level (0-7, lower values have higher priority)IO_CLASS
: I/O classCPU_POLICY
: CPU scheduling policy
Example configuration:
#!/bin/bash
# makepkg-cg configuration file
CPU_PERCENT=75
RAM_PERCENT=75
RAM_MAX=90
IO_LEVEL=7
IO_CLASS=idle
CPU_POLICY=idle
Once installed, use makepkg-cg in place of makepkg when building packages. The command accepts the same arguments as makepkg. Resource limits will be applied based on the configuration file.
makepkg-cg <makepkg_arguments>
Feel free to contribute to the project by opening pull requests or reporting issues on the project's GitHub repository.
Note: The eBPF support is currently non-functional. That's as good a place to start as any.
Copyright 2023 Fredrick R. Brennan
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this software or any of the provided source code files except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
By contributing you release your contribution under the terms of the license.