From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB7D6C2D0D0 for ; Fri, 13 Dec 2019 21:11:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C4EA824682 for ; Fri, 13 Dec 2019 21:11:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20150623.gappssmtp.com header.i=@cmpxchg-org.20150623.gappssmtp.com header.b="fi8pocFA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C4EA824682 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 120E18E0018; Fri, 13 Dec 2019 15:05:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D1B48E0001; Fri, 13 Dec 2019 15:05:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F02DB8E0018; Fri, 13 Dec 2019 15:05:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0084.hostedemail.com [216.40.44.84]) by kanga.kvack.org (Postfix) with ESMTP id D7E828E0001 for ; Fri, 13 Dec 2019 15:05:22 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 66049824999B for ; Fri, 13 Dec 2019 20:05:22 +0000 (UTC) X-FDA: 76261197684.11.bat32_4beef01583e5f X-HE-Tag: bat32_4beef01583e5f X-Filterd-Recvd-Size: 6079 Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Fri, 13 Dec 2019 20:05:21 +0000 (UTC) Received: by mail-qt1-f194.google.com with SMTP id i12so62581qtp.6 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=Kc8KkgZmFNGKiZDNgY+UcTkeU1OAF6YSfaeKyrEnNgh1s9Mf9V7uRvcMlz291o7CHh CeW1/hKPndTt7/wmcbhnSihzqtqOd+mLdwcHteufDxlWIaUGSt/lhMU6qu4Ix3vWa2mS XzsaWawwQg+PZ2BsfEvA7Zy3R6U8NtK279T/KQjA6Z0xXJPRloARXwUCCpAQXjn/Ejv0 KIZWCRr/cciA5u8/BFS/7DsMZh6ZA8rikn6FgOrGhF1LQbZBivjeS7p0BAnLxy8iHJ/c mgWB6nS9E61qgjeu+Cd1WMtXt9poE/ISnGjMKChYemIEXST7bzrycSM/N9YbGOvwH2X4 evwQ== X-Gm-Message-State: APjAAAUz8a1txfTQqa5bhHciKP2m/x6VW/DCSIyA0UU7b38SsC/3FMSc bDxXVzS6PTZL6aDpoRl0TWdcxA== X-Google-Smtp-Source: APXvYqyt8/F7dcovN6ml4CYTmL9Z4Gv+D5IHB1cNmx/2gV7w9evyzyCC0M4BYf6Eo/p0Bvy7I4PQQA== 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> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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;