Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751351AbdFASgd (ORCPT ); Thu, 1 Jun 2017 14:36:33 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:33756 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751237AbdFASgX (ORCPT ); Thu, 1 Jun 2017 14:36:23 -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 5/7] mm, oom: introduce oom_score_adj for memory cgroups Date: Thu, 1 Jun 2017 19:35:13 +0100 Message-ID: <1496342115-3974-6-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: be60329d-513c-4055-4e8b-08d4a91d0a20 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075)(201703031133081);SRVR:DM3PR15MB1081; X-Microsoft-Exchange-Diagnostics: 1;DM3PR15MB1081;3:4lDG7+IDA+8VRU4fT4SD18q6JGyBNSXIfnEPDWkVPdbgmRmwX+jt+4q1mR2L17HHpiEGthXB6tGEkJaneq/384s10J1xmPm2s4PPjbSiCfjoAMAykSB6wHblXLgmfPtaEVT8KSJnoEu0PY4o2qLKUcwhqXaRJcwAsfGmubEtJZkx2pP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G90zptiK7p6o8XVpZgQGCKtjnvqj6NC+8NTKCuaRq+RRLCCP2817j0fdZK8gFEdK0iS6oqjaBEMxBQQr7az7rnwZWAdYfiOMGpSiMFryimHpO5Zejyyx54mxXTZjSzXuOaw3uT5ouX6DzqYhauGaPSbjLJ3ymCQpNemNEpUVKOhiqI5wjG/1GyykfJHQzv7ybRH4aVMq2oLDLtYFcxn4s4GBCMtArHLK7cz9so+VI+95BxeGMwADzSi6YGTcoagBlQe9F65GK4Cn9c9+rILnjHlhmkVCfdZBFOlK04irfpW/d9FPV5Mys9B83ziVuPJ/LoGZxgxIah+UOqK43er2j4uRI7FcrP3nArzTe1A5DkvO2rbJwnrR/IX4xj 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:rdRjSTF2g5QV3e1p7LpOGN8pcb+Zo3hKzpbzhDhvMN?= =?us-ascii?Q?ZCDeIuraVzeyV+lugJ/5QMNXRw1kdY5LV0/pLHGJPP3ze5sTJRn3/fcSl3pM?= =?us-ascii?Q?V4Tsu5FE3bpEpPs8IPW8oFvZ2imeSUZ6N+M79DtO8BfV/XrsHZweE6Qz+EPD?= =?us-ascii?Q?EVle1AC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=?us-ascii?Q?GltmNIcdoTjcfNoo5basjwnwcfN+hagOEuGZSjkzIWR/xfzv/owj98htXxiV?= =?us-ascii?Q?u9WCjIB3ksuLVtbi7IecBVRB1PaiFmvMAi3A4f9XUIDUTT4ctUNbdiYin/qn?= =?us-ascii?Q?nrf60wGVd4NXFgz7uy6y9+BfThHCu6aGtW1vCvpGeN55ZNukf3AZavkRWb00?= =?us-ascii?Q?XNwMPipdgvlIOv/dg=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:fqctO5XrJhnUswW3AB4ia5FAFMCtDSSRewDqJTr5d?= =?us-ascii?Q?LEfEN0bVtB37rLcZBt9upwlCxdrNcR7mMG3g2itASN+xG4ln/sHHALOzbkQH?= =?us-ascii?Q?K5m4vVyNBjXRwOXm+SnujueFiMAecCrPNdTSUAvhpCYn3XNJhqK9k5NzETKu?= =?us-ascii?Q?JNNgctYqPz6BEzzgOGt5J69HavNGLxPB65FluK0xtASpEx0EY7Fheifw/eys?= =?us-ascii?Q?pOMj71D+CDdsVMFJHrM/t12IPzIlqoAuVXGYg0zP+Ft/k8QmEHU9r9vobYEj?= =?us-ascii?Q?IGTGV05Hx/Emog6NquNdkWfo+PAIkcBb8W02XjQAC+hDXcqpHmN4zSKAXS+w?= =?us-ascii?Q?9trSFBadcQTpx2PRMEssAKUWH0XBtyU7F9tJnijFw3ljXZmlpuWNMZ9bPZzv?= =?us-ascii?Q?88gt+2OZ1T/bREUOYeuNlQC2Rm587/x8T10RjYgrQJCKASBuvrMOH5hEpK8O?= =?us-ascii?Q?a6cD7AYOZyt38hsxF1DZ3GAWYKGE4Wu+ySSTDNBHn5X4DlM+ZjWC7QhV3nLP?= =?us-ascii?Q?YU6LfTBUoCbUIFAuD2WQLmHLdnX1UlCjm6OZJDgpX2kOOMlCIyMc/X/VijO6?= =?us-ascii?Q?34/EW5rgg2HuBic9l+htnLjTttg32ptzeZn+5NyL3UR5vmkCV0Q36Vu6NGqN?= =?us-ascii?Q?M4OGd6lb6n6NNcC8CFfd7CUzVJazdx+yl5RYQWsngS4EdQu711SnCaOPBLx0?= =?us-ascii?Q?kXjPaX5a7+K3KKtIacu2RZHisX32JG3CK2p99U9xlBtE48zqeOuVD6KN5VrC?= =?us-ascii?Q?ZiU15SMptI76FsWN1WwalWUVJI84elWcFIIXUNCruXCVh/ns8ri1pkqKIOEW?= =?us-ascii?Q?1bt3lvNcZrRbzvtBMmBHJ59yybq1ntE49fEs7AtXuXpGbOszYlCBC26z95Xh?= =?us-ascii?Q?wvaZoWQG6npO9he64uOrQroDtEYFBfA54GGHoY/11HeLaEtxZhSNxUjDoxu5?= =?us-ascii?Q?AF4ca5aBWPJj0pzqTCODZMYAOlrCjWorezFOmL5k7+kWnBT56hMEQ93+qgAy?= =?us-ascii?Q?SdPam+fCclZxOJLnqMRPyKZHPvcxx9MvESzylCLGrGLDXbEbIxBoDMbcS1lc?= =?us-ascii?Q?sIXgY9PeFxQMPm1h297ESEACXWiPcQsqTsawqefh0XUUqu3jJlvVTqPlJMz3?= =?us-ascii?Q?aV2hEu+IiU=3D?= X-Microsoft-Exchange-Diagnostics: 1;DM3PR15MB1081;6:EeemaVbTO2a9pRrqY4yXBYG4yHwZI6JfJIaJCCzZUm10Wom91Q1zBsquX55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JGuWfQ3wR1w8vaBYu8d1z5mYK0d3awss2d5CWxT3P1ZS5oGjazopcLAZIgwOACdSjqwT8ZiU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DM3PR15MB1081;7:NG18fAz4EUJOSlJ9Vkzs6wUpnqpZIOY7HLYYj+J1bp14i71ERrqQhSUilL4+Aaf1xzG2ZHyaWqzmQcHVIXLX162LGtdDIVchWKJaKn14QoFBWwu6gDl5VUp6O794LX5Uc3Ic9zJ6o0MXB0FcnLZPAAVgo7R1XVBU9V/5lHn5n7Cv8XY7zXPvVg+ltb7W5e2iXAJO0X1IQvmvWoRwWXkJta2CBAG4gjgW+REylUYnLyeyNWzGFmOgeioREK2lLj07KgiDVbYsL+l1vUmrcDaDa94iSS7ddF71lWh8gnxboSBHhTmVT0GH4YcKsJypETbTHAkTm6QlUalOqP8Q671JCw==;20:4ZdmIqs2EcrJdlQ5ENJXKWatNkceSbueYXhqmNf8fmKi1CVghM6yBCDdax41b77mCp8xcHXGiYVBCdS52mpX3gdLn+iCvmzPAIqirVdhkXXe2ppXCGoDAewsqphM1PJerQ/qmKVtoxBC4cSrm8Xy7k9hGdO3JXMLcziGO3l1T6Q= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jun 2017 18:35:53.7604 (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: 2715 Lines: 95 Introduce a per-memory-cgroup oom_score_adj setting. A read-write single value file which exits on non-root cgroups. The default is "0". It will have a similar meaning to a per-process value, available via /proc//oom_score_adj. Should be in a range [-1000, 1000]. 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 | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 8a308c9..818a42e 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -198,6 +198,9 @@ struct mem_cgroup { /* kill all tasks below in case of OOM */ bool oom_kill_all_tasks; + /* OOM kill score adjustment */ + short oom_score_adj; + /* handle for "memory.events" */ struct cgroup_file events_file; diff --git a/mm/memcontrol.c b/mm/memcontrol.c index d4ffa79..f979ac7 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5183,6 +5183,36 @@ static ssize_t memory_oom_kill_all_tasks_write(struct kernfs_open_file *of, return nbytes; } +static int memory_oom_score_adj_show(struct seq_file *m, void *v) +{ + struct mem_cgroup *memcg = mem_cgroup_from_css(seq_css(m)); + short oom_score_adj = memcg->oom_score_adj; + + seq_printf(m, "%d\n", oom_score_adj); + + return 0; +} + +static ssize_t memory_oom_score_adj_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_score_adj; + int err; + + err = kstrtoint(strstrip(buf), 0, &oom_score_adj); + if (err) + return err; + + if (oom_score_adj < OOM_SCORE_ADJ_MIN || + oom_score_adj > OOM_SCORE_ADJ_MAX) + return -EINVAL; + + memcg->oom_score_adj = (short)oom_score_adj; + + return nbytes; +} + static int memory_events_show(struct seq_file *m, void *v) { struct mem_cgroup *memcg = mem_cgroup_from_css(seq_css(m)); @@ -5298,6 +5328,12 @@ static struct cftype memory_files[] = { .write = memory_oom_kill_all_tasks_write, }, { + .name = "oom_score_adj", + .flags = CFTYPE_NOT_ON_ROOT, + .seq_show = memory_oom_score_adj_show, + .write = memory_oom_score_adj_write, + }, + { .name = "events", .flags = CFTYPE_NOT_ON_ROOT, .file_offset = offsetof(struct mem_cgroup, events_file), -- 2.7.4