diff options
author | Matt Whitlock <distcc@mattwhitlock.name> | 2021-09-04 20:39:12 -0400 |
---|---|---|
committer | Matt Whitlock <distcc@mattwhitlock.name> | 2021-09-04 20:39:12 -0400 |
commit | 9699301fc3f16ef34570fa53e0863a2b91cdd3a6 (patch) | |
tree | 1b1d32b8e46dbed7f5430be696b3358429573dc1 /src/dopt.c | |
parent | b83d607b65d879c1bca5933dcc6ca1689b073646 (diff) | |
download | distcc-git-9699301fc3f16ef34570fa53e0863a2b91cdd3a6.tar.gz |
distccd: add --oom-score-adj option (Linux only)
This new option sets /proc/self/oom_score_adj in prefork worker child
processes. This can afford users a bit of protection against a scenario
in which many concurrent compilation jobs cause an out-of-memory
condition that prompts the kernel's OOM killer to kill a process that is
not so "disposable" as a distccd worker.
This commit adds a new Autoconf test to check whether the host system
type (that is, the type of the system on which the compiled binaries are
to be run) is Linux. The new --oom-score-adj option is implemented only
if the host system type is Linux.
Diffstat (limited to 'src/dopt.c')
-rw-r--r-- | src/dopt.c | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -33,6 +33,7 @@ #include <fcntl.h> #include <errno.h> #include <popt.h> +#include <limits.h> #include <sys/socket.h> #include <netinet/in.h> @@ -49,6 +50,10 @@ int opt_niceness = 5; /* default */ +#ifdef HAVE_LINUX +int opt_oom_score_adj = INT_MIN; /* default is not to change */ +#endif + /** * Number of children running jobs on this machine. If zero (recommended), * then dynamically set from the number of CPUs. @@ -154,6 +159,9 @@ const struct poptOption options[] = { { "no-detach", 0, POPT_ARG_NONE, &opt_no_detach, 0, 0, 0 }, { "no-fifo", 0, POPT_ARG_NONE, &opt_no_fifo, 0, 0, 0 }, { "no-fork", 0, POPT_ARG_NONE, &opt_no_fork, 0, 0, 0 }, +#ifdef HAVE_LINUX + { "oom-score-adj",0, POPT_ARG_INT, &opt_oom_score_adj, 0, 0, 0 }, +#endif { "pid-file", 'P', POPT_ARG_STRING, &arg_pid_file, 0, 0, 0 }, { "port", 'p', POPT_ARG_INT, &arg_port, 0, 0, 0 }, #ifdef HAVE_GSSAPI @@ -191,6 +199,9 @@ static void distccd_show_usage(void) #endif " -P, --pid-file FILE save daemon process id to file\n" " -N, --nice LEVEL lower priority, 20=most nice\n" +#ifdef HAVE_LINUX +" --oom-score-adj ADJ set OOM score adjustment, -1000 to 1000\n" +#endif " --user USER if run by root, change to this persona\n" " --jobs, -j LIMIT maximum tasks at any time\n" " --job-lifetime SECONDS maximum lifetime of a compile request\n" |