From patchwork Thu Sep 7 11:36:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arturo Borrero Gonzalez X-Patchwork-Id: 810976 X-Patchwork-Delegate: pablo@netfilter.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netfilter-devel-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xnz285MZFz9t2W for ; Thu, 7 Sep 2017 21:37:04 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755200AbdIGLhD (ORCPT ); Thu, 7 Sep 2017 07:37:03 -0400 Received: from smtp3.cica.es ([150.214.5.190]:38829 "EHLO smtp.cica.es" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754943AbdIGLhD (ORCPT ); Thu, 7 Sep 2017 07:37:03 -0400 Received: from localhost (unknown [127.0.0.1]) by smtp.cica.es (Postfix) with ESMTP id B32FC51F36C for ; Thu, 7 Sep 2017 11:37:00 +0000 (UTC) X-Virus-Scanned: amavisd-new at cica.es Received: from smtp.cica.es ([127.0.0.1]) by localhost (mail.cica.es [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7Kt3xUDlx6ht for ; Thu, 7 Sep 2017 13:36:55 +0200 (CEST) Received: from nfdev2.cica.es (nfdev2.cica.es [150.214.8.221]) (Authenticated sender: servers@cica.es) by smtp.cica.es (Postfix) with ESMTP id 04E7A51F368 for ; Thu, 7 Sep 2017 13:36:54 +0200 (CEST) Subject: [ulogd2 PATCH] ulogd: use a RT scheduler by default From: Arturo Borrero Gonzalez To: netfilter-devel@vger.kernel.org Date: Thu, 07 Sep 2017 13:36:53 +0200 Message-ID: <150478421358.15825.13845813307098453243.stgit@nfdev2.cica.es> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org Is common that ulogd runs in scenarios where a lot of packets are to be logged. If there are more packets than ulogd can handle, users can start seing log messages like this: ulogd[556]: We are losing events. Please, consider using the clauses \ `netlink_socket_buffer_size' and `netlink_socket_buffer_maxsize' Which means that Netlink buffer overrun have happened. There are several approaches to prevent this situation: * in the ruleset, limit the amount of packet queued for log * in the ruleset, instruct the kernel to use a queue-threshold * from userspace, increment Netlink buffer sizes * from userspace, configure ulogd to run as high priority process The first 3 method can be configured by users at runtime. This patch deals with the last method. SCHED_RR is configured by default, with no associated configuration parameter for users, since I believe this is common enough, and should produce no harm. A similar approach is used in the conntrackd daemon. Signed-off-by: Arturo Borrero Gonzalez --- src/ulogd.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/src/ulogd.c b/src/ulogd.c index b85d0ee..684444f 100644 --- a/src/ulogd.c +++ b/src/ulogd.c @@ -64,6 +64,7 @@ #include #include #include +#include #include #include #ifdef DEBUG @@ -1395,6 +1396,19 @@ static void signal_handler_task(int signal) deliver_signal_pluginstances(signal); } +static void set_scheduler(void) +{ + struct sched_param schedparam; + int sched_type; + + schedparam.sched_priority = sched_get_priority_max(SCHED_RR); + sched_type = SCHED_RR; + + if (sched_setscheduler(0, sched_type, &schedparam) < 0) + fprintf(stderr, "WARNING: scheduler configuration failed:" + " %s\n", strerror(errno)); +} + static void print_usage(void) { printf("ulogd Version %s\n", VERSION); @@ -1589,6 +1603,7 @@ int main(int argc, char* argv[]) signal(SIGALRM, &signal_handler); signal(SIGUSR1, &signal_handler); signal(SIGUSR2, &signal_handler); + set_scheduler(); ulogd_log(ULOGD_INFO, "initialization finished, entering main loop\n");