diff --git a/src/udev/udevd.c b/src/udev/udevd.c index a6f7ee82bb..873d03bc5e 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -69,6 +69,8 @@ #include "udev.h" #include "user-util.h" +#define WORKER_NUM_MAX 2048U + static bool arg_debug = false; static int arg_daemonize = false; static ResolveNameTiming arg_resolve_name_timing = RESOLVE_NAME_EARLY; @@ -1745,16 +1747,18 @@ static int run(int argc, char *argv[]) { return r; if (arg_children_max == 0) { + unsigned long cpu_limit, mem_limit; + unsigned long cpu_count = 1; cpu_set_t cpu_set; - unsigned long mem_limit; - - arg_children_max = 8; if (sched_getaffinity(0, sizeof(cpu_set), &cpu_set) == 0) - arg_children_max += CPU_COUNT(&cpu_set) * 8; + cpu_count = CPU_COUNT(&cpu_set); - mem_limit = physical_memory() / (128LU*1024*1024); - arg_children_max = MAX(10U, MIN(arg_children_max, mem_limit)); + cpu_limit = cpu_count * 2 + 16; + mem_limit = MAX(physical_memory() / (128UL*1024*1024), 10U); + + arg_children_max = MIN(cpu_limit, mem_limit); + arg_children_max = MIN(WORKER_NUM_MAX, arg_children_max); log_debug("Set children_max to %u", arg_children_max); }