Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp345400pxu; Thu, 7 Jan 2021 06:35:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJzlWfwoAJvqIAFYR1vnIdLEL7QDL9SUx1c1dIg/qZ9wgxl9D04uUONI5EOzzuVh6grL+oFn X-Received: by 2002:aa7:d2d3:: with SMTP id k19mr1873995edr.28.1610030155333; Thu, 07 Jan 2021 06:35:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610030155; cv=none; d=google.com; s=arc-20160816; b=A+2rHYxY0eKkMAvxvt21N1acoJBlGv/uSJ3nXAJuISO4u20kHy3bspFr+HlH6EHjZW /E0ofhfNODKJcJ3t7mBtyMajhhq4nyqWuRe1i31J33iWl935du6bf9XpxDEdRKfQPIDP PGMO8glYNgEDMP+UMuYOWY+wM9JfvF1vxXcDp0ZOWUUfmhKWrLMwM/GfR4EIqTZKfzX3 nNlvfdxKCSlID4f+OserZywffF9OxzxJiWkbX+aDVWQteVlKPGPunkwit02qYpIUGkgn EcSYbMNqU9DM8HUKgjq4rp5XVbp+pNKEP8g0Uag/Q6MKGnsfRONwCXZglL2U7m+feKYk Zsdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=aqZzK3Vkwc6Zd7rh7micAiTm7C7gBdI/Vyr6pt0XNBs=; b=NKgPq8279rABN+3dXXb/moh5hRXRKkWxr+ChewVZf2VwN4WdpMXth4vKsiPUWMgUYV 5D3SD4+7VmxpMOB/vxsxcclBvmufmz41qjBbo5eibvM0imrA7zvZvRm9aIakj68B5bq3 cjei0L6bQf8POjWKUZdvy+4vKtqASIzLb/hGTFkSq1Kt75ae4moLKCUA2VHol8xNcAlu PciVY6YkVi0BcIvxcInF7lQg6/6Xc2q7QcHuHXOXL5KVFIY3wc2Osiion9aLLjj3ZnGf HJ9vPe/7ha9WHPU6bAvMTFsWKTBjoaKpAg47NgURh2rNgbpXOdjXDBFUPIbM5sMnAEbc 36Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NtbQEUuX; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p10si2285344eji.254.2021.01.07.06.35.31; Thu, 07 Jan 2021 06:35:55 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=NtbQEUuX; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729416AbhAGOci (ORCPT + 99 others); Thu, 7 Jan 2021 09:32:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:46510 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729337AbhAGOc1 (ORCPT ); Thu, 7 Jan 2021 09:32:27 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2191A208A9; Thu, 7 Jan 2021 14:31:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610029888; bh=f4vhq9KKECt90I+ZBtZ2i5ARE0XL8YZKLdTxRXOPHJc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NtbQEUuXY37wOueB5g1oAIfzwOKTtbeZzTuiGYLVwt5gdyVXmlehuGMZxv94H+qXI K3UWHnm6DLJswgSBO/WEO9p0i+9hOjdbPiCnTxKvvXVwnB9p5GEbPqt7jJtt53zWlQ 9zkqIF6gouWlabxnHHPcoS3MHTmbw7SicX1zQdFo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Johannes Weiner , Vladimir Davydov , Michal Hocko , Andrew Morton , Linus Torvalds , Shaoying Xu Subject: [PATCH 4.14 07/29] mm: memcontrol: implement lruvec stat functions on top of each other Date: Thu, 7 Jan 2021 15:31:22 +0100 Message-Id: <20210107143053.956822483@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210107143052.973437064@linuxfoundation.org> References: <20210107143052.973437064@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Johannes Weiner commit 284542656e22c43fdada8c8cc0ca9ede8453eed7 upstream The implementation of the lruvec stat functions and their variants for accounting through a page, or accounting from a preemptible context, are mostly identical and needlessly repetitive. Implement the lruvec_page functions by looking up the page's lruvec and then using the lruvec function. Implement the functions for preemptible contexts by disabling preemption before calling the atomic context functions. Link: http://lkml.kernel.org/r/20171103153336.24044-2-hannes@cmpxchg.org Signed-off-by: Johannes Weiner Acked-by: Vladimir Davydov Cc: Michal Hocko Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Cc: stable@vger.kernel.org Signed-off-by: Shaoying Xu Signed-off-by: Greg Kroah-Hartman --- include/linux/memcontrol.h | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -569,51 +569,51 @@ static inline void __mod_lruvec_state(st { struct mem_cgroup_per_node *pn; + /* Update node */ __mod_node_page_state(lruvec_pgdat(lruvec), idx, val); + if (mem_cgroup_disabled()) return; + pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec); + + /* Update memcg */ __mod_memcg_state(pn->memcg, idx, val); + + /* Update lruvec */ __this_cpu_add(pn->lruvec_stat->count[idx], val); } static inline void mod_lruvec_state(struct lruvec *lruvec, enum node_stat_item idx, int val) { - struct mem_cgroup_per_node *pn; - - mod_node_page_state(lruvec_pgdat(lruvec), idx, val); - if (mem_cgroup_disabled()) - return; - pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec); - mod_memcg_state(pn->memcg, idx, val); - this_cpu_add(pn->lruvec_stat->count[idx], val); + preempt_disable(); + __mod_lruvec_state(lruvec, idx, val); + preempt_enable(); } static inline void __mod_lruvec_page_state(struct page *page, enum node_stat_item idx, int val) { - struct mem_cgroup_per_node *pn; + pg_data_t *pgdat = page_pgdat(page); + struct lruvec *lruvec; - __mod_node_page_state(page_pgdat(page), idx, val); - if (mem_cgroup_disabled() || !page->mem_cgroup) + /* Untracked pages have no memcg, no lruvec. Update only the node */ + if (!page->mem_cgroup) { + __mod_node_page_state(pgdat, idx, val); return; - __mod_memcg_state(page->mem_cgroup, idx, val); - pn = page->mem_cgroup->nodeinfo[page_to_nid(page)]; - __this_cpu_add(pn->lruvec_stat->count[idx], val); + } + + lruvec = mem_cgroup_lruvec(pgdat, page->mem_cgroup); + __mod_lruvec_state(lruvec, idx, val); } static inline void mod_lruvec_page_state(struct page *page, enum node_stat_item idx, int val) { - struct mem_cgroup_per_node *pn; - - mod_node_page_state(page_pgdat(page), idx, val); - if (mem_cgroup_disabled() || !page->mem_cgroup) - return; - mod_memcg_state(page->mem_cgroup, idx, val); - pn = page->mem_cgroup->nodeinfo[page_to_nid(page)]; - this_cpu_add(pn->lruvec_stat->count[idx], val); + preempt_disable(); + __mod_lruvec_page_state(page, idx, val); + preempt_enable(); } unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order,