Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1414575pxa; Thu, 20 Aug 2020 10:38:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWyitniXjD10B6g1r1sqfPi5ejJNG18JtIh066WmOIGpBz87yT3mJTCN6lMBbMvkWEB9RX X-Received: by 2002:a17:906:d92:: with SMTP id m18mr4529854eji.428.1597945127166; Thu, 20 Aug 2020 10:38:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597945127; cv=none; d=google.com; s=arc-20160816; b=L+Y8E0dJqmMBG76Lrho6pisskOuZVlw/RfSX8crhXfKOZTgo1nWsEfjGk8+iL+N8hT Vu8DrlGfg2Au0Cx6f6P0q0fyQlFGCEXUaaTjYx8xtwyP+61z7qdb7YQln8PRUBvCcy60 2Uzei4C3VzN13womexGfRdiwkrcPu9YmizTW1pi5Sn6fh3WQYzZj4Z9l9bwMeghPKTfA 3CoAnmr77VG+CjHGx3m2rBsRNO3067hxxWEDlAGEVlFdC7eyDCtkWPtsUTQUBNXkxQAi doFMBDEVlsOl+8Q8ROn7JrA8VFywkCiNCWVOEbAeTsqFq6Tkm8CI/njZ2Ib0LyJmJ00h PQVg== 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 :dkim-signature; bh=LoboofYleSqsx6Po76z6KtFKykk6O4/M/law9ADONhQ=; b=M6ao8o8LgppcZnb9Gf8y1RVqFVjB+WMQJLjBP81aKY2cPJ11ncdG49Xhy/iZ3e2PIo /m1JXen5flAdHF014Kir46dS0Rpvma1Dtpz4E8x4UuhKOgjYAZMT34qk32Fgc/ibAJSc SeNfHVoTIMnOLRgtxl4sSS6SRdFCjRT4Ins7kWvjhsUJq31d36MODhWDRept2SQXjt+4 reDi/6OchB6vSmMe+H7yFT3ENhHHH5YuJZW34butAj2Em4ilB+ha8Mvvjlxwhvdl8sWM apkUoIBgTO3FoMKlZ5j+akiPyKUVxbKu+d88GYefUmLMLV6bYWorHMqaXrBA+1iga9gN B9Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=bqapqgbG; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g18si1605844ejb.224.2020.08.20.10.38.21; Thu, 20 Aug 2020 10:38:47 -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; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=bqapqgbG; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730609AbgHTRhN (ORCPT + 99 others); Thu, 20 Aug 2020 13:37:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729122AbgHTRhD (ORCPT ); Thu, 20 Aug 2020 13:37:03 -0400 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52BFBC061385 for ; Thu, 20 Aug 2020 10:37:03 -0700 (PDT) Received: by mail-qt1-x843.google.com with SMTP id x12so1799273qtp.1 for ; Thu, 20 Aug 2020 10:37:03 -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:in-reply-to; bh=LoboofYleSqsx6Po76z6KtFKykk6O4/M/law9ADONhQ=; b=bqapqgbGxSqIpTZ9lqM1OdRQ4ld0i+GkD+9Nmxa1GUtaiBn/O9VbQypsMHolHj0z6R O5BVPWUTxs1lPqRKqLIHUGDCBJLiJ4iTA7HIC6qB9jSaJjvKbm8SI/1kvGieeG0doLWJ OCDi+LYKIfxOKRk0/y7qOPc8DpMwu+WU3vD+l8KIvb21LNwGFGLgzaQthypuZUWvs+rs oJCpu+HfrIXROzi0WhrBWx4WpDDfRvE0lUwTcbI+9/X0czS0xt7v14LrRI0jg5MRRTp/ LBDfwgBeTz7UfF8zOvwgvyF3yu6ue4PzybmMEWhEHmy34YliUAVBRRucg//JTWS0mIdc WDfA== 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:in-reply-to; bh=LoboofYleSqsx6Po76z6KtFKykk6O4/M/law9ADONhQ=; b=Zr53uYGofj71/+DY5++AfU7O5nJaZ/l9E/yVa3H6bkPAFLbMNdlZvrEex+ocw5Jo67 Y1fyEX2a9DKv6ZWt1S7hVVJO4HXubfzZyL4cCqoyFZudjf7Da5Ac8oG609cTr7yCT3NQ 8mGHfzBsWX+MME58n1hqscdAEwL2bw/zoD1yrMIUzNKYow0bWto9IS+FEMvT80l2PSaV gwJdpycizuOAgsK0e7cABR5Z8rOG5SdJnpQQpL4arZ9pCwEOSC8nOm7v4YahwzLkAcvZ E+McRjrLqcHcrC7MDVXnkmAJ4o4b3Nt4q8i9CIOCImci2/anI7ZcqarcLo38SfhFrfRY Fg2Q== X-Gm-Message-State: AOAM532ECipM38VZUlYK2E6bQgRyYoaDF9k8jowHhlZNre9Pt+u0QFxp zfJ6J5Iq8Opj8/vQdv4ehVpLsw== X-Received: by 2002:ac8:c0e:: with SMTP id k14mr3885478qti.364.1597945021939; Thu, 20 Aug 2020 10:37:01 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1:3cdd]) by smtp.gmail.com with ESMTPSA id k11sm2653665qkk.93.2020.08.20.10.37.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2020 10:37:01 -0700 (PDT) Date: Thu, 20 Aug 2020 13:35:46 -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 2/3] mm/memcg: Simplify mem_cgroup_get_max() Message-ID: <20200820173546.GB912520@cmpxchg.org> References: <20200820130350.3211-1-longman@redhat.com> <20200820130350.3211-3-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200820130350.3211-3-longman@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 20, 2020 at 09:03:49AM -0400, 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 | 14 +++++--------- > 1 file changed, 5 insertions(+), 9 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 26b7a48d3afb..d219dca5239f 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -1633,17 +1633,13 @@ void mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg) > */ > unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg) > { > - unsigned long max; > + unsigned long max = READ_ONCE(memcg->memory.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); > + if (cgroup_subsys_on_dfl(memory_cgrp_subsys)) > + max += READ_ONCE(memcg->swap.max); > + else > + max = memcg->memsw.max; I agree with the premise of the patch, but v1 and v2 have sufficiently different logic, and the way v1 overrides max from the innermost branch again also doesn't help in understanding what's going on. Can you please split out the v1 and v2 code? if (cgroup_subsys_on_dfl(memory_cgrp_subsys)) { max = READ_ONCE(memcg->memory.max); if (mem_cgroup_swappiness(memcg)) max += READ_ONCE(memcg->swap.max); } else { if (mem_cgroup_swappiness(memcg)) max = memcg->memsw.max; else max = READ_ONCE(memcg->memory.max); } It's slightly repetitive, but IMO much more readable.