Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1222847pxa; Thu, 20 Aug 2020 06:06:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXMFJ07Kqx3NEKf+646KAlqxOM+PGcB6iEMDQQIksLj31K1G2iXNTEoPu0RGhzvqibz7vs X-Received: by 2002:a17:906:aad2:: with SMTP id kt18mr3272819ejb.537.1597928775517; Thu, 20 Aug 2020 06:06:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597928775; cv=none; d=google.com; s=arc-20160816; b=GvafqutgJHtBbwULx0lNnzgMMWB50u8KVDHIuwaUXYpmn5W9uvyBYZFGdAxa7x6Kxt fQi1+VCWMklsTmluVmQe2VVh0nDF54U0PcyBSZHrX2IvGnJJKztJGVnFoHU/tjSufWxO ovhUgTWdJhZHerUmh83aUAHtV5EtyxITxlxv9rfv//l5o+lMY4BYutkQMzMB2lGroiwD QMv/dP5SfANSX8TEXjHKLH0umwnZEs8PogR7Dc8OIuRdLAhIRsnRGVRndBhrUrjPuxTW 6n2YJkX3U18L2k0pqA0HV8QIET3YKOi3GcgD3U4M4Zv65lJRyzcS9bhkMXARqa3QMlwJ 2ySA== 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=kBu3kMgySM1JmJ3UbrHPhytTu9PiX289muKYqVsxxD0=; b=eOicxlWuqIn6ObT0aVZpa4c+4EVRF9C3sQjNPZKJ2kUg/oRILYBicM+FvqIdrRjcKj uwvzZuX30cfLIfb9UCMdpS2zhtecghrp1lq5QmhMvs5tPPWMX7/iqEjPa5xpzQLH8NwG yniaNno0zLXic3cKtEXVRS4xv7L8JEAZEjvThFvvg8/+Gq/Zk0lcsR+FSxhR0usDCHOM 5WleP6E0F9fCNQiccTTz3gYbLJ8dIzGTrLxlR0+Z48hvCjdG9eMYex5cBB+NdRI7/i0r 1Uzmz5ngApyLUb3Ow2OVmE0cg2UtuJLuK0I8JeaM1VzzrHFGEsB9DGHhebA6vUkrP+fz 1vog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cleW8DPe; 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 k5si1195751ejc.446.2020.08.20.06.05.49; Thu, 20 Aug 2020 06:06:15 -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=cleW8DPe; 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 S1729021AbgHTNEn (ORCPT + 99 others); Thu, 20 Aug 2020 09:04:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:35419 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730070AbgHTNEV (ORCPT ); Thu, 20 Aug 2020 09:04:21 -0400 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= 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-38-_GR2kcr7MCGriJw5680LiA-1; Thu, 20 Aug 2020 09:04:14 -0400 X-MC-Unique: _GR2kcr7MCGriJw5680LiA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9F9AE1006296; Thu, 20 Aug 2020 13:04:12 +0000 (UTC) Received: from llong.com (unknown [10.10.115.249]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E2997A1F4; Thu, 20 Aug 2020 13:04:11 +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 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> In-Reply-To: <20200820130350.3211-1-longman@redhat.com> References: <20200820130350.3211-1-longman@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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 | 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