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 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 A34DCC433E2 for ; Mon, 14 Sep 2020 21:30:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D5C3A20759 for ; Mon, 14 Sep 2020 21:30:29 +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="W3aKslhu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D5C3A20759 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 009F06B005D; Mon, 14 Sep 2020 17:30:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EFD366B0062; Mon, 14 Sep 2020 17:30:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DEC2E6B006C; Mon, 14 Sep 2020 17:30:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0249.hostedemail.com [216.40.44.249]) by kanga.kvack.org (Postfix) with ESMTP id C9F1A6B005D for ; Mon, 14 Sep 2020 17:30:28 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 81E83824999B for ; Mon, 14 Sep 2020 21:30:28 +0000 (UTC) X-FDA: 77262960936.22.drink69_030a7c62710b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 4B77718038E60 for ; Mon, 14 Sep 2020 21:30:28 +0000 (UTC) X-HE-Tag: drink69_030a7c62710b X-Filterd-Recvd-Size: 5831 Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Mon, 14 Sep 2020 21:30:27 +0000 (UTC) Received: by mail-qk1-f196.google.com with SMTP id o5so1891455qke.12 for ; Mon, 14 Sep 2020 14:30:27 -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=yrT8gC4TTWet6cZ9YwSESn7cnuC6utKAOdmSGQgzcPU=; b=W3aKslhundhu3B/Fi871b2e1Fj2OCJtvs3SQyw2QoDeAfHiT1b1gbC21cgtxcN50dv Cl4JMtBfvUJmy9RKwjSs56Q31TGv1HgO7nxpzUNGD2+pg4uDX6AE4R5Ma8mwZ3Erc/YK lW+50k3WsMh8OoaNKn4SxKilIjiwgWYIclfyPq2DbbLw6Xei5uUMHF4p0ObonXrxcZhT TmmRrdD/VsUAEtTbbTdj4+IQ0mvQ2mXthq0yJpFmfnrEohvPyxMISwsI7I1wjKJQ1F6Z ERw5AsyT/pD/oIHNusD7gJKQH56XMtLUL5i7yaHDmTZx8Se9E5lzKJn9MmkGYrnKmxGU 6FZA== 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=yrT8gC4TTWet6cZ9YwSESn7cnuC6utKAOdmSGQgzcPU=; b=WA3JEXzwwPknkMDMIGn2GNDcSkjGXwcbmp/5/JjlCR0hUURNPNmf2F0kf+F4FwkrId WNxDLDI11Cy59NDHQQpn4wL7Oi12XKNYUyLPa7Ll5EyIKqswA1goVKy7DsEzMRXvVZOu owPIFwJeXVrCpi/1vl+5FCU/frbCrRzyYdWNaIKOrqgCzPAk1d5Sd0GBsNio4kFiVu6Q dd/K+KhZLahVCAFbG3SavEKBrzRoT8sFL5e3Bp6/GeCprDxnzqPrmd7MCsxEeOgndGkR ORSmzoE2KpBAsqs3QAzy/3mg4o0wgFuTlXokYii12VL6VWUvQQNnn23hb7KK9UVhtOYH YMFg== X-Gm-Message-State: AOAM533PhlRxdPiOJcnu1q/+XNCOaqcvvItdJcPtC5ndxuF34krdbSwn ak9mlqnhqwCvQkk4SIvSi4iMAQ== X-Google-Smtp-Source: ABdhPJwMuP07J26GGphmCo+u7UAeSFqN5H7Ty4LWtqDD81qpUgIvxOKrdjMXQKWssUo+sQzJki5LYA== X-Received: by 2002:a37:a84a:: with SMTP id r71mr14209038qke.481.1600119026836; Mon, 14 Sep 2020 14:30:26 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1:3700]) by smtp.gmail.com with ESMTPSA id z74sm15698299qkb.11.2020.09.14.14.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 14:30:26 -0700 (PDT) Date: Mon, 14 Sep 2020 17:29:04 -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: <20200914212904.GB175618@cmpxchg.org> References: <20200914024452.19167-1-longman@redhat.com> <20200914024452.19167-3-longman@redhat.com> <20200914114825.GM16999@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 4B77718038E60 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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 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 from > > > both the v1 memsw and v2 memory+swap page counters & return the max= imum > > > of these 2 values. This is redundant and it is more efficient to ju= st > > > get either the v1 or the v2 values depending on which one is curren= tly > > > 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 me= m_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 default > > state it would lead to max =3D PAGE_COUNTER_MAX which is not somethin= g > > 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_pa= ges): memsw.max can be smaller than max. max =3D min3(max, READ_ONCE(memcg->memsw.max), total_swap_pages)?