From patchwork Fri Nov 6 20:32:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 11888053 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BF87314C0 for ; Fri, 6 Nov 2020 20:32:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5EEB121556 for ; Fri, 6 Nov 2020 20:32:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tQ8gw4rh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5EEB121556 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7001B6B0036; Fri, 6 Nov 2020 15:32:45 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6B0716B005C; Fri, 6 Nov 2020 15:32:45 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 59F696B005D; Fri, 6 Nov 2020 15:32:45 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0083.hostedemail.com [216.40.44.83]) by kanga.kvack.org (Postfix) with ESMTP id 2B9456B0036 for ; Fri, 6 Nov 2020 15:32:45 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B8781181AEF07 for ; Fri, 6 Nov 2020 20:32:44 +0000 (UTC) X-FDA: 77455141848.25.body43_23102ab272d5 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 8E7111804E3A1 for ; Fri, 6 Nov 2020 20:32:44 +0000 (UTC) X-Spam-Summary: 1,0,0,c38bfb7cc824c4b6,d41d8cd98f00b204,minchan.kim@gmail.com,,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1311:1314:1345:1437:1515:1535:1544:1605:1711:1730:1747:1777:1792:1801:2196:2199:2393:2559:2562:2899:3138:3139:3140:3141:3142:3355:3865:3866:3867:3870:3871:3872:4118:4250:4321:4385:4605:5007:6119:6261:6653:7875:10004:11026:11232:11473:11658:11914:12043:12291:12296:12297:12438:12517:12519:12555:12895:12986:13894:14096:14181:14394:14721:21080:21324:21444:21451:21627:21740:21795:21966:21990:30045:30051:30054:30070,0,RBL:209.85.210.195:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100;04yg5auzr4udzr1cp1uiiuzn53ikbopb1dqkwqopnpx37wg8d7bs9wrf3w8uq8o.uadwpn5ukwxgdrsz47fnise4o6jtjz7f99g1imrqxjokqyrcjs8b7znzkykuuu4.4-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:70,LUA_SUMMARY:none X-HE-Tag: body43_23102ab272d5 X-Filterd-Recvd-Size: 7158 Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Fri, 6 Nov 2020 20:32:44 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id 13so2442310pfy.4 for ; Fri, 06 Nov 2020 12:32:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PkvXPr5zRt9c79wXe0lFh0HyRUZh0ALu/SSWSOopLw8=; b=tQ8gw4rhQ/+f7Nz4CZr/cHFXTIVQI/1xVvlm+geWQV8vn9+NVunE6e7B4GTxLnpXI3 oNnjddkVVzaBGyZ8qmLOFucUZML2wRgpEgL/E3svpGXZxxwKoRrnh3DUI0U+OYYqHXmv 2+1sox+YaZZWS6OMQ1KepWmVle7q/AgVODVNNuw8069XNls3sVAEqvCUW4XzRotTdpS5 9disIfZ50fg1r5ovJBc+S8F/jalVg7m5FuRYCmZFASkhaWDi32uRo+ZYQeiUKJH/oXDA dpmKAi+mcD6DiJoM5YrYh4l8Bg1zFhgDNvjgx2zq6R3vUZZCm/QZbo4oTw2zhcu6SzaP WPKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=PkvXPr5zRt9c79wXe0lFh0HyRUZh0ALu/SSWSOopLw8=; b=syN63WtI81jM8VpLHx3cSfEirqgSiSLkptlIdXr9vv2b3jJbZx31DLiNcwEnt+UjVU TquMA5draKkyUx/qNuQiyeuigb7qIqGZ5qsHmGfBfsReeRY6nBeFEl3/H2npISQHA9OR MnWvC9CzRDq1Baklwlx6/XWduVrjX/MshH0xbaauavW9UEdv0XAGdkHd5L/MaOv/zCHd W5LZ5NJ4tQY7cCDmlG0eLTP3Nm37JfrinrJqiHj0Xgx+yU0D1T+7CI63O/Ft2qntT0so OQy3ZQLi+uOSoEOhMNbJF9PkKRveIl7AzzzWm7R/mnlTq6Q71t3ppReaeaH1pey/zzCT 2RTg== X-Gm-Message-State: AOAM531eqzh5el9YlJvEEYoJTpbUFBNsgMmKjADSgVdTya09EVqByBZF 6+EQdeuR+o0vfRxqFILk6lo= X-Google-Smtp-Source: ABdhPJwolHgUPm3z0zvjns3t/ctGcn7N/1qwo5ZoF1k4A2Q46/r2fi1fftA958FBqgwopJv40WWqBg== X-Received: by 2002:a17:90a:fe07:: with SMTP id ck7mr1405212pjb.212.1604694762984; Fri, 06 Nov 2020 12:32:42 -0800 (PST) Received: from bbox-1.mtv.corp.google.com ([2620:15c:211:201:7220:84ff:fe09:5e58]) by smtp.gmail.com with ESMTPSA id v126sm3150538pfb.137.2020.11.06.12.32.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2020 12:32:41 -0800 (PST) From: Minchan Kim To: Andrew Morton Cc: LKML , linux-mm , Michal Hocko , Minchan Kim Subject: [PATCH] mm: introduce oom_kill_disable sysctl knob Date: Fri, 6 Nov 2020 12:32:38 -0800 Message-Id: <20201106203238.1375577-1-minchan@kernel.org> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog MIME-Version: 1.0 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: It's hard to have some tests to be supposed to work under heavy memory pressure(e.g., injecting some memory hogger) because out-of-memory killer easily kicks out one of processes so system is broken or system loses the memory pressure state since it has plenty of free memory soon so. Even though we could mark existing process's oom_adj to -1000, it couldn't cover upcoming processes to be forked for the job. This knob is handy to keep system memory pressure. Signed-off-by: Minchan Kim --- Documentation/admin-guide/sysctl/vm.rst | 14 ++++++++++++++ include/linux/mm.h | 2 ++ include/linux/oom.h | 1 + kernel/sysctl.c | 9 +++++++++ mm/oom_kill.c | 24 ++++++++++++++++++++++++ 5 files changed, 50 insertions(+) diff --git a/Documentation/admin-guide/sysctl/vm.rst b/Documentation/admin-guide/sysctl/vm.rst index f455fa00c00f..49dcedfaf0c0 100644 --- a/Documentation/admin-guide/sysctl/vm.rst +++ b/Documentation/admin-guide/sysctl/vm.rst @@ -694,6 +694,20 @@ is used in oom_kill_allocating_task. The default value is 0. +oom_kill_disable +================ + +This disables or enables OOM killing in out-of-memory situations. + +If this is set to one, the OOM killer is disabled so OOM kill never +hapens in out-of-memory situation. It could cause system dangerous +state due to memory allocation failure so user should be careful to +use it. + +If this is set to zero, the OOM killer is enabled so OOM kill happens +in out-of-memory situations. + +The default value is 0. overcommit_kbytes ================= diff --git a/include/linux/mm.h b/include/linux/mm.h index db6ae4d3fb4e..a98400cee341 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -215,6 +215,8 @@ int overcommit_kbytes_handler(struct ctl_table *, int, void *, size_t *, loff_t *); int overcommit_policy_handler(struct ctl_table *, int, void *, size_t *, loff_t *); +int oom_kill_disable_handler(struct ctl_table *, int, void *, size_t *, + loff_t *); #define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n)) diff --git a/include/linux/oom.h b/include/linux/oom.h index 2db9a1432511..0f378498e6aa 100644 --- a/include/linux/oom.h +++ b/include/linux/oom.h @@ -126,5 +126,6 @@ extern struct task_struct *find_lock_task_mm(struct task_struct *p); /* sysctls */ extern int sysctl_oom_dump_tasks; extern int sysctl_oom_kill_allocating_task; +extern int sysctl_oom_kill_disable; extern int sysctl_panic_on_oom; #endif /* _INCLUDE_LINUX_OOM_H */ diff --git a/kernel/sysctl.c b/kernel/sysctl.c index afad085960b8..1fe872fe1c05 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -2690,6 +2690,15 @@ static struct ctl_table vm_table[] = { .mode = 0644, .proc_handler = proc_dointvec, }, + { + .procname = "oom_kill_disable", + .data = &sysctl_oom_kill_disable, + .maxlen = sizeof(sysctl_oom_kill_disable), + .mode = 0644, + .proc_handler = oom_kill_disable_handler, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, { .procname = "oom_dump_tasks", .data = &sysctl_oom_dump_tasks, diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 8b84661a6410..0f48cdeeb1e7 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -53,6 +53,7 @@ int sysctl_panic_on_oom; int sysctl_oom_kill_allocating_task; +int sysctl_oom_kill_disable; int sysctl_oom_dump_tasks = 1; /* @@ -72,6 +73,29 @@ static inline bool is_memcg_oom(struct oom_control *oc) return oc->memcg != NULL; } +int oom_kill_disable_handler(struct ctl_table *table, int write, void *buffer, + size_t *lenp, loff_t *ppos) +{ + int ret; + + ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); + if (ret || !write) + goto out; + if (sysctl_oom_kill_disable == 1) { + if (!oom_killer_disable(HZ)) + ret = -EBUSY; + } else { + if (mutex_lock_killable(&oom_lock)) { + ret = -EBUSY; + goto out; + } + oom_killer_enable(); + mutex_unlock(&oom_lock); + } +out: + return ret; +} + #ifdef CONFIG_NUMA /** * oom_cpuset_eligible() - check task eligiblity for kill