From: Waiman Long Subject: [PATCH 2/3] mm/memcg: Simplify mem_cgroup_get_max() Date: Thu, 20 Aug 2020 09:03:49 -0400 Message-ID: <20200820130350.3211-3-longman@redhat.com> References: <20200820130350.3211-1-longman@redhat.com> Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597928658; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=kBu3kMgySM1JmJ3UbrHPhytTu9PiX289muKYqVsxxD0=; b=cleW8DPeygNMfRwKU0pSoyW/rhS/k607AR/mDmGP6wcLQhqSs/LGHtEyGDr0qPfEHoOD9D +K+uHNH+B/cQboo4AQ/PBM7NbLJ7HOBkiJcCy4QwGc/QAMyxltEVvVhVycj6oU0f+tBQge NzUIBcgyZY7FjuD4YC80X7DvBQg44UA= In-Reply-To: <20200820130350.3211-1-longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> Sender: cgroups-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Tejun Heo Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, Shakeel Butt , Chris Down , Roman Gushchin , Yafang Shao , Waiman Long 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; } return max; } -- 2.18.1