From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754170AbeAJNNU (ORCPT + 1 other); Wed, 10 Jan 2018 08:13:20 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:43262 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751261AbeAJNNR (ORCPT ); Wed, 10 Jan 2018 08:13:17 -0500 Date: Wed, 10 Jan 2018 05:11:44 -0800 From: Roman Gushchin To: David Rientjes CC: Andrew Morton , , Michal Hocko , Vladimir Davydov , Johannes Weiner , Tetsuo Handa , Tejun Heo , , , , , Subject: Re: [PATCH v13 0/7] cgroup-aware OOM killer Message-ID: <20180110131143.GB26913@castle.DHCP.thefacebook.com> References: <20171130152824.1591-1-guro@fb.com> <20171130123930.cf3217c816fd270fa35a40cb@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.1 (2017-09-22) X-Originating-IP: [2620:10d:c092:200::1:327a] X-ClientProxiedBy: DB6PR0902CA0012.eurprd09.prod.outlook.com (2603:10a6:6:2::25) To SN2PR15MB1086.namprd15.prod.outlook.com (2603:10b6:804:22::8) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 96f4204b-e51a-46a3-6104-08d5582bb969 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020);SRVR:SN2PR15MB1086; X-Microsoft-Exchange-Diagnostics: 1;SN2PR15MB1086;3:NtxIwYRrS6Y1XAsoTzjINNjMbXNbFwans+wraX/cW8a2WWIQwT6D3c1HPdgjuBJTgPHJhMo6xf5WhOa0i+pK4eOJZBt87L/GpczgOIFQ2sq25sD7lpRCxS7k/a5L6D3g0cmUp21o/OMF9HmRR8Ce3o/s/d2VvMgPUIp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EMGJkdEh+QIHUHFOSb+C9ejdntdhgDyANt4NAmOfSuzUGrcpqH/YmemNpPKHTW9Mj4zun4hJfRjhgnT1W3t7Cs/F0MNgDdB0v9ASEZ52FZzzVz8h36u+vJvz7PKtXZd/Go6Rpskk2wPoibdelZFQhXuML8rQLXdBExFvIc+NxRS;4:jdI1n3mIGWo1Cw49jem0t4IPQdOtEsLg++Vyp0fspaLjsYKukP+UWJQI+PGDIbA1c49mgOUlCFIc4VdI4A0nTEn3HOceTxl1D2bzoY7fcIQTbW4CZiSvu3T0mHfqRQ242PKngEk5WzNXHjJbsadz5AwzoeUMKGaKQ/O9AIkSN0gNG7OBHhNPFWxjHJyOTYHguRHZg92FH5mYYzsyjpWP6v7JOUc8+iNkDeZ91nXZRI3PMeXKsXPXxGDQkwmJJtxe2bRxW5acWPlruBFZbl6UqQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231023)(11241501184)(944501075)(93006095)(93001095)(6041268)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(6072148)(201708071742011);SRVR:SN2PR15MB1086;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:SN2PR15MB1086; X-Forefront-PRVS: 0548586081 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(366004)(39860400002)(346002)(396003)(376002)(39380400002)(24454002)(54534003)(199004)(189003)(6306002)(4326008)(52116002)(86362001)(6916009)(6506007)(97736004)(39060400002)(23726003)(6246003)(229853002)(2906002)(83506002)(5660300001)(53936002)(2950100002)(1076002)(59450400001)(6116002)(54906003)(33656002)(47776003)(6666003)(55016002)(58126008)(25786009)(52396003)(76176011)(7696005)(316002)(16586007)(5890100001)(386003)(8936002)(106356001)(105586002)(81156014)(81166006)(7416002)(68736007)(8676002)(7736002)(50466002)(9686003)(305945005)(966005)(478600001)(18370500001)(42262002)(6606295002);DIR:OUT;SFP:1102;SCL:1;SRVR:SN2PR15MB1086;H:castle.DHCP.thefacebook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN2PR15MB1086;23:sqlX4K7vFAgoDMYy03vj/9t8mpO6syfsECAkCm4Xa?= =?us-ascii?Q?h285xAHo4+91db93yWSubkP/6PgImzkTtWSX0AjoHWvp0DESUnYdVC/fDg+Q?= =?us-ascii?Q?P9NBfFHLs2ONYdbYK8sLpKhTLCNovMC+l1prmUetTm2/Yl/mYVopnoNSSage?= =?us-ascii?Q?WNkqWGd2BERLwnoqRJ5KUDzK7B2+1O4cBdiYmTdw1qmTArd8qiHajTzFwZPx?= =?us-ascii?Q?DpmM0txdd0FfqEDqIWcs0/a6iM+TG6XaRkFdWoca4GLomAa3X8RZ1r0r7fPT?= =?us-ascii?Q?pjMZQA/OLBklJPCdLBSnB9z5IwrjA7vp4Bqbv+m45mMsNjFQQXrvFNjinhIs?= =?us-ascii?Q?g+myTuSO38CJet6am6L9+SFA8pYOJ1lL8wMt3jlR1pipeISnrfQSPGfrQKuw?= =?us-ascii?Q?1apwYRACRB75A79RZJKsfKHvVYV2w+Xy46KersR8dJesTfwrfMo4+SBVWW90?= =?us-ascii?Q?k/oy8STKWDLxbfiDoXCVMh23gHX+suRmRkdF1b/iiZDb1LXveN/P2CMFSL++?= =?us-ascii?Q?NE4dUdL17FeNL6aGysi8yg+xPNwRfGcnTghnKbOKmuBKUk4YMuyYY7GXmQI3?= =?us-ascii?Q?sAhemYpBXsGVrMs+DwqjtMZtj91EfR81QSo9t+hOpVCT+sU9fHAB7GbOhgSO?= =?us-ascii?Q?lopFbYKbb9PVMW+rBBNsVgAN1RdIaU9DXEtqNYD5k4WvZUe3wWcR76R2O2be?= =?us-ascii?Q?7dO1fS3obpuh0kdLrRTXD3jmxwIIKsht/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7rEgwTKOM5UXdmX5TXkIrpu/f9lTJ74Tw2t1O8XQhcP+QnTTpFZtrWGlVz1c+xldqPgEDHNIyi9yGRPviceE/pvnhDswQQzxeXMP/seCsrg1KwesAF4c12rTn7t4s3ne1HwrJAxOOUVNfk=;5:DNtuXTQNEJUe65BDZYpeBzVHIYqgnuKrJgi0L4Cnp2igcDN7uWDIN1Bgz6eFDjHvtuFaCYkAATATpWo8pvkKA2HmRUinFxhmTPi872MopgTYVc3cnian/J0lGtm1gdXeBWdIjkoXCI4nXp14dSfmf9fxMYJ3ILqN+yHfT581bY8=;24:GWJQwBWFhXhn3OzkK2YKfyloKR87qNfw1//LkirkhzPttQKMCwnnM+Vz5xKS/F2lq158FP6nX/Bn1rQRYf/P35Fztb/GqrVZaVc557sfHLo=;7:onl3SvqcYY6iIMr72kWsvEOVg3IrCimzZ9fcGFNEL/IsC7/B4ilImEmnAXZAjazFZMBHJWQgEpw7JkPSztNaFLWrcWrhnDtqrrENxLUQpY32kX8eLWYQcKAw4ZkSWZ2fMY1N8f7frT3sj6f8uim6baS4MUTJh7I4HdVk00qwezI9oURqEnYCh39INlYVBbNjMUpDn4g0G5hyEAsMNUpsz5sJV/cBcUulCOD5p6cc+31dqfuJapJuilW8RDwrlefA SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;SN2PR15MB1086;20:fSCYEHsdrJDJaKe8GLkI9jly2krsa6lJfRVU+c6dV5To4ADKlqHj0L2WDEKbo5PIQyTX6aDrrPa1i0t8C1ItXzlr0VgJh3s+oi3z9i7KqQ+np756LkEuWj023BnBYmeTGEiz6enV0MruFbL1YqmxnYftbCdRcQHbNdIPplIvgV8= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jan 2018 13:11:53.9068 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 96f4204b-e51a-46a3-6104-08d5582bb969 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR15MB1086 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-01-10_07:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Hello, David! On Tue, Jan 09, 2018 at 04:57:53PM -0800, David Rientjes wrote: > On Thu, 30 Nov 2017, Andrew Morton wrote: > > > > This patchset makes the OOM killer cgroup-aware. > > > > Thanks, I'll grab these. > > > > There has been controversy over this patchset, to say the least. I > > can't say that I followed it closely! Could those who still have > > reservations please summarise their concerns and hopefully suggest a > > way forward? > > > > Yes, I'll summarize what my concerns have been in the past and what they > are wrt the patchset as it stands in -mm. None of them originate from my > current usecase or anticipated future usecase of the oom killer for > system-wide or memcg-constrained oom conditions. They are based purely on > the patchset's use of an incomplete and unfair heuristic for deciding > which cgroup to target. > > I'll also suggest simple changes to the patchset, which I have in the > past, that can be made to address all of these concerns. > > 1. The unfair comparison of the root mem cgroup vs leaf mem cgroups > > The patchset uses two different heuristics to compare root and leaf mem > cgroups and scores them based on number of pages. For the root mem > cgroup, it totals the /proc/pid/oom_score of all processes attached: > that's based on rss, swap, pgtables, and, most importantly, oom_score_adj. > For leaf mem cgroups, it's based on that memcg's anonymous, unevictable, > unreclaimable slab, kernel stack, and swap counters. These can be wildly > different independent of /proc/pid/oom_score_adj, but the most obvious > unfairness comes from users who tune oom_score_adj. > > An example: start a process that faults 1GB of anonymous memory and leave > it attached to the root mem cgroup. Start six more processes that each > fault 1GB of anonymous memory and attached them to a leaf mem cgroup. Set > all processes to have /proc/pid/oom_score_adj of 1000. System oom kill > will always kill the 1GB process attached to the root mem cgroup. It's > because oom_badness() relies on /proc/pid/oom_score_adj, which is used to > evaluate the root mem cgroup, and leaf mem cgroups completely disregard > it. > > In this example, the leaf mem cgroup's score is 1,573,044, the number of > pages for the 6GB of faulted memory. The root mem cgroup's score is > 12,652,907, eight times larger even though its usage is six times smaller. > > This is caused by the patchset disregarding oom_score_adj entirely for > leaf mem cgroups and relying on it heavily for the root mem cgroup. It's > the complete opposite result of what the cgroup aware oom killer > advertises. > > It also works the other way, if a large memory hog is attached to the root > mem cgroup but has a negative oom_score_adj it is never killed and random > processes are nuked solely because they happened to be attached to a leaf > mem cgroup. This behavior wrt oom_score_adj is completely undocumented, > so I can't presume that it is either known nor tested. > > Solution: compare the root mem cgroup and leaf mem cgroups equally with > the same criteria by doing hierarchical accounting of usage and > subtracting from total system usage to find root usage. I find this problem quite minor, because I haven't seen any practical problems caused by accounting of the root cgroup memory. If it's a serious problem for you, it can be solved without switching to the hierarchical accounting: it's possible to sum up all leaf cgroup stats and substract them from global values. So, it can be a relatively small enhancement on top of the current mm tree. This has nothing to do with global victim selection approach. > > 2. Evading the oom killer by attaching processes to child cgroups > > Any cgroup on the system can attach all their processes to individual > child cgroups. This is functionally the same as doing > > for i in $(cat cgroup.procs); do mkdir $i; echo $i > $i/cgroup.procs; done > > without the no internal process constraint introduced with cgroup v2. All > child cgroups are evaluated based on their own usage: all anon, > unevictable, and unreclaimable slab as described previously. It requires > an individual cgroup to be the single largest consumer to be targeted by > the oom killer. > > An example: allow users to manage two different mem cgroup hierarchies > limited to 100GB each. User A uses 10GB of memory and user B uses 90GB of > memory in their respective hierarchies. On a system oom condition, we'd > expect at least one process from user B's hierarchy would always be oom > killed with the cgroup aware oom killer. In fact, the changelog > explicitly states it solves an issue where "1) There is no fairness > between containers. A small container with few large processes will be > chosen over a large one with huge number of small processes." > > The opposite becomes true, however, if user B creates child cgroups and > distributes its processes such that each child cgroup's usage never > exceeds 10GB of memory. This can either be done intentionally to > purposefully have a low cgroup memory footprint to evade the oom killer or > unintentionally with cgroup v2 to allow those individual processes to be > constrained by other cgroups in a single hierarchy model. User A, using > 10% of his memory limit, is always oom killed instead of user B, using 90% > of his memory limit. > > Others have commented its still possible to do this with a per-process > model if users split their processes into many subprocesses with small > memory footprints. > > Solution: comparing cgroups must be done hierarchically. Neither user A > nor user B can evade the oom killer because targeting is done based on the > total hierarchical usage rather than individual cgroups in their > hierarchies. We've discussed this a lot. Hierarchical approach has their own issues, which we've discussed during previous iterations of the patchset. If you know how to address them (I've no idea), please, go on and suggest your version. > > 3. Userspace has zero control over oom kill selection in leaf mem cgroups > > Unlike using /proc/pid/oom_score_adj to bias or prefer certain processes > from the oom killer, the cgroup aware oom killer does not provide any > solution for the user to protect leaf mem cgroups. This is a result of > leaf mem cgroups being evaluated based on their anon, unevictable, and > unreclaimable slab usage and disregarding any user tunable. > > Absent the cgroup aware oom killer, users have the ability to strongly > prefer a process is oom killed (/proc/pid/oom_score_adj = 1000) or > strongly bias against a process (/proc/pid/oom_score_adj = -999). > > An example: a process knows its going to use a lot of memory, so it sets > /proc/self/oom_score_adj to 1000. It wants to be killed first to avoid > distrupting any other process. If it's attached to the root mem cgroup, > it will be oom killed. If it's attached to a leaf mem cgroup by an admin > outside its control, it will never be oom killed unless that cgroup's > usage is the largest single cgroup usage on the system. The reverse also > is true for processes that the admin does not want to be oom killed: set > /proc/pid/oom_score_adj to -999, but it will *always* be oom killed if its > cgroup has the highest usage on the system. > > The result is that both admins and users have lost all control over which > processes are oom killed. They are left with only one alternative: set > /proc/pid/oom_score_adj to -1000 to completely disable a process from oom > kill. It doesn't address the issue at all for memcg-constrained oom > conditions since no processes are killable anymore, and risks panicking > the system if it is the only process left on the system. A process > preferring that it is first in line for oom kill simply cannot volunteer > anymore. > > Solution: allow users and admins to control oom kill selection by > introducing a memory.oom_score_adj to affect the oom score of that mem > cgroup, exactly the same as /proc/pid/oom_score_adj affects the oom score > of a process. The per-process oom_score_adj interface is not the nicest one, and I'm not sure we want to replicate it on cgroup level as is. If you have an idea of how it should look like, please, propose a patch; otherwise it's hard to discuss it without the code. > > > I proposed a solution in > https://marc.info/?l=linux-kernel&m=150956897302725, which was never > responded to, for all of these issues. The idea is to do hierarchical > accounting of mem cgroup hierarchies so that the hierarchy is traversed > comparing total usage at each level to select target cgroups. Admins and > users can use memory.oom_score_adj to influence that decisionmaking at > each level. > > This solves #1 because mem cgroups can be compared based on the same > classes of memory and the root mem cgroup's usage can be fairly compared > by subtracting top-level mem cgroup usage from system usage. All of the > criteria used to evaluate a leaf mem cgroup has a reasonable system-wide > counterpart that can be used to do the simple subtraction. > > This solves #2 because evaluation is done hierarchically so that > distributing processes over a set of child cgroups either intentionally > or unintentionally no longer evades the oom killer. Total usage is always > accounted to the parent and there is no escaping this criteria for users. > > This solves #3 because it allows admins to protect important processes in > cgroups that are supposed to use, for example, 75% of system memory > without it unconditionally being selected for oom kill but still oom kill > if it exceeds a certain threshold. In this sense, the cgroup aware oom > killer, as currently implemented, is selling mem cgroups short by > requiring the user to accept that the important process will be oom killed > iff it uses mem cgroups and isn't attached to root. It also allows users > to actually volunteer to be oom killed first without majority usage. > > It has come up time and time again that this support can be introduced on > top of the cgroup oom killer as implemented. It simply cannot. For > admins and users to have control over decisionmaking, it needs a > oom_score_adj type tunable that cannot change semantics from kernel > version to kernel version and without polluting the mem cgroup filesystem. > That, in my suggestion, is an adjustment on the amount of total > hierarchical usage of each mem cgroup at each level of the hierarchy. > That requires that the heuristic uses hierarchical usage rather than > considering each cgroup as independent consumers as it does today. We > need to implement that heuristic and introduce userspace influence over > oom kill selection now rather than later because its implementation > changes how this patchset is implemented. > > I can implement these changes, if preferred, on top of the current > patchset, but I do not believe we want inconsistencies between kernel > versions that introduce user visible changes for the sole reason that this > current implementation is incomplete and unfair. We can implement and > introduce it once without behavior changing later because the core > heuristic has necessarily changed. David, I _had_ hierarchical accounting implemented in one of the previous versions of this patchset. And there were _reasons_, why we went away from it. You can't just ignore them and say that "there is a simple solution, which Roman is not responding". If you know how to address these issues and convince everybody that hierarchical approach is a way to go, please, go on and send your version of the patchset. Thanks! Roman