Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751416AbdFASgj (ORCPT ); Thu, 1 Jun 2017 14:36:39 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:52005 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751230AbdFASg2 (ORCPT ); Thu, 1 Jun 2017 14:36:28 -0400 Authentication-Results: kvack.org; dkim=none (message not signed) header.d=none;kvack.org; dmarc=none action=none header.from=fb.com; From: Roman Gushchin To: CC: Roman Gushchin , Tejun Heo , Johannes Weiner , Li Zefan , Michal Hocko , Vladimir Davydov , Tetsuo Handa , , , , Subject: [RFC PATCH v2 4/7] mm, oom: introduce oom_kill_all_tasks option for memory cgroups Date: Thu, 1 Jun 2017 19:35:12 +0100 Message-ID: <1496342115-3974-5-git-send-email-guro@fb.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496342115-3974-1-git-send-email-guro@fb.com> References: <1496342115-3974-1-git-send-email-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [2620:10d:c092:200::1:ebb3] X-ClientProxiedBy: DB6PR07CA0129.eurprd07.prod.outlook.com (10.170.219.22) To DM3PR15MB1081.namprd15.prod.outlook.com (10.166.160.135) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM3PR15MB1081: X-MS-Office365-Filtering-Correlation-Id: cc576b54-56ce-468d-6e9d-08d4a91d08d9 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075)(201703031133081);SRVR:DM3PR15MB1081; X-Microsoft-Exchange-Diagnostics: 1;DM3PR15MB1081;3:Qq6D7yZ9tUG/4BwdQrGbO+wuaKcxU9JR2i8NQrIg1XtebYD6kEAps0z3/8MASKOpEnjHP27Y3hb0iLyX2E6adPyuAxr2vE9tGeTBK3BV04bccnY2XsNV8QrMfLmfSnPaRSahKOPX7C8TbzuAZvQMzaZ4Pn6k/RqHL4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vuyke+jljBMbUWwFiOX0yCX3LJ4BmnVK9IJV9TuFKiFJRahjZhKO/QJOazybGMNHtyE0GkPqTc++2WulfwJtEB48hfGjvlFqE66JMGm+iSkHZtQL2tbuzzyGyDJBfWboWjHcqR5ufOi1MggeuvFW7FtNCHjXqIyd1+DfF/jUJrhnUEq1FIquB4xl+4Q5NA7gfBH0REdzCUkNRYFzoLq/UTlmzo0GFNX+GXyGMkhMekTCMZucj7aISPG09+sFP803iGtjrcHQLXry3h/xZLI9WSQQDJevQJGO1jEccN9KJgEMJ6U4n3hwyIxfUhBTD0kJ5moqpvOGbkZZw/YopVg76Yc/TEmw46xwSyOb8tE95fnOkDSAz/0OU X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(50582790962513)(67672495146484); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(93006095)(93001095)(10201501046)(3002001)(6041248)(20161123558100)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123562025)(20161123555025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:DM3PR15MB1081;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:DM3PR15MB1081; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM3PR15MB1081;4:LHzLbLXfe4HMpZXi4Ta/v5Xz0DG34tDPo2uDZGZa3e?= =?us-ascii?Q?AJn4cY6uBNMhi7uf1s90E+WXovcnAmi0W3UF7DPoltW3yc11qpabWpDmV65p?= =?us-ascii?Q?+FPM/Qxwp8W/+Rr2IACtj1emx4KRM5D6dU7QV9Mid52waLYfgSerfD7S+Oz8?= =?us-ascii?Q?UXVJEaexrimfECMoZfb++8KJ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x9LIC7yULgt3oIh6rfuFmnw3aIo6jWNBTbI0j+lFb9PdFBaIn75?= =?us-ascii?Q?8kFnXFq70AoxZXHxeEbv5IawnyIxJE5767ANVf09rGxIJ2yMeR7OUpwfqhGJ?= =?us-ascii?Q?D3h6jpDN1BIEcY3x3z2bqbvKRQlxQ7LjNImGN1pBxRv9wV+Xbw/dBxw0bk6E?= =?us-ascii?Q?sbHdLiLVVxrfXtbBs=3D?= X-Forefront-PRVS: 0325F6C77B X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(39450400003)(39400400002)(39850400002)(39840400002)(39410400002)(33646002)(5003940100001)(2351001)(6666003)(6116002)(305945005)(2950100002)(6506006)(2361001)(86362001)(6486002)(6916009)(5660300001)(8676002)(6512007)(50466002)(42186005)(48376002)(7416002)(54906002)(53416004)(81166006)(76176999)(50986999)(38730400002)(25786009)(47776003)(2906002)(53936002)(50226002)(110136004)(478600001)(7736002)(189998001)(36756003)(4326008)(217873001)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:DM3PR15MB1081;H:castle.thefacebook.com;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM3PR15MB1081;23:st2EoTrAgub6wKLLQXd2YWUoh+0ZY3qS5c6cfRSkW?= =?us-ascii?Q?27FXbh6QB7EcO7F3mnSKzVuc6FJSZodKuE0iLEetKayR7KqmJFdVW7jA5Jh1?= =?us-ascii?Q?iucDsLuqw13rgmWIlBE6azXdYYn3y+1XC5xwlRYCJLSkmjIbuEbV305BWv08?= =?us-ascii?Q?NpK0TYAt3nqj+9sysTYAFkhLy6bOPdtEv9TINJ8wR2DrwtW4wqSrdlEpjlCn?= =?us-ascii?Q?OTKjktl8U/foNcUmtTuy+uixndSpD4nSFYexvjUhildU3uLDbVjwQ0OH/8iw?= =?us-ascii?Q?KwS99C76mGP/YDR/DhmjQKWjp/La7f+QjvTcuFoT5R6CTxHLnrOBp/s/O2Q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Mbonqyoih6gL2VKm8H6AssE8Wh5OtJrvPnukYZw1Dqusk1l3IBA7UKL4c5DYY+TVrIJB4CK34COdLrK4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DM3PR15MB1081;7:d5cAj5vEQ3GVC9XoivvBIosR+Ro20b+dT21qvYwyZjKmvJ6Nfk6cWBoTfg9/h20PO8NcmpzstQ9/XCfHi+EZ+tXZ3oLYNqDj9ilJWwFZ23Ph5rvLk7t/nyeBZs9Q4vR78WAgw9AWwwxkAubHaos7RPWLHwfaWIwrX4G9QBJRDoWZOi595fPW0BbhGhfljI+16akuvV44H3uoSoAV44HeOju9vJx1iEdFaPwKQa0mEv2NGzEwiWU/KgIAZIbWNhfEWE9vpUkzf5uKYXbb2QFXqtQ54iADhV4xUu9wQRGac3n12k1AXoI9AfZ4DgZEv64k5pcRSPVosMlte6KJuKa0Zg==;20:YxTM9cIr2wRuHTgfSyKQjlsPO+Nv7jd2nYGc9ePtE6BIKKuOHEJAewtVTXz7CEF1QN6CLRHajbQREo6YG9ptwuN9eJPF00mMAytaspDBbmIk1xfWREbpjTqBltxh84rChUIbE2ODcR2RQVDp8vd7ZSvG0MBv3Y/RZAvYFGdtHKc= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jun 2017 18:35:51.6026 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR15MB1081 X-OriginatorOrg: fb.com X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-06-01_04:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2675 Lines: 93 This option defines whether a cgroup should be treated as a single entity by the OOM killer. If set, the OOM killer will compare the whole cgroup with other memory consumers (other cgroups and tasks in the root cgroup), and in case of an OOM will kill all belonging tasks. Disabled by default. Signed-off-by: Roman Gushchin Cc: Tejun Heo Cc: Johannes Weiner Cc: Li Zefan Cc: Michal Hocko Cc: Vladimir Davydov Cc: Tetsuo Handa Cc: kernel-team@fb.com Cc: cgroups@vger.kernel.org Cc: linux-doc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org --- include/linux/memcontrol.h | 3 +++ mm/memcontrol.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 899949b..8a308c9 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -195,6 +195,9 @@ struct mem_cgroup { /* OOM-Killer disable */ int oom_kill_disable; + /* kill all tasks below in case of OOM */ + bool oom_kill_all_tasks; + /* handle for "memory.events" */ struct cgroup_file events_file; diff --git a/mm/memcontrol.c b/mm/memcontrol.c index c131f7e..d4ffa79 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5156,6 +5156,33 @@ static ssize_t memory_max_write(struct kernfs_open_file *of, return nbytes; } +static int memory_oom_kill_all_tasks_show(struct seq_file *m, void *v) +{ + struct mem_cgroup *memcg = mem_cgroup_from_css(seq_css(m)); + bool oom_kill_all_tasks = memcg->oom_kill_all_tasks; + + seq_printf(m, "%d\n", oom_kill_all_tasks); + + return 0; +} + +static ssize_t memory_oom_kill_all_tasks_write(struct kernfs_open_file *of, + char *buf, size_t nbytes, + loff_t off) +{ + struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of)); + int oom_kill_all_tasks; + int err; + + err = kstrtoint(strstrip(buf), 0, &oom_kill_all_tasks); + if (err) + return err; + + memcg->oom_kill_all_tasks = !!oom_kill_all_tasks; + + return nbytes; +} + static int memory_events_show(struct seq_file *m, void *v) { struct mem_cgroup *memcg = mem_cgroup_from_css(seq_css(m)); @@ -5265,6 +5292,12 @@ static struct cftype memory_files[] = { .write = memory_max_write, }, { + .name = "oom_kill_all_tasks", + .flags = CFTYPE_NOT_ON_ROOT, + .seq_show = memory_oom_kill_all_tasks_show, + .write = memory_oom_kill_all_tasks_write, + }, + { .name = "events", .flags = CFTYPE_NOT_ON_ROOT, .file_offset = offsetof(struct mem_cgroup, events_file), -- 2.7.4