Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1252033ybl; Fri, 13 Dec 2019 12:06:21 -0800 (PST) X-Google-Smtp-Source: APXvYqw69h/veYMKaZPcoaNLp9S7/kOoXx3UpNNbW6ssGoRtiflqLPK/CrNxUi2nr9TziJZkBC/E X-Received: by 2002:a05:6830:147:: with SMTP id j7mr611366otp.44.1576267581855; Fri, 13 Dec 2019 12:06:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576267581; cv=none; d=google.com; s=arc-20160816; b=f4+g5PBslYEMf/OW23QdjCcn62ngT7x6u4mDPcXRni8rmJ/sL3XMEit2sQ4HO+bGmy 63+5HIbnTJYboZb4egnxbjPFMW26JiV6d48k00XkMmdZfT4m+ZPDDcgRwHTqzlu9nNi2 HdQLJUMCIgPBt5F1Ykf61HEbqatsiYP7mhd3mviG4ZjqimNc1xn4vG3xDY3QmmC1varq ekUqce+gwCyzLLuw9w5wPMag0PbanbfJgHDa1e8un1fP5fuIdWEmT92MODCXDkvgxEPx GO5VW/siAUeJOoEESTK7c5mc11n5R03BwjUVJvb6JefAYJiWotGfR7TVkaBkNSQs6/JW 3Q/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=AGxRnEh5CXFWXGLun9RvFBMrbc3Csuo1hFkC8taJ9Ao=; b=DYLasa0/RAxLAOxJv84IWEv5RKtJPhD3NNimHsZCNyi54iam/t8h7T3it/phdvp1/C 8T8Xmza9Sds5HIVnX/GM8nJOmPfPLwO5Y4/bxMfK9fH/5lvKgpMrOT6EyB3r7MOWmjnn qGPJb0UGIB5yw7ennJwG6fa6VD7vrHdeUoWE3TD3lvEC1/TXCkspKizTTj83be5M91Lf nYShTZurs6nTeqdWVBrZr620LwImE7/OSlmoIGXP9q60izFOmEqW2J6b5JVH9W+TgRB2 dfmueFrwRV0UWIn2sywEhJ8htNzOhXPTvXd+HPkREzleV8IPPBx1c4SbLrGvYgQQB4vK VaTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=fi8pocFA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l26si5806845oti.152.2019.12.13.12.06.09; Fri, 13 Dec 2019 12:06:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=fi8pocFA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729013AbfLMUFW (ORCPT + 99 others); Fri, 13 Dec 2019 15:05:22 -0500 Received: from mail-qt1-f195.google.com ([209.85.160.195]:35731 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728736AbfLMUFW (ORCPT ); Fri, 13 Dec 2019 15:05:22 -0500 Received: by mail-qt1-f195.google.com with SMTP id e12so80144qto.2 for ; Fri, 13 Dec 2019 12:05:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=AGxRnEh5CXFWXGLun9RvFBMrbc3Csuo1hFkC8taJ9Ao=; b=fi8pocFAG1MtH+wrS/RwicUEW6vUdIGEjPL2lsSHOLPBs6UThnygqIyuQc95xton9e Yxoneci0+u6nu3ovdvs2nwA6RCfIMHAvQP7WkJLiEs9uazqRsxy1GzWplPGcynkU2vEK m7juwjZ8BwyfJRwNzTstai0DRHVpUgvjzk1Q5uqS/8LJE0nHMg3ldrRcWLKuHAHLT9dG VlArpH8BK+h7UwtXjWpyLxEFn8kV0wny/tRfB8fOru0yd0avuJOpcJRwpsLKPK0y/1/z q1OAdPQzLYkV9FLa/Gez/xOtKcg1Uv+ldtQ5Z2yWXT1+Sl1YJ5Vol1E4IiG9H3W6XsSS WQAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=AGxRnEh5CXFWXGLun9RvFBMrbc3Csuo1hFkC8taJ9Ao=; b=am+Mz0aldLp0ukkWdwSEn1eKevpeu9oHerfuCIGyWoDaSzOSS5jW3+k+UFO8yxIn9k qIxeunNv1o6dfvrlGO86koAKtxx9WGX99/P+vOIQFsnCWm+w/KvjqnT1oi6p9Fj+wI30 LydM/IAdzCVFQpJsaLBHS4uSaeWIOhQ+6P5j6ugXE3jHuF2HSJ25K8eEr7SUU8M95kTw HqzjLvEoZJ2Q+4srNMJARiHoTdE90mfIsoaTBsmtzi9zpAHLmCzLtsIS2NZqlkX2vhJ+ iJ8Y/tONAr7dICY/IN9cE0u3rIvFjSy0T1jgXfCNi3dI5RCRfnJwhrT7eMrBTMYzWXCe bdbA== X-Gm-Message-State: APjAAAVErmsltRchHa3EPgs+RnN752Ler8f5Qa8/kcItfJsFzW6QtLqY zQkPPu21q7gIZee/5myJUcua6Q== X-Received: by 2002:aed:24ec:: with SMTP id u41mr4951304qtc.220.1576267520991; Fri, 13 Dec 2019 12:05:20 -0800 (PST) Received: from localhost (70.44.39.90.res-cmts.bus.ptd.net. [70.44.39.90]) by smtp.gmail.com with ESMTPSA id f23sm3092385qke.104.2019.12.13.12.05.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Dec 2019 12:05:20 -0800 (PST) Date: Fri, 13 Dec 2019 15:05:19 -0500 From: Johannes Weiner To: Andrew Morton Cc: Michal Hocko , Roman Gushchin , Tejun Heo , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH 3/3] mm: memcontrol: recursive memory.low protection Message-ID: <20191213200519.GA168988@cmpxchg.org> References: <20191213192158.188939-1-hannes@cmpxchg.org> <20191213192158.188939-4-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191213192158.188939-4-hannes@cmpxchg.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 13, 2019 at 02:21:58PM -0500, Johannes Weiner wrote: > + if (cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_RECURSIVE_PROT) { > + unsigned long unclaimed; > + /* > + * If the children aren't claiming (all of) the > + * protection afforded to them by the parent, > + * distribute the remainder in proportion to the > + * (unprotected) size of each cgroup. That way, > + * cgroups that aren't explicitly prioritized wrt each > + * other compete freely over the allowance, but they > + * are collectively protected from neighboring trees. > + * > + * We're using unprotected size for the weight so that > + * if some cgroups DO claim explicit protection, we > + * don't protect the same bytes twice. > + */ > + unclaimed = parent_effective - siblings_protected; > + unclaimed *= usage - protected; > + unclaimed /= parent_usage - siblings_protected; Brainfart I noticed just after sending it out - naturally. If there is unclaimed protection in the parent, but the children use exactly how much they claim, this will div0. We have to check for usage that isn't explicitly protected in the child to which to apply the float. Fixlet below. Doesn't change the overall logic, though. diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 2e352cd6c38d..8d7e9490740b 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6328,21 +6328,24 @@ static unsigned long effective_protection(unsigned long usage, */ ep = protected; - if (cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_RECURSIVE_PROT) { + /* + * If the children aren't claiming (all of) the protection + * afforded to them by the parent, distribute the remainder in + * proportion to the (unprotected) size of each cgroup. That + * way, cgroups that aren't explicitly prioritized wrt each + * other compete freely over the allowance, but they are + * collectively protected from neighboring trees. + * + * We're using unprotected size for the weight so that if some + * cgroups DO claim explicit protection, we don't protect the + * same bytes twice. + */ + if (!(cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_RECURSIVE_PROT)) + return ep; + + if (usage > protected && parent_effective > siblings_protected) { unsigned long unclaimed; - /* - * If the children aren't claiming (all of) the - * protection afforded to them by the parent, - * distribute the remainder in proportion to the - * (unprotected) size of each cgroup. That way, - * cgroups that aren't explicitly prioritized wrt each - * other compete freely over the allowance, but they - * are collectively protected from neighboring trees. - * - * We're using unprotected size for the weight so that - * if some cgroups DO claim explicit protection, we - * don't protect the same bytes twice. - */ + unclaimed = parent_effective - siblings_protected; unclaimed *= usage - protected; unclaimed /= parent_usage - siblings_protected;