Skip to content

Commit

Permalink
systemd-udevd: limit children-max by available memory (#8668)
Browse files Browse the repository at this point in the history
Udev workers consume typically 50-100MiB virtual memory.
On systems with lots of CPUs and relatively low memory, that may
easily cause workers to be OOM-killed.

This patch limits the number of workers to 8 per GiB memory.
But don't let the limit drop below the smallest value we had
without this patch (8 + 1 * 2 = 10); on small systems, udev's
memory footprint is likely lower.

(cherry picked from commit e438c57)
  • Loading branch information
mwilck authored and keszybz committed Apr 9, 2018
1 parent 63e0c53 commit f398c54
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/udev/udevd.c
Expand Up @@ -1676,12 +1676,16 @@ int main(int argc, char *argv[]) {

if (arg_children_max == 0) {
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) * 2;

mem_limit = physical_memory() / (128LU*1024*1024);
arg_children_max = MAX(10U, MIN(arg_children_max, mem_limit));

log_debug("set children_max to %u", arg_children_max);
}

Expand Down

0 comments on commit f398c54

Please sign in to comment.