Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2100303pxk; Mon, 14 Sep 2020 04:59:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7KGSk10EjLdA7Aaw+/bE8AiBVLjttojwEy2AQ1ZOaCgh+OTxpkU8NL+HW29QxAJK4yaOp X-Received: by 2002:a50:875b:: with SMTP id 27mr16472319edv.117.1600084742980; Mon, 14 Sep 2020 04:59:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600084742; cv=none; d=google.com; s=arc-20160816; b=zGV9nPvZrsdCgblrwYjHB8pSUUsOqM2eFQa2qePDkIlHbPAthOyn/n8IQp7+WulvfR rLtkn5lZYgD5lsUCIBxUECAeGsEAdcxn47qcAwlk8Qn3abGEVhy2UBW9cmp1zeMy49si TSfRNE3tVnMrbGKhNDnTBtjpVykjSPIF7VROUJduG9iy3Q7nfCL/Ie4JAxOlWCAdmxTi saRneuTgg/diTpRpj7Nbupcv61GlNJbV7jERMJdViIcyDKJapJBYJanb1gbLdehSrj0B RgY4e1CP5CmqrxGzlo3xx9BeNacaf5bnHu/gDXuzciL3p5h3HHR3rfyRfNxkEwbkBgqv EOog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=vGoX1cYVIdlY57o+02NiYH886200jJcg94c6aMqzc/k=; b=pBcv2TXr+p1K1bbIIhLPDspFWOwJe4Ls5POO35+McClDZSTAl0FKSKyPeSiLC9TV4o uhPY+Xztc95HRf8IS8Fxcfz1xanI3hEktK0TLZWEg7IV3SSVy6+dTyuZsWUnr000huYt t5VaNg1WvCHvgi3L5CBLPSIhew6eK+Nf1RgLxedmF6XO05BcLhS6VF4v8L5jdGI3Yb6r cmpuQLi+CtUiieetsRSYvt49YiIDCVICdgmh0/qk9AVbqzKEJ+CcF86gTilArYXFaXN9 7HK/4n5vRTwtpAlGzrqxc66dFQlbz5sj4F3jLOpgli/xlDvloW/UOrpF5I75YLYHaDgQ lEOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f8si6763301edm.193.2020.09.14.04.58.40; Mon, 14 Sep 2020 04:59:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726176AbgINL5g (ORCPT + 99 others); Mon, 14 Sep 2020 07:57:36 -0400 Received: from mx2.suse.de ([195.135.220.15]:58736 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726145AbgINLs1 (ORCPT ); Mon, 14 Sep 2020 07:48:27 -0400 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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