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 EBA67C43461 for ; Mon, 14 Sep 2020 14:47:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 80257207EA for ; Mon, 14 Sep 2020 14:47:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 80257207EA 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 ADFF16B0037; Mon, 14 Sep 2020 10:47:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A90766B005D; Mon, 14 Sep 2020 10:47:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9A7196B0062; Mon, 14 Sep 2020 10:47:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0050.hostedemail.com [216.40.44.50]) by kanga.kvack.org (Postfix) with ESMTP id 823246B0037 for ; Mon, 14 Sep 2020 10:47:44 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 2FE25181AC9CC for ; Mon, 14 Sep 2020 14:47:44 +0000 (UTC) X-FDA: 77261946048.27.tank10_3c001f827109 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id CDE973D670 for ; Mon, 14 Sep 2020 14:47:41 +0000 (UTC) X-HE-Tag: tank10_3c001f827109 X-Filterd-Recvd-Size: 3308 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Mon, 14 Sep 2020 14:47:41 +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 42EC4AD11; Mon, 14 Sep 2020 14:47:55 +0000 (UTC) Date: Mon, 14 Sep 2020 16:47:39 +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 v3 2/3] mm/memcg: Simplify mem_cgroup_get_max() Message-ID: <20200914144739.GV16999@dhcp22.suse.cz> References: <20200914024452.19167-1-longman@redhat.com> <20200914141955.2145-1-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200914141955.2145-1-longman@redhat.com> X-Rspamd-Queue-Id: CDE973D670 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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 14-09-20 10:19:55, 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 | 24 +++++++++++++----------- > 1 file changed, 13 insertions(+), 11 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 8c74f1200261..2331d4bc7c4d 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -1633,17 +1633,19 @@ 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)) { > + unsigned long memsw = READ_ONCE(memcg->memsw.max); > + > + if (memsw > max) > + max += min(memsw - max, (unsigned long)total_swap_pages); Yes this looks better. But, memsw can never be smaller than the hard limit (mem_cgroup_resize_max). I would find it slightly easier to understand if you did /* calculate swap excess capacity from memsw limit*/ unsigned long memsw = READ_ONCE(memcg->memsw.max) - max; max += min (memsw, total_swap_pages); > + } > } > return max; > } > -- > 2.18.1 -- Michal Hocko SUSE Labs