Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1859354pxk; Sun, 13 Sep 2020 19:46:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHcZVaq2brDEGJ3HWLUlUOSnUVgmyTACZQoj23gln1ayF36ZMR9b22hG7DiPVpTF8cf2sU X-Received: by 2002:a17:907:432b:: with SMTP id ob19mr12619454ejb.400.1600051588983; Sun, 13 Sep 2020 19:46:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600051588; cv=none; d=google.com; s=arc-20160816; b=oIAPmMKUibMIioT+d9ue10Yjmu2QHJiO7e9Ma9Is2RV2oNp6deUwvWZmDAY8ZxX2il NUB2zM23j5ElxVeJJyn80sZ6MfviDBnju7D1nrY08uCgAxFi+aQ0lO0Yhczrk0bna9oR vtBgdQlhobEawj2npWl+9k52MyUsklB2QUkmHV2Ypf+3EA3KtOccpm06JsflwqPF/KWs keVTLGf09XGNxGMzbFsYEj9NXlIGKHmjzt0XxSWvHf50WbKtvTN0MnfMVOtuICCredZs 3A/sMAakl59l/9pKfCuoBFABN+p1SNx65OrazS5XhJAYTi4vnQAwd0XOfYerDPpvr2ll VP/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=ac1RMJJ983xTNNkjK3Roq6fpubHne8/578b+AWco/Fo=; b=uq3MsFFflqx6kqa0dVSUKEzKZB1+ZXVq3vW/wpaD0LAoKE7wt0D/voc1jc11bqqBo2 mwLGxnA38l0M0YE6zUvGqrxypnj3yTvRKbk39kL/mOeXJSuOXHKXR/RRb3gnkCYEB3Gw gftZtZEfRg+YW6SMYyEjVbrE5+A+EUpZnWMk4pFtR8wvOxByw4KXn9Fg/ySJe03kEalx 0auoC/A8TWKt8AOu4KOgoR617xN3yMlVlMuFl+2sfvzyso6fYHrpxAP51S0yq2t7Yhd9 lhWrZzD+DPrPKlBVYioKzLKT4qNeqk2VWf49rW9D0hE67zXVAC4B7mEu0J1eeojbcENE 4IDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=K7NgPFJM; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d2si6471247edz.345.2020.09.13.19.46.06; Sun, 13 Sep 2020 19:46:28 -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=@redhat.com header.s=mimecast20190719 header.b=K7NgPFJM; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726064AbgINCpb (ORCPT + 99 others); Sun, 13 Sep 2020 22:45:31 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:43067 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726058AbgINCpZ (ORCPT ); Sun, 13 Sep 2020 22:45:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600051523; 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=ac1RMJJ983xTNNkjK3Roq6fpubHne8/578b+AWco/Fo=; b=K7NgPFJMH9E18S6T7zwY7cmdDRRe6dSPTY8pNF6BOYWq0gQ3RR23Bqt46+YofJSJfafCbo /VsP1qrK4K+nRFTML3HlixS9V3kcpJIS2xlrJpcFOmc3jMZrIf1LVdnzjrX73QRdT0p73T uXPdivf5cx+Lna5UYNS2w0pHWlRfzzY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-71-oltS5sNFMYymUwryPBaNlw-1; Sun, 13 Sep 2020 22:45:18 -0400 X-MC-Unique: oltS5sNFMYymUwryPBaNlw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 87F3F1074657; Mon, 14 Sep 2020 02:45:16 +0000 (UTC) Received: from llong.com (ovpn-113-90.rdu2.redhat.com [10.10.113.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38A2460BF3; Mon, 14 Sep 2020 02:45:15 +0000 (UTC) From: Waiman Long To: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Tejun Heo Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Shakeel Butt , Chris Down , Roman Gushchin , Yafang Shao , Waiman Long Subject: [PATCH v2 2/3] mm/memcg: Simplify mem_cgroup_get_max() Date: Sun, 13 Sep 2020 22:44:51 -0400 Message-Id: <20200914024452.19167-3-longman@redhat.com> In-Reply-To: <20200914024452.19167-1-longman@redhat.com> References: <20200914024452.19167-1-longman@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } return max; } -- 2.18.1