diff options
author | Martin Wilck <mwilck@suse.com> | 2018-04-07 17:33:48 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-04-07 17:33:48 +0200 |
commit | e438c57a640ac5afba366531be5e456b9fe22672 (patch) | |
tree | bf05197083bf8ff2bc692e2f0c9a24f2f044228f /src/udev/udevd.c | |
parent | Clarify checker/helper in systemd-fsck@.service manpage (#8674) (diff) | |
download | systemd-e438c57a640ac5afba366531be5e456b9fe22672.tar.xz systemd-e438c57a640ac5afba366531be5e456b9fe22672.zip |
systemd-udevd: limit children-max by available memory (#8668)
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.
Diffstat (limited to '')
-rw-r--r-- | src/udev/udevd.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 254a72556e..006cdd3501 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -1673,12 +1673,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); } |