Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751443AbdFFQVB (ORCPT ); Tue, 6 Jun 2017 12:21:01 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:37152 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751454AbdFFQU5 (ORCPT ); Tue, 6 Jun 2017 12:20:57 -0400 Authentication-Results: google.com; dkim=none (message not signed) header.d=none;google.com; dmarc=none action=none header.from=fb.com; Date: Tue, 6 Jun 2017 17:20:07 +0100 From: Roman Gushchin To: David Rientjes CC: , Tejun Heo , Johannes Weiner , Li Zefan , Michal Hocko , Vladimir Davydov , Tetsuo Handa , , , , Subject: Re: [RFC PATCH v2 1/7] mm, oom: refactor select_bad_process() to take memcg as an argument Message-ID: <20170606162007.GB752@castle> References: <1496342115-3974-1-git-send-email-guro@fb.com> <1496342115-3974-2-git-send-email-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [2620:10d:c092:200::1:ba6f] X-ClientProxiedBy: AM3PR07CA0132.eurprd07.prod.outlook.com (2603:10a6:207:8::18) To BL2PR15MB1075.namprd15.prod.outlook.com (2603:10b6:201:17::9) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL2PR15MB1075: X-MS-Office365-Filtering-Correlation-Id: 11d89d92-97e4-4bae-f169-08d4acf7eb46 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075)(201703031133081);SRVR:BL2PR15MB1075; X-Microsoft-Exchange-Diagnostics: 1;BL2PR15MB1075;3:V69XrO3iEy6uzveIioS+fNQaMMIky4ZnlPIHXZW8Uz27vVSlCEAPzLeuIta6eTuPVCHZqDx5HHXYuHaxCQvwlG9pjdM+HjRMJxU0yXCFluQo+x8CA0r/En6Lre4CjmldPcTgvX2KnSRtzT3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FnGooXv5/g0Cw161zd5Tmi8WNPRGrKbVrCLyJeWFGP4ZmiQSIT/Inr2S0jeo/MchGWzoFwxakYcYU11f+LrmuAbgNeUXwFyTQyuBVvyWciwl0hSPE4W+MFeqsdkbliMutOGaflZRLlIRWVHJIHSvyz5jJOlVhVgSXiLF6e0GKCGXN6V46yN9/oHkGwWuFqwo0A62PkWtraxYixsUPpbi/6Uh0JN07OS05aZLb7XTS6Wy+EmOt8Et++Nhdvn71semS4XWYw8OKEseNt5JlepggnkrfbC3vwXTtNjaGnGRr8cWIddjbsjRt5OSw1Lttq1r8I76HrXOtR22GBWeMlQBlWP4SwAuqWioHfIyCdyZvYOh7KLy350UbHeydN2ZefcrVyyRDmasZ3NhFkwt7AmsIjglHmx3tms1cOgid X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(231250463719595); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(10201501046)(3002001)(93006095)(93001095)(6041248)(20161123564025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123558100)(20161123555025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:BL2PR15MB1075;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:BL2PR15MB1075; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BL2PR15MB1075;4:WuMyvGb36x9XKYAMyjpRFcC9TmY7xWPqkrI/5FtZl+?= =?us-ascii?Q?eNUm/XYRLtpIyzeLSQ/rCu8lOgw3Lr+urRz3fXAwrvjy137mJnjQEPeKVqf2?= =?us-ascii?Q?yr90dhzmb2Kid4DYEG+GTBXzHnGBPO7A7FvSjj1fSN0csBqcmtTCQLBOT7+o?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98r2rJwJ2ahaWwOOPAqnJ7A5uGWI7?= =?us-ascii?Q?iTkurEwPBJawpf8P1GhvDmlJq/EPrgZ4EieQiqXFg6F0kaf8Dz9u3M3Ykf6O?= =?us-ascii?Q?mbEByobt5qC+op2MThZOV3/GX/nt/oh97dM8rNQWHMJky1HL3T1eq6uoFTai?= =?us-ascii?Q?uQT4MGoJwG5dg=3D?= X-Forefront-PRVS: 033054F29A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(39410400002)(39400400002)(39840400002)(39450400003)(39850400002)(24454002)(110136004)(86362001)(33656002)(38730400002)(189998001)(9686003)(6916009)(53936002)(33716001)(6116002)(2950100002)(23726003)(6496005)(4001350100001)(1076002)(54906002)(55016002)(2906002)(25786009)(6246003)(5660300001)(54356999)(42186005)(50986999)(76176999)(4326008)(7416002)(83506001)(229853002)(345774005)(305945005)(81166006)(8676002)(6666003)(5890100001)(47776003)(7736002)(478600001)(18370500001)(217873001)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:BL2PR15MB1075;H:castle;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BL2PR15MB1075;23:pbbXaGvJttcEuTDSGxry8VBwG1eHyb64Y4SYzS3JV?= =?us-ascii?Q?HXBfrgflRRgOSDzh+UESw2gvM9ZWBkjMo/vYSFaqK9snPg0VZvYxmxUEjRYG?= =?us-ascii?Q?8egvCsEuMIii0ZD5Dr/Q3mOsBIQN75+bUbnCCMBDc6EbwgqMT1o+dsl7+dTm?= =?us-ascii?Q?qqcy8893fBXHy0Zdg2S7m3Eg6CDpF9B1Ig7X1YgvotfXJJ9xpPshugF947P5?= =?us-ascii?Q?QNTRgMcoToAG27agJV7R9/caf/jH2QTKcXJ/FDj87QuvSDnBIC4scYV2/Bik?= =?us-ascii?Q?vS6MV/up/TLPzqMIAs/7u9tjH3JQOZoXHmf0IQrTLalbzku877U+c2wjnNaG?= =?us-ascii?Q?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jqMPIjevUa6IocMx2Gze6OkHjxIcM8KswWuCF9/L1RMrHalqGxHduvgpqARw9QAqaR82/aTFpXVBXSXs9CWkMcQlKIORTiYFo3D6t2sRbjRCekcYrxc6PZuo3SCcE12YBDLIx;24:cXsMx/gLXUMq5FqLIV3FVqg4L1K/AIHfgoQuFfOqK5nISJDD8Tdgapj5HXSRf9UX6q3I21k8mBQQUyVwrE5djGFbkyZCYkw6jdnz3CeegCs= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BL2PR15MB1075;7:BXZZQbuJpmTGn1LeYY5oaj9EdYJKgaYOqAYg7f26OklYDF3tt7ojqvnc5bq6LFgyJwntOHuB0Mq5Yn+ai1W1UxtR5f3+jlsdAngKS1zvrF1XRpS1LLWQnNXhQeb647U6LD5VGYBXYGXjgPHqeo7iapk8wrfoMCB3mWsHECVRaliBrP6J2EuLe95MD2n8XA6SpLYVfkhyiLMoqtpcBNFvIwbV+042Xbu5YU3jT/LRN7Dk4eO+PGHTjINNEXvRGYmvUtUJ/8BqJHLoX2TSvceCulR6AMOuOwBHV6GBla+URcAWV+oejfGBsQTXXZi6rh6vE8zVofxCfjyi+7lw5CLeig==;20:ehCnvcLc7JGNfeA2HLBcWwWT850t7ZXArTvpC0e2g1xdbL1zsOagdZ8MXQJgJ3H63HyqZb8NoZEnBGf33tdEh8iMKAUyCnpSBfBLoVBH6SbyFyg5S4cXMvvf6ZLroHuPVTkjGP/W0ULncBpfgDFS6C1ia8Z8xirOGagRKRc0/6A= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2017 16:20:15.5589 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR15MB1075 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-06_12:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4375 Lines: 87 On Sun, Jun 04, 2017 at 03:50:37PM -0700, David Rientjes wrote: > We use a heavily modified system and memcg oom killer and I'm wondering > if there is some opportunity for collaboration because we may have some > shared goals. > > I can summarize how we currently use the oom killer at a high level so > that it is not overwhelming with implementation details and give some > rationale for why we have converged onto this strategy over the period of > a few years. > > For victim selection, we have strict priority based oom killing both at > the memcg level and the process level. > > Each process has its own "badness" value that is independent of > oom_score_adj, although some conversion is done if a third-party thread > chooses to disable itself from oom killing for backwards compatibility. > Lower values are more preferable victims, but that detail should not > matter significantly. If two processes share the same badness value, > tiebreaks are done by selecting the largest rss. > > Each memcg in a hierarchy also has its own badness value which > semantically means the same as the per-process value, although it > considers the entire memcg as a unit, similar to your approach, when > iterating the hierarchy to choose a process. The benefit of the > per-memcg and per-process approach is that you can kill the lowest > priority process from the lowest priority memcg. > > The above scoring is enabled with a VM sysctl for the system and is used > for both system (global) and memcg oom kills. For system overcommit, > this means we can kill the lowest priority job on the system; for memcg, > we can allow users to define their oom kill priorities at each level of > their own hierarchy. > > When the system or root of an oom memcg hierarchy encounters its limit, > we iterate each level of the memcg hierarchy to find the lowest priority > job. This is done by comparing the badness of the sibling memcgs at > each level, finding the lowest, and iterating that subtree. If there are > lower priority processes per the per-process badness value compared to > all sibling memcgs, that process is killed. > > We also have complete userspace oom handling support. This complements > the existing memory.oom_control notification when a memcg is oom with a > separate notifier that notifies when the kernel has oom killed a process. > It is possible to delay the oom killer from killing a process for memcg > oom kills with a configurable, per-memcg, oom delay. If set, the kernel > will wait for userspace to respond to its oom notification and effect its > own policy decisions until memory is uncharged to that memcg hierarchy, > or the oom delay expires. If the oom delay expires, the kernel oom > killer kills a process based on badness. > > Our oom kill notification file used to get an fd to register with > cgroup.event_control also provides oom kill statistics based on system, > memcg, local, hierarchical, and user-induced oom kills when read(). > > We also have a convenient "kill all" knob that userspace can write when > handling oom conditions to iterate all threads attached to a particular > memcg and kill them. This is merely to prevent races where userspace > does the oom killing itself, which is not problematic in itself, but > additional tasks continue to be attached to an oom memcg. > > A caveat here is that we also support fully inclusive kmem accounting to > memcg hierarchies, so we call the oom killer as part of the memcg charge > path rather than only upon returning from fault with VM_FAULT_OOM. We > have our own oom killer livelock detection that isn't necessarily > important in this thread, but we haven't encountered a situation where we > livelock by calling the oom killer during charge, and this is a > requirement for memcg charging as part of slab allocation. > > I could post many patches to implement all of this functionality that we > have used for a few years, but I first wanted to send this email to see > if there is any common ground or to better understand your methodology > for using the kernel oom killer for both system and memcg oom kills. > > Otherwise, very interesting stuff! Hi David! Thank you for sharing this! It's very interesting, and it looks like, it's not that far from what I've suggested. So we definitily need to come up with some common solution. Thanks! Roman