From: Waiman Long Subject: [PATCH v3 2/3] mm/memcg: Simplify mem_cgroup_get_max() Date: Mon, 14 Sep 2020 10:19:55 -0400 Message-ID: <20200914141955.2145-1-longman@redhat.com> References: <20200914024452.19167-1-longman@redhat.com> Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600093225; 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=HtBSdfoUR8h4s3JfPJeC6QxKphf9QsZWctKie4ScbZc=; b=PdQNTFtZXazXcpJ5FSZgea6zH99q17ZEQVRyYNcXgCHkFgtzziW+nZnXhD9mMu555MOjLd VOLyvJEHQyvB1w0QonolHtKOMjwOIOaGyN2HyG40vgtwxCOvT+Y/NheIK8GtorUQrnZmfF CwJ8V85bGpkkDyVOpLQ87489vooIw6k= In-Reply-To: <20200914024452.19167-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 | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 8c74f1200261..2331d4bc7c4d 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)) { + unsigned long memsw = READ_ONCE(memcg->memsw.max); + + if (memsw > max) + max += min(memsw - max, (unsigned long)total_swap_pages); + } } return max; } -- 2.18.1