From: Michael Tremer Date: Fri, 19 Aug 2022 11:08:11 +0000 (+0000) Subject: build: Make cgroup parameters configurable X-Git-Tag: 0.9.28~435 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a1284fff2720ad60af20d6d6faab99dfb55f62e;p=pakfire.git build: Make cgroup parameters configurable Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 92a6fde8d..c79645fdd 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -47,7 +47,7 @@ #define CCACHE_DIR "/var/cache/ccache" // We guarantee 2 GiB of memory to every build container -#define PAKFIRE_BUILD_GUARANTEED_MEMORY (size_t)2 * 1024 * 1024 * 1024 +#define PAKFIRE_BUILD_MEMORY_GUARANTEED (size_t)2 * 1024 * 1024 * 1024 // We allow only up to 2048 processes/threads for every build container #define PAKFIRE_BUILD_PID_LIMIT (size_t)2048 @@ -810,6 +810,7 @@ static int pakfire_build_set_default_target(struct pakfire_build* build) { Sets up a new cgroup for this build */ static int pakfire_build_setup_cgroup(struct pakfire_build* build) { + struct pakfire_config* config = NULL; char path[PATH_MAX]; int r; @@ -817,7 +818,7 @@ static int pakfire_build_setup_cgroup(struct pakfire_build* build) { r = pakfire_string_format(path, "pakfire/build-%s", build->_id); if (r) { ERROR(build->pakfire, "Could not compose path for cgroup: %m\n"); - return 1; + goto ERROR; } // Create a new cgroup @@ -825,21 +826,37 @@ static int pakfire_build_setup_cgroup(struct pakfire_build* build) { PAKFIRE_CGROUP_ENABLE_ACCOUNTING); if (r) { ERROR(build->pakfire, "Could not create cgroup for build %s: %m\n", build->_id); - return r; + goto ERROR; } + // Fetch config + config = pakfire_get_config(build->pakfire); + if (!config) + goto ERROR; + // Guarantee some minimum memory - r = pakfire_cgroup_set_guaranteed_memory(build->cgroup, PAKFIRE_BUILD_GUARANTEED_MEMORY); - if (r) - return r; + size_t memory_guaranteed = pakfire_config_get_bytes(config, "build", + "memory_guaranteed", PAKFIRE_BUILD_MEMORY_GUARANTEED); + if (memory_guaranteed) { + r = pakfire_cgroup_set_guaranteed_memory(build->cgroup, memory_guaranteed); + if (r) + goto ERROR; + } // Set PID limit - r = pakfire_cgroup_set_pid_limit(build->cgroup, PAKFIRE_BUILD_PID_LIMIT); - if (r) - return r; + size_t pid_limit = pakfire_config_get_int(config, "build", + "pid_limit", PAKFIRE_BUILD_PID_LIMIT); + if (pid_limit) { + r = pakfire_cgroup_set_pid_limit(build->cgroup, pid_limit); + if (r) + goto ERROR; + } - // Done - return 0; +ERROR: + if (config) + pakfire_config_unref(config); + + return r; } /* diff --git a/tests/pakfire.conf b/tests/pakfire.conf index df7a47d9a..286e70d8b 100644 --- a/tests/pakfire.conf +++ b/tests/pakfire.conf @@ -7,3 +7,11 @@ version_id = 1 codename = Blah vendor = Test Project slogan = Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live + +[build] + +# Guaranteed memory for the build environment +memory_guaranteed = 256M + +# PID limit for the build environment +pid_limit = 512