From 210f5429678dba06f361b1f37bcb946f27e2e20b Mon Sep 17 00:00:00 2001 From: Arturo Borrero Gonzalez Date: Mon, 12 Jun 2017 10:34:35 +0200 Subject: conntrackd: make the daemon run in RT mode by default In order to prevent netlink buffer overrun, conntrackd is recommended to run at max priority. Make conntrackd to use a RT (SHED_RR) scheduler by default at max priority. This is common among other HA daemons. For example corosync uses SCHED_RR by default. The scheduler configuration option is kept in order to allow admins to perform fine-tuning, but it is deleted from example configuration files. Note that this default sched priority is so high that it makes the nice value useless, so deprecate the nice configuration. Anyway the nice value can be set externally at runtime using nice/renice. The code is moved to the init() routine. In case of error setting the scheduler, the system default will be used. Report a message to the user and continue working. Signed-off-by: Arturo Borrero Gonzalez Signed-off-by: Pablo Neira Ayuso --- src/run.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/run.c') diff --git a/src/run.c b/src/run.c index 1fe6cba..f11a532 100644 --- a/src/run.c +++ b/src/run.c @@ -32,6 +32,7 @@ #include "internal.h" #include "systemd.h" +#include #include #include #include @@ -234,11 +235,35 @@ int evaluate(void) return 0; } + +static void set_scheduler(void) +{ + struct sched_param schedparam; + int sched_type; + + if (CONFIG(sched).type == SCHED_OTHER) { + /* default */ + schedparam.sched_priority = sched_get_priority_max(SCHED_RR); + sched_type = SCHED_RR; + } else { + schedparam.sched_priority = CONFIG(sched).prio; + sched_type = CONFIG(sched).type; + } + + if (sched_setscheduler(0, sched_type, &schedparam) < 0) + dlog(LOG_WARNING, "scheduler configuration failed: %s. " + "Likely a bug in conntrackd, please report it. " + "Continuing with system default scheduler.", + strerror(errno)); +} + int init(void) { do_gettimeofday(); + set_scheduler(); + STATE(fds) = create_fds(); if (STATE(fds) == NULL) { dlog(LOG_ERR, "can't create file descriptor pool"); -- cgit v1.2.3