Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754412AbdIFM6p (ORCPT ); Wed, 6 Sep 2017 08:58:45 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:35900 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754350AbdIFM6d (ORCPT ); Wed, 6 Sep 2017 08:58:33 -0400 Date: Wed, 6 Sep 2017 13:57:50 +0100 From: Roman Gushchin To: Michal Hocko CC: , Vladimir Davydov , "Johannes Weiner" , Tetsuo Handa , David Rientjes , Andrew Morton , Tejun Heo , , , , Subject: Re: [v7 2/5] mm, oom: cgroup-aware OOM killer Message-ID: <20170906125750.GB12904@castle> References: <20170904142108.7165-1-guro@fb.com> <20170904142108.7165-3-guro@fb.com> <20170905145700.fd7jjd37xf4tb55h@dhcp22.suse.cz> <20170905202357.GA10535@castle.DHCP.thefacebook.com> <20170906083158.gvqx6pekrsy2ya47@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20170906083158.gvqx6pekrsy2ya47@dhcp22.suse.cz> User-Agent: Mutt/1.8.3 (2017-05-23) X-Originating-IP: [2620:10d:c092:200::1:1bb7] X-ClientProxiedBy: DB6PR07CA0084.eurprd07.prod.outlook.com (2603:10a6:6:2b::22) To CO1PR15MB1077.namprd15.prod.outlook.com (2a01:111:e400:7b66::7) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b4e8ab59-5856-4371-dbc7-08d4f526f1d2 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(2017052603199)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:CO1PR15MB1077; X-Microsoft-Exchange-Diagnostics: 1;CO1PR15MB1077;3:B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dho4HPEWta+sLzIXyjuLUweC4OQvC4oIOfPVuAVAWqRKwBTYzNOYEMxFvXbackinhbiOiYeh09QfovzL0oyvVXu65tCYP7h0EPhbbGS5uAIEDkF50tHUvdrofKawg58K9ke52F7jLgCQ1VMhrWzGx9ZnxULXpx9TaN05dLJlrvNa/OQd8sxbHhs6ug43PRxVdmNNlxudHJIS95lo5RZrsAXw9dLuoI3Mgpk1yCQeoRAqFmRqTLBqsP3gsyl+e7nKL+BXq4ap9BVvWBlxHIcxMDiKgZ+y4jSJiraVgm32q87PE7DTYW+IXC2EWWJDH1RJARgy1/5ZeybWwHftOOzUjcTHKZl3RwPwsQKwoG;4:RZ0p1hXZxRIQqtI5slWKqo621Ms+EuEBy1jp5/hKpsi2e4PN7sX8btrP1vMSrSbEsMXWruv3UjRN3JdEzKD/p9Zv8GYDKOtPTOzAXWc3LEaka0gmscpVlQZP/BOWkj3FVyz9a2ayM+06Xq8elCXtOGgQdmUNOGKSAFCFHwN8eYurWYf2ZTKkM0T7TzZWRze/lKJDAF6D5ezm3SlNJ9ggUBK8wzigx9v+2SjhDY5qWzgKtZMqta81joIfLgojHEKZ X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(100000703101)(100105400095)(3002001)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123558100)(20161123564025)(20161123562025)(20161123555025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:CO1PR15MB1077;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:CO1PR15MB1077; X-Forefront-PRVS: 0422860ED4 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6009001)(189002)(54534003)(199003)(377424004)(24454002)(53936002)(2950100002)(6666003)(6916009)(54906002)(55016002)(9686003)(50986999)(76176999)(229853002)(54356999)(189998001)(106356001)(42186005)(105586002)(93886005)(50466002)(8936002)(33656002)(8676002)(81156014)(81166006)(7736002)(101416001)(305945005)(83506001)(68736007)(23726003)(6116002)(1076002)(4001350100001)(478600001)(5660300001)(2906002)(25786009)(7416002)(33716001)(97736004)(4326008)(86362001)(6246003)(110136004)(39060400002)(6496005)(47776003)(18370500001)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:CO1PR15MB1077;H:castle;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CO1PR15MB1077;23:8/C7+cVxUTLCWxzeoUfkHKQJvwNn4ZdXa/+LhD83S?= =?us-ascii?Q?C0z+DR99cB2OHqjNnHBvizQfcwwwBjablcV+oYMp7dOqJEh+cuQGz+OrxHqO?= =?us-ascii?Q?54fFn6sgxUrsjJ54/O04mC339/lKs3aCHFhhFWSvp+jytm1WGR+W6no80f49?= =?us-ascii?Q?9Psf0QKRKrD4dcRpt5IctpvzaoAhFV/W9RQk65PQI/+n5k8GttnJoy/yWOaR?= =?us-ascii?Q?Y4XhUqBmu6Gk77HWEbal7szEoqdZSRmvHtV/edzuXDAixIAWn9kkMggRQ6XP?= =?us-ascii?Q?JiZis2qOdVRbC4rZ61mEyHCZyv8sms6r38shfc5+nmSitY9L/929gYn/d/ry?= =?us-ascii?Q?1mx9dM9TStSMNkcxOlF0dolN+p2vrVTXbHfhoGAbtMIineInZuIbc2mSesGh?= =?us-ascii?Q?KkMNlRMkuOAwnjr5zNtspuJ7B5ef2kTqERNyRQf2yDQqVuiDvGSZE1tsi/K4?= =?us-ascii?Q?ImXH7brucwExXEC3Vw0DeVo/qPgqsoFoolM5YHlooQw8vyTvENEU0JZeIHhY?= =?us-ascii?Q?W+oyQSKmrDZMGu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ShKbyPd5dgqS6/UUPHuURsvAjPPDjXxKv8om0gvR01z+Xvp9aTVTNwGiURmbeAM7TI4d5WfDRXgPTErYxSJbNmSGk74J5I28TgVCnDlccuUOx8xgNF7J2zet+4VT/6H/NT799f6/ILFq5PPmQiXgmib6252icE3dpiQ8Yndgryv94u4obt/IMM8Scb7PqXuyCK32CIPJF+UDntQFh1f62aSMg==;5:/YDExCPVT4Zxyxo9V6zS4M7yqwGRTB2glW2ksMErwKeqqBPyFWjEFLMJOksMhoWpJqjIRgz7S+vDzJhG/uBAYhq5ZV42CJVCOxASRdHQdGcBmsslOjoR41OOT/iJ1JVUxEd1O3pXyv/J2fwnaeOUTQ==;24:+WFOr0vobSKPqwI2imHjVPn72gs7zKbXHyH8uv+CTc4SgGqF3yKq43qsL5rjYkUX76lhIkbK7wxeOrHOlGwDPHC/eAc4gjzr82A7c5PORhg=;7:tqRYDlg8LWHO/JQRNWVid3FS9Qa2UT/mQhP9pQU9RSOOpvUox5imevxh+KW64v3PhvD/NwdmmEIIRK6QYrjsxBK15oy6Yki/IS7QApjsolbHcO2B9d65NMBOW7K+NSBMcbLx9rd29uTTw0JZAkdMI89KQkxF6T0FmDNMDim/v4u+tfkTckg3+P/CMij/hNVCc20yWAX1o6wcBsUE+brw0KmYXlQj8R4ZK21CqODI7nU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CO1PR15MB1077;20:yTazZmK8uPHxgM93l5gaec8uc2G/cB3GPz6rWtbOWZLAPM9ZI2o7NSn90YLWH9KcpgEwmziYrQADw2GY3rTM/QRF1yWi/dmRddM7IvZk1i+sjQa0Hfd67FwCrs3a5+8qV95rYrwdlklo1Ap3zxHKWP7VjgR0Wj/oUBrwVvKNYyc= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2017 12:58:15.8115 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR15MB1077 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-09-06_05:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4412 Lines: 107 On Wed, Sep 06, 2017 at 10:31:58AM +0200, Michal Hocko wrote: > On Tue 05-09-17 21:23:57, Roman Gushchin wrote: > > On Tue, Sep 05, 2017 at 04:57:00PM +0200, Michal Hocko wrote: > [...] > > > Hmm. The changelog says "By default, it will look for the biggest leaf > > > cgroup, and kill the largest task inside." But you are accumulating > > > oom_score up the hierarchy and so parents will have higher score than > > > the layer of their children and the larger the sub-hierarchy the more > > > biased it will become. Say you have > > > root > > > /\ > > > / \ > > > A D > > > / \ > > > B C > > > > > > B (5), C(15) thus A(20) and D(20). Unless I am missing something we are > > > going to go down A path and then chose C even though D is the largest > > > leaf group, right? > > > > You're right, changelog is not accurate, I'll fix it. > > The behavior is correct, IMO. > > Please explain why. This is really a non-intuitive semantic. Why should > larger hierarchies be punished more than shallow ones? I would > completely agree if the whole hierarchy would be a killable entity (aka > A would be kill-all). I think it's a reasonable and clear policy: we're looking for a memcg with the smallest oom_priority and largest memory footprint recursively. Then we reclaim some memory from it (by killing the biggest process or all processes, depending on memcg preferences). In general, if there are two memcgs of equal importance (which is defined by setting the oom_priority), we're choosing the largest, because there are more chances that it contain a leaking process. The same is true right now for processes. I agree, that for size-based comparison we could use a different policy: comparing leaf cgroups despite their level. But I don't see a clever way to apply oom_priorities in this case. Comparing oom_priority on each level is a simple and powerful policy, and it works well for delegation. > > [...] > > > I do not understand why do we have to handle root cgroup specially here. > > > select_victim_memcg already iterates all memcgs in the oom hierarchy > > > (including root) so if the root memcg is the largest one then we > > > should simply consider it no? > > > > We don't have necessary stats for the root cgroup, so we can't calculate > > it's oom_score. > > We used to charge pages to the root memcg as well so we might resurrect > that idea. In any case this is something that could be hidden in > memcg_oom_badness rather then special cased somewhere else. In theory I agree, but I do not see a good way to calculate root memcg oom_score. > > > > You are skipping root there because of > > > memcg_has_children but I suspect this and the whole accumulate up the > > > hierarchy approach just makes the whole thing more complex than necessary. With > > > "tasks only in leafs" cgroup policy we should only see any pages on LRUs > > > on the global root memcg and leaf cgroups. The same applies to memcg > > > stats. So why cannot we simply do the tree walk, calculate > > > badness/check the priority and select the largest memcg in one go? > > > > We have to traverse from top to bottom to make priority-based decision, > > but size-based oom_score is calculated as sum of descending leaf cgroup scores. > > > > For example: > > root > > /\ > > / \ > > A D > > / \ > > B C > > A and D have same priorities, B has larger priority than C. > > > > In this case we need to calculate size-based score for A, which requires > > summing oom_score of the sub-tree (B an C), despite we don't need it > > for choosing between B and C. > > > > Maybe I don't see it, but I don't know how to implement it more optimal. > > I have to think about the priority based oom killing some more to be > honest. Do we really want to allow setting a priority to non-leaf > memcgs? How are you going to manage the whole tree consistency? Say your > above example have prio(A) < prio(D) && prio(C) > prio(D). Your current > implementation would kill D, right? Right. > Isn't that counter intuitive > behavior again. If anything we should prio(A) = max(tree_prio(A)). Again > I could understand comparing priorities only on killable entities. Answered above. Also, I don't think any per-memcg knobs should have global meaning, despite parent memcg settings. It will break delegation model. Thanks! Roman