Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1574172pxa; Thu, 20 Aug 2020 15:05:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxljjdjehg+asvOf3NB267WGzoCggYxyDzQ56Hq+RghhClU36COkrOmRsSkYLYEiDPuGOgo X-Received: by 2002:aa7:d809:: with SMTP id v9mr28233edq.94.1597961136260; Thu, 20 Aug 2020 15:05:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597961136; cv=none; d=google.com; s=arc-20160816; b=oAfEN+J574ja1WWJv+gHmR3fRrMH6roHIVtoIbMK1spqfRwBF6Z4cEHXIZUyZ3qHnL KwdV+vdS/hTmB9/Pmq8eG1zWeKQOEuOgZhneEXdBJOvmd6k3yGE5H5mYgodwnNgahQ/W VjCkumWUprvzmVYNAhxPXxER8jBh6GxIhJmWi2PVPRgKKt74xY60MdtPtOkV3PiUnZJC InTm0Tc0Hcd4nCo0xIzEJTOy5yEv9AqiH93YhjOgfHD1ef3LxhMaEGL25MMCWtGzf7Ue eik16RTLkyOsrotLNsrwDzsciZ9N4gpRtrzaEVWZiBSLlkOlcAy8+AELsSY3LJrfYhPF Sqxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=qg7ruuG7drWC0btRbr1uOGU4H3EwWSnI1pvnZe6oIgQ=; b=wyywooufOwSRrNOjurkDTt2SStHHsCTDxDhEhxsGpRlR8MmOC2O1Rl/hgDT+aLP092 VtvMBTn94TGw/ZYQI5edCBmcWWtAK9X7pDoLxi4HiYx8ddjSf2VOy+KNTVDTRX0R74bE qWMJ+y4E+9dcGv5Oy2z2v3ePFs12T9SonVccVHFPo/LkLM8yZ56Vu6VWkfaXMtRyVrqZ Khr7wr5ZTdDDs2+b4PKjP0NyYiyejCYsZziM92Ic+cvvZTP1grANfePEJRxJ6NdYiWGn 0AvNu5AJ8iHG+5dIPlHzCxuo2GrUsykQ7rCj8mOih+in8yIWUhcOO05pifmpCgAg6IRX 8q3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=WYASPIx5; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lc6si2235565ejb.23.2020.08.20.15.05.11; Thu, 20 Aug 2020 15:05:36 -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=@google.com header.s=20161025 header.b=WYASPIx5; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728774AbgHTVZz (ORCPT + 99 others); Thu, 20 Aug 2020 17:25:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727792AbgHTVZy (ORCPT ); Thu, 20 Aug 2020 17:25:54 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AE80C061385 for ; Thu, 20 Aug 2020 14:25:54 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id y2so3722289ljc.1 for ; Thu, 20 Aug 2020 14:25:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=qg7ruuG7drWC0btRbr1uOGU4H3EwWSnI1pvnZe6oIgQ=; b=WYASPIx5hMDjYGgzF+G0RR6vw6melkP0mguy36kGh/wXS2V3ohz4Yii1y0Dtu6iU+C lgRRuCa0Yz5B35a2ewWAKf33bxKi/ZqAeyD8rQWw85LdFb2z8gOVCfCrvbQvZJodRNNh 93t7iBP1COzAj3azTPFpmNT9k287RMuDfF0QdK0dNPN9GZd/Pm2A1vVPjU1lJWZkZaHf nU6xPpk8TwGTW75Mc7AKO0NSOXk++jx1+LU8HnsQ1FWGYEidvRi3cymONp0dCcu0QeUG 4+nCMyIA/qqZc1mDImkpEjw/YDWEjMczSHz8TTIH2lTkWLwJ5jB54ykxBxVdOEh8OdXx YVpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qg7ruuG7drWC0btRbr1uOGU4H3EwWSnI1pvnZe6oIgQ=; b=Zk8YFnxQcxzPElEnJBhWQz/F6pn4xpAMh7yeDc+kKEatIaUUc9dOeKrFh6y3Exs1nG Fdl/rJf84SjvMToakXrbD6dk5/R355QsXDZh5nLFB0pwZOX6kOUrXQvvLLHoYPWSi2Z5 BazD9R+GL3P/NmgmnKXUhTB8IrvMVOLkBVDgrq7j9Gx5H0ajxTQtwr4a6qEkwg0HkR0P x7IrlK9VY3u1KwduXEpepDnP0BV26dk5Upu3qoghKN+j4QaF41Gp8McLFAON/01vTL4u budBXzlNT/eRx4Z3eHSvCfLH/kMyuGGR1R0Zc+AEkEkFCggQ5cjLh0xEzknv7EqcKO7B VBsA== X-Gm-Message-State: AOAM532dhqDoDbDRwRWa84zV2eZcaFlpoVaCj0xTPIQCVk0YW1oGZc02 0O+9T7XPZc4vQQSZ6A9fsPRUmptb9yobwRW1wG2gyw== X-Received: by 2002:a2e:9396:: with SMTP id g22mr121322ljh.446.1597958752359; Thu, 20 Aug 2020 14:25:52 -0700 (PDT) MIME-Version: 1.0 References: <20200820130350.3211-1-longman@redhat.com> <20200820130350.3211-3-longman@redhat.com> <20200820173546.GB912520@cmpxchg.org> In-Reply-To: From: Shakeel Butt Date: Thu, 20 Aug 2020 14:25:41 -0700 Message-ID: Subject: Re: [PATCH 2/3] mm/memcg: Simplify mem_cgroup_get_max() To: Waiman Long Cc: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Tejun Heo , LKML , Cgroups , Linux MM , Chris Down , Roman Gushchin , Yafang Shao Content-Type: text/plain; charset="UTF-8" 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 1:29 PM Waiman Long wrote: > > On 8/20/20 1:35 PM, Johannes Weiner wrote: > > 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. > > > Sure. That makes it even better. > Can you please also add in the commit message why it is ok to drop total_swap_pages comparison from mem_cgroup_get_max()?