From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2F89C433E7 for ; Tue, 13 Oct 2020 11:01:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 12FA22173E for ; Tue, 13 Oct 2020 11:01:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 12FA22173E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0CC56940007; Tue, 13 Oct 2020 07:01:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 07D05900002; Tue, 13 Oct 2020 07:01:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EAE00940007; Tue, 13 Oct 2020 07:01:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0153.hostedemail.com [216.40.44.153]) by kanga.kvack.org (Postfix) with ESMTP id BED1E900002 for ; Tue, 13 Oct 2020 07:01:51 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 559E83625 for ; Tue, 13 Oct 2020 11:01:51 +0000 (UTC) X-FDA: 77366612022.23.root95_47113b327202 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 3722637604 for ; Tue, 13 Oct 2020 11:01:51 +0000 (UTC) X-HE-Tag: root95_47113b327202 X-Filterd-Recvd-Size: 5422 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Tue, 13 Oct 2020 11:01:50 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: rcn) with ESMTPSA id 55D651F44E6D From: =?UTF-8?q?Ricardo=20Ca=C3=B1uelo?= To: akpm@linux-foundation.org Cc: kernel@collabora.com, hch@lst.de, guro@fb.com, rientjes@google.com, mcgrof@kernel.org, keescook@chromium.org, yzaikin@google.com, linux-mm@kvack.org, sergey.senozhatsky@gmail.com, pmladek@suse.com, rostedt@goodmis.org, mhocko@suse.com Subject: [PATCH v2] mm, oom: enable rate-limiting controls for oom dumps Date: Tue, 13 Oct 2020 13:01:23 +0200 Message-Id: <20201013110123.30689-1-ricardo.canuelo@collabora.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add two sysctl entries (vm.oom_dump_ratelimit and vm.oom_dump_ratelimit_burst) to control the rate limiting interval and burst, respectively, of the OOM killer output (oom_kill_process()). These entries are disabled by default and can be enabled during kernel configuration with CONFIG_DUMP_RATELIMIT. They take DEFAULT_RATELIMIT_INTERVAL and DEFAULT_RATELIMIT_BURST as their default values. In some setups, the amount of output that the OOM killer generates when it kills a process and dumps the list of tasks can be too large. Unfortunately, the rate-limiting used for it uses the default values for the rate limit interval and burst. This patch allows the user to configure these values. Signed-off-by: Ricardo Ca=C3=B1uelo --- I'm sending this v2 because I found a mistake in the first version: the oom_dump_ratelimit sysctl parameter must use proc_dointvec_jiffies instead of proc_dointvec so that the user can use it to specify the number of seconds easily. I also added the rationale to the commit log as Michal suggested and moved the config option to mm/Kconfig.debug as suggested by Sergey: I personally like this patch. There are no universal ratelimit values, so having some sort of user configuration makes sense. One thing - I think that config option should be in mm/Kconfig.debug but I'd like to keep the discussion open as there seem to be many different opinions about this topic. Cheers, Ricardo include/linux/oom.h | 2 ++ kernel/sysctl.c | 16 ++++++++++++++++ mm/Kconfig.debug | 9 +++++++++ mm/oom_kill.c | 5 +++++ 4 files changed, 32 insertions(+) diff --git a/include/linux/oom.h b/include/linux/oom.h index 2db9a1432511..76c560a1a4c7 100644 --- a/include/linux/oom.h +++ b/include/linux/oom.h @@ -127,4 +127,6 @@ extern struct task_struct *find_lock_task_mm(struct t= ask_struct *p); extern int sysctl_oom_dump_tasks; extern int sysctl_oom_kill_allocating_task; extern int sysctl_panic_on_oom; +extern int sysctl_oom_dump_ratelimit; +extern int sysctl_oom_dump_ratelimit_burst; #endif /* _INCLUDE_LINUX_OOM_H */ diff --git a/kernel/sysctl.c b/kernel/sysctl.c index ce75c67572b9..dd51a7e26a54 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -2708,6 +2708,22 @@ static struct ctl_table vm_table[] =3D { .mode =3D 0644, .proc_handler =3D proc_dointvec, }, +#ifdef CONFIG_OOM_DUMP_RATELIMIT + { + .procname =3D "oom_dump_ratelimit", + .data =3D &sysctl_oom_dump_ratelimit, + .maxlen =3D sizeof(sysctl_oom_dump_ratelimit), + .mode =3D 0644, + .proc_handler =3D proc_dointvec_jiffies, + }, + { + .procname =3D "oom_dump_ratelimit_burst", + .data =3D &sysctl_oom_dump_ratelimit_burst, + .maxlen =3D sizeof(sysctl_oom_dump_ratelimit_burst), + .mode =3D 0644, + .proc_handler =3D proc_dointvec, + }, +#endif { .procname =3D "overcommit_ratio", .data =3D &sysctl_overcommit_ratio, diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug index 864f129f1937..93207f26d57a 100644 --- a/mm/Kconfig.debug +++ b/mm/Kconfig.debug @@ -170,3 +170,12 @@ config PTDUMP_DEBUGFS kernel. =20 If in doubt, say N. + +config OOM_DUMP_RATELIMIT + bool "Enable rate limiting for OOM dumps" + default n + help + Say Y here to enable the configuration of the rate limiting of + OOM task dumps to the console through sysctl entries + vm.oom_dump_ratelimit (rate limit interval) and + vm.oom_dump_ratelimit_burst (rate limit burst). diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 8b84661a6410..2b3fa826a172 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -54,6 +54,8 @@ int sysctl_panic_on_oom; int sysctl_oom_kill_allocating_task; int sysctl_oom_dump_tasks =3D 1; +int sysctl_oom_dump_ratelimit =3D DEFAULT_RATELIMIT_INTERVAL; +int sysctl_oom_dump_ratelimit_burst =3D DEFAULT_RATELIMIT_BURST; =20 /* * Serializes oom killer invocations (out_of_memory()) from all contexts= to @@ -959,6 +961,9 @@ static void oom_kill_process(struct oom_control *oc, = const char *message) static DEFINE_RATELIMIT_STATE(oom_rs, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST); =20 + oom_rs.interval =3D sysctl_oom_dump_ratelimit; + oom_rs.burst =3D sysctl_oom_dump_ratelimit_burst; + /* * If the task is already exiting, don't alarm the sysadmin or kill * its children or threads, just give it access to memory reserves --=20 2.18.0