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,URIBL_BLOCKED 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 B8639C2BC11 for ; Mon, 14 Sep 2020 15:18:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6033120639 for ; Mon, 14 Sep 2020 15:18:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6033120639 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 DEB07900004; Mon, 14 Sep 2020 11:18:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D9AA3900003; Mon, 14 Sep 2020 11:18:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB12D900004; Mon, 14 Sep 2020 11:18:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0206.hostedemail.com [216.40.44.206]) by kanga.kvack.org (Postfix) with ESMTP id B3064900003 for ; Mon, 14 Sep 2020 11:18:38 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 667F38249980 for ; Mon, 14 Sep 2020 15:18:38 +0000 (UTC) X-FDA: 77262023916.09.quilt02_501258027109 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id 2D5EA180AD804 for ; Mon, 14 Sep 2020 15:18:38 +0000 (UTC) X-HE-Tag: quilt02_501258027109 X-Filterd-Recvd-Size: 3077 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Mon, 14 Sep 2020 15:18:37 +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 2882EB52E; Mon, 14 Sep 2020 15:18:52 +0000 (UTC) Date: Mon, 14 Sep 2020 17:18:36 +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 v4 2/3] mm/memcg: Simplify mem_cgroup_get_max() Message-ID: <20200914151836.GB16999@dhcp22.suse.cz> References: <20200914024452.19167-1-longman@redhat.com> <20200914150928.7841-1-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200914150928.7841-1-longman@redhat.com> X-Rspamd-Queue-Id: 2D5EA180AD804 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 Mon 14-09-20 11:09:28, 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 Acked-by: Michal Hocko Thanks! > --- > mm/memcontrol.c | 24 +++++++++++++----------- > 1 file changed, 13 insertions(+), 11 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 8c74f1200261..cad1ac4551ad 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)) { > + /* Calculate swap excess capacity from memsw limit */ > + unsigned long swap = READ_ONCE(memcg->memsw.max) - max; > + > + max += min(swap, (unsigned long)total_swap_pages); > + } > } > return max; > } > -- > 2.18.1 -- Michal Hocko SUSE Labs