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.8 required=3.0 tests=BAYES_00, 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 BC901C433E2 for ; Mon, 14 Sep 2020 11:48:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 574AB21D1A for ; Mon, 14 Sep 2020 11:48:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 574AB21D1A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BCE7D6B0055; Mon, 14 Sep 2020 07:48:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B57F66B005A; Mon, 14 Sep 2020 07:48:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A471E6B005C; Mon, 14 Sep 2020 07:48:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0162.hostedemail.com [216.40.44.162]) by kanga.kvack.org (Postfix) with ESMTP id 8B14C6B0055 for ; Mon, 14 Sep 2020 07:48:27 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 4BC9C1802186D for ; Mon, 14 Sep 2020 11:48:27 +0000 (UTC) X-FDA: 77261494254.01.judge54_1e0cb2b27108 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin01.hostedemail.com (Postfix) with ESMTP id 1BE90100A2D35 for ; Mon, 14 Sep 2020 11:48:27 +0000 (UTC) X-HE-Tag: judge54_1e0cb2b27108 X-Filterd-Recvd-Size: 3173 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Mon, 14 Sep 2020 11:48:26 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 11374AC19; Mon, 14 Sep 2020 11:48:41 +0000 (UTC) Date: Mon, 14 Sep 2020 13:48:25 +0200 From: Michal Hocko To: Waiman Long Cc: Johannes Weiner , 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: <20200914114825.GM16999@dhcp22.suse.cz> References: <20200914024452.19167-1-longman@redhat.com> <20200914024452.19167-3-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200914024452.19167-3-longman@redhat.com> X-Rspamd-Queue-Id: 1BE90100A2D35 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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 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 maximum > 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 currently > in use. > > Signed-off-by: Waiman Long > --- > mm/memcontrol.c | 20 +++++++++----------- > 1 file changed, 9 insertions(+), 11 deletions(-) > > 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 = READ_ONCE(memcg->memory.max); > - if (mem_cgroup_swappiness(memcg)) { > - unsigned long memsw_max; > - unsigned long swap_max; > - > - memsw_max = memcg->memsw.max; > - swap_max = READ_ONCE(memcg->swap.max); > - swap_max = min(swap_max, (unsigned long)total_swap_pages); > - max = min(max + swap_max, memsw_max); > + unsigned long max = READ_ONCE(memcg->memory.max); > + > + if (cgroup_subsys_on_dfl(memory_cgrp_subsys)) { > + if (mem_cgroup_swappiness(memcg)) > + max += min(READ_ONCE(memcg->swap.max), > + (unsigned long)total_swap_pages); > + } else { /* v1 */ > + if (mem_cgroup_swappiness(memcg)) > + max = 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 = PAGE_COUNTER_MAX which is not something we want, right? instead you want max += min(READ_ONCE(memcg->memsw.max), total_swap_pages); > } > return max; > } > -- > 2.18.1 > -- Michal Hocko SUSE Labs