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=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 D2BB1C43461 for ; Mon, 14 Sep 2020 21:33:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6521E20759 for ; Mon, 14 Sep 2020 21:33:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=cmpxchg-org.20150623.gappssmtp.com header.i=@cmpxchg-org.20150623.gappssmtp.com header.b="rwyLUxhp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6521E20759 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 BE8C06B006C; Mon, 14 Sep 2020 17:33:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B9A2A6B006E; Mon, 14 Sep 2020 17:33:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB1D88E0001; Mon, 14 Sep 2020 17:33:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 7FE526B006C for ; Mon, 14 Sep 2020 17:33:25 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 1D408181AC217 for ; Mon, 14 Sep 2020 21:33:25 +0000 (UTC) X-FDA: 77262968370.02.wheel62_56131252710b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id D1F3510097AA8 for ; Mon, 14 Sep 2020 21:33:24 +0000 (UTC) X-HE-Tag: wheel62_56131252710b X-Filterd-Recvd-Size: 6138 Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Mon, 14 Sep 2020 21:33:24 +0000 (UTC) Received: by mail-qt1-f196.google.com with SMTP id r8so1386230qtp.13 for ; Mon, 14 Sep 2020 14:33:23 -0700 (PDT) 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:content-transfer-encoding:in-reply-to; bh=M6GRxBpT2cC25wV82DuNi9J3pqiD8OWCE31gUld/UhE=; b=rwyLUxhptQJc4HOqwpHP2HBqm700/ViMyS+157/Rz8Xv6Kt/qW1SS8hfob3t+geEaN jgum4YbUdr9Z/zipYDu1H+ZK7te0x5IIz2kR1YJOnnYec34roru9spTQuD3GhyqhJY7E wn6kotmIL/HBuARMoYXTBU3L5Is9LfKgxWv9elRtM1XilCShSVzx3Ee6PqpwV6evdyUI 5R0Pbsb0l9+ce6wHYdnl+Rg3xvN1fh/T6OtQePz+hvQMJgIBut1tgGPjsxnwwtaxvPnl 5v3i2B/3e9WAQVVQIaAWihJ0Sv6vxWISBtn5UOkRsG58l7XOP20RC+5xHSPvcaET7Uoe hfqg== 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:content-transfer-encoding :in-reply-to; bh=M6GRxBpT2cC25wV82DuNi9J3pqiD8OWCE31gUld/UhE=; b=pRHYAW9qGMEZq/baOpTY53b0kAiqN6fCfsNiY85UyE1OictpGtWmAHwP9a6HLCw5BF 5g+1ZR7q7JDsBd+bxFLu9OVTBVExL2WoyxV2QaiPpPsgYTyG7lqptfagIE8JfznMnfVl JbQVqBxQ+cG7t8e9NpQdjzoleMDmMv2+IoRMMJtzj8P4FLq0yfL6LZpTDtRVNXiUDsn2 phcoH93dP4o2OR69yTLCEK9klc8jcKACF2sboqYG8VxC2vCC8Na9w68JdMy0hexubyTx i/fQUUCelqqUbCMB/+/A+2JFhU7XsODHAWF/109F5Rcz8zlO7ZraicwWW1S/PZOmweDq kHRQ== X-Gm-Message-State: AOAM532o7YEKM3a6K8E7JGouo09yIL1lKDAzaNrb8p9rZYiOCadWmUzK TkPNdVCx0pq6KJ1EfKy0Ws/j7A== X-Google-Smtp-Source: ABdhPJxl25SSqbEom8UNjHbcdzIzm36yZ81zxV71gBF1hYZVcVt4BpQ808OQZYcMcR2vsN2uySCkVA== X-Received: by 2002:ac8:76c7:: with SMTP id q7mr15059779qtr.293.1600119203260; Mon, 14 Sep 2020 14:33:23 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1:3700]) by smtp.gmail.com with ESMTPSA id f3sm14633329qtg.71.2020.09.14.14.33.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 14:33:22 -0700 (PDT) Date: Mon, 14 Sep 2020 17:32:00 -0400 From: Johannes Weiner To: Waiman Long Cc: Michal Hocko , Vladimir Davydov , Andrew Morton , Tejun Heo , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Shakeel Butt , Chris Down , Roman Gushchin , Yafang Shao Subject: Re: [PATCH v2 2/3] mm/memcg: Simplify mem_cgroup_get_max() Message-ID: <20200914213200.GC175618@cmpxchg.org> References: <20200914024452.19167-1-longman@redhat.com> <20200914024452.19167-3-longman@redhat.com> <20200914114825.GM16999@dhcp22.suse.cz> <20200914212904.GB175618@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <20200914212904.GB175618@cmpxchg.org> X-Rspamd-Queue-Id: D1F3510097AA8 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 Content-Transfer-Encoding: quoted-printable 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 Mon, Sep 14, 2020 at 05:29:06PM -0400, Johannes Weiner wrote: > On Mon, Sep 14, 2020 at 09:51:26AM -0400, Waiman Long wrote: > > On 9/14/20 7:48 AM, Michal Hocko wrote: > > > On Sun 13-09-20 22:44:51, Waiman Long wrote: > > > > The mem_cgroup_get_max() function used to get memory+swap max fro= m > > > > both the v1 memsw and v2 memory+swap page counters & return the m= aximum > > > > of these 2 values. This is redundant and it is more efficient to = just > > > > get either the v1 or the v2 values depending on which one is curr= ently > > > > in use. > > > >=20 > > > > Signed-off-by: Waiman Long > > > > --- > > > > mm/memcontrol.c | 20 +++++++++----------- > > > > 1 file changed, 9 insertions(+), 11 deletions(-) > > > >=20 > > > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > > > index 8c74f1200261..ca36bed588d1 100644 > > > > --- a/mm/memcontrol.c > > > > +++ b/mm/memcontrol.c > > > > @@ -1633,17 +1633,15 @@ void mem_cgroup_print_oom_meminfo(struct = mem_cgroup *memcg) > > > > */ > > > > unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg) > > > > { > > > > - unsigned long max; > > > > - > > > > - max =3D READ_ONCE(memcg->memory.max); > > > > - if (mem_cgroup_swappiness(memcg)) { > > > > - unsigned long memsw_max; > > > > - unsigned long swap_max; > > > > - > > > > - memsw_max =3D memcg->memsw.max; > > > > - swap_max =3D READ_ONCE(memcg->swap.max); > > > > - swap_max =3D min(swap_max, (unsigned long)total_swap_pages); > > > > - max =3D min(max + swap_max, memsw_max); > > > > + unsigned long max =3D READ_ONCE(memcg->memory.max); > > > > + > > > > + if (cgroup_subsys_on_dfl(memory_cgrp_subsys)) { > > > > + if (mem_cgroup_swappiness(memcg)) > > > > + max +=3D min(READ_ONCE(memcg->swap.max), > > > > + (unsigned long)total_swap_pages); > > > > + } else { /* v1 */ > > > > + if (mem_cgroup_swappiness(memcg)) > > > > + max =3D memcg->memsw.max; > > > I agree that making v1 vs. v2 distinction here makes the code more > > > obvious. But I do not think your code is correct for v1. In a defau= lt > > > state it would lead to max =3D PAGE_COUNTER_MAX which is not someth= ing > > > we want, right? > > >=20 > > > instead you want > > > max +=3D min(READ_ONCE(memcg->memsw.max), total_swap_pages); > > >=20 > > You are right, it is a bit tricky for v1. > >=20 > > I will change it to > >=20 > > =A0=A0=A0 max +=3D min(READ_ONCE(memcg->memsw.max) - max, total_swap_= pages): >=20 > memsw.max can be smaller than max. >=20 > max =3D min3(max, READ_ONCE(memcg->memsw.max), total_swap_pages)? Nevermind, I saw the follow-up below, and it's indeed not allowed to configure it like that.