Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4587387yba; Wed, 17 Apr 2019 14:56:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqz2kL9IMjFNYeJoOKA6TQG6hb/Y5QuK+7aUN9FxftWchVLEyh50quPP/wxI0Vdf9AfE+gMo X-Received: by 2002:a63:5061:: with SMTP id q33mr86111600pgl.218.1555538182215; Wed, 17 Apr 2019 14:56:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555538182; cv=none; d=google.com; s=arc-20160816; b=fUs2El1K0AWzqO0g6+3yV0Nh10nJOcw9O8RQZl1J2ljR44ps0mA9SNuiAd/WItz7Xd HWuu9WBs2DJblqkWZfgJd7RE/qsSdfoYkO7/Gm91SVvj7JUpH3uAavf2OEuveOSn0PtG Edk+icfWeMV5zOPeXf+2jka7gB1/lD5y/0ZPkKKjKPPauXC5UoOE+fukDvmQuwAX/jwu f5SaD3qR34UJaaKwrKpIyDllkATP7FUY3FymXerKw4cXSz1xJwzwGlYl6ULgonxciFDD DHq6a4w7yuRwDFRCvh1pKzugoFICDercre7vnmAmOyEX6nz4l+ACKXQjngkHfip1/v3T d9QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cRmr36eXTaKgScK2fa3yPK15EeGvQLf0Lc+faeDoG3Q=; b=jJQG/LKbLTddDBKKm/Yb/ji9nXnDfI4bXA1KEm4SwXpygzoVGLU700kl7LNyg10RAH 2stqu6pnQ7B5IyAAwFqVIZI5NdoP6D47KwzBmKOidLOO4CiKiu0RtrviklJJdqndXxVc rs3B+eDYU/mPR/x/B/4UuubNvWcimKnoEYaIofGJPsZ5l5PSLyEXP0R5rijo/q7nUlMi CeixRnKVTR0JcjrGFXuiJlbSi6ieMqDoinjA1grvKaILdloEq0RDSMZl7ansOuqSPrrG OlZhh0TMnK4rupoN2UJWIbDef5ZmKO4UfKIAm0LASeJMnh75W1nsNMjaivw/bFu8wtwx yMmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NTl4XRWo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j143si279774pfd.124.2019.04.17.14.56.07; Wed, 17 Apr 2019 14:56:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NTl4XRWo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387595AbfDQVy7 (ORCPT + 99 others); Wed, 17 Apr 2019 17:54:59 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:42132 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387578AbfDQVy6 (ORCPT ); Wed, 17 Apr 2019 17:54:58 -0400 Received: by mail-pf1-f194.google.com with SMTP id w25so82283pfi.9; Wed, 17 Apr 2019 14:54:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cRmr36eXTaKgScK2fa3yPK15EeGvQLf0Lc+faeDoG3Q=; b=NTl4XRWoAOp1/x1XLk1hvjEAxMAeJ6AzgfrCpOEahhVu5/jEYVGYy9d8pQy0Q15Q5U Af+lGn62qofRvBvBdvBMEbsEt60SVxN4kbLUVNa3p4G04O0b3J0+eI/IK/fQuiBqxiS6 WiuryM9qYvtgVaF+gjTGm1N4hsHjkIoMrNg+aPLTfQz5+EXgGtkXNKvE9FYVv7RBNw+3 //6RWegxUI3mqwV1pBVcvVWJrvdru3y0dvGNdNFFl8qK0pwHGJLQr9whaDrPGVDFzW8S 2zjbStnsuX0AEOR3NxF66n1IsvnQg5X6M9nueJXmXqIsgr7PkbG+bqIfS8Q3nPtlQuZA XMrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cRmr36eXTaKgScK2fa3yPK15EeGvQLf0Lc+faeDoG3Q=; b=EBGHnFl2/pCVdVI++j67KLqMqlPj5q4plo54TYqU73LxdLY5sZwxG20jyMH2Kojq02 lPwbTD766qXeB3uVce28+0TezB4wsNL+rCpgRml7PgOUVquG4Bu0kPFj/8/taR0hrHDB dWrhzSOChlIGexghvI3N8V+pGj7K286pCWGNe3TZBh5noxB7lpr9vLjvkRjfZjvHqTDp 6R444xq30GkrLMmYCHh1WSeioSSG0lf/1ULOJ94wDrmb950yMi0tGsEyBWYk0ZPAGdly qKASis1NJhezaLKOi7ISgxHcpMI2Etc3Y2IdFrbzjkgtF4rvgpxL4VhId51JL0IL5jvW vbzg== X-Gm-Message-State: APjAAAXZgQQF1uX/KEgLD7VUl7nOWoZJAxKmlRT9V9D7jh0vxRDCem9M aVv8z0vyRP04ENVhUDlh6xg= X-Received: by 2002:a63:d713:: with SMTP id d19mr28640839pgg.145.1555538097772; Wed, 17 Apr 2019 14:54:57 -0700 (PDT) Received: from tower.thefacebook.com ([2620:10d:c090:200::5597]) by smtp.gmail.com with ESMTPSA id x6sm209024pfb.171.2019.04.17.14.54.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Apr 2019 14:54:57 -0700 (PDT) From: Roman Gushchin X-Google-Original-From: Roman Gushchin To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Johannes Weiner , Michal Hocko , Rik van Riel , david@fromorbit.com, Christoph Lameter , Pekka Enberg , Vladimir Davydov , cgroups@vger.kernel.org, Roman Gushchin Subject: [PATCH 3/5] mm: introduce __memcg_kmem_uncharge_memcg() Date: Wed, 17 Apr 2019 14:54:32 -0700 Message-Id: <20190417215434.25897-4-guro@fb.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190417215434.25897-1-guro@fb.com> References: <20190417215434.25897-1-guro@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Let's separate the page counter modification code out of __memcg_kmem_uncharge() in a way similar to what __memcg_kmem_charge() and __memcg_kmem_charge_memcg() work. This will allow to reuse this code later using a new memcg_kmem_uncharge_memcg() wrapper, which calls __memcg_kmem_unchare_memcg() if memcg_kmem_enabled() check is passed. Signed-off-by: Roman Gushchin --- include/linux/memcontrol.h | 10 ++++++++++ mm/memcontrol.c | 25 +++++++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 36bdfe8e5965..deb209510902 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1298,6 +1298,8 @@ int __memcg_kmem_charge(struct page *page, gfp_t gfp, int order); void __memcg_kmem_uncharge(struct page *page, int order); int __memcg_kmem_charge_memcg(struct page *page, gfp_t gfp, int order, struct mem_cgroup *memcg); +void __memcg_kmem_uncharge_memcg(struct mem_cgroup *memcg, + unsigned int nr_pages); extern struct static_key_false memcg_kmem_enabled_key; extern struct workqueue_struct *memcg_kmem_cache_wq; @@ -1339,6 +1341,14 @@ static inline int memcg_kmem_charge_memcg(struct page *page, gfp_t gfp, return __memcg_kmem_charge_memcg(page, gfp, order, memcg); return 0; } + +static inline void memcg_kmem_uncharge_memcg(struct page *page, int order, + struct mem_cgroup *memcg) +{ + if (memcg_kmem_enabled()) + __memcg_kmem_uncharge_memcg(memcg, 1 << order); +} + /* * helper for accessing a memcg's index. It will be used as an index in the * child cache array in kmem_cache, and also to derive its name. This function diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 48a8f1c35176..b2c39f187cbb 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2750,6 +2750,22 @@ int __memcg_kmem_charge(struct page *page, gfp_t gfp, int order) css_put(&memcg->css); return ret; } + +/** + * __memcg_kmem_uncharge_memcg: uncharge a kmem page + * @memcg: memcg to uncharge + * @nr_pages: number of pages to uncharge + */ +void __memcg_kmem_uncharge_memcg(struct mem_cgroup *memcg, + unsigned int nr_pages) +{ + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) + page_counter_uncharge(&memcg->kmem, nr_pages); + + page_counter_uncharge(&memcg->memory, nr_pages); + if (do_memsw_account()) + page_counter_uncharge(&memcg->memsw, nr_pages); +} /** * __memcg_kmem_uncharge: uncharge a kmem page * @page: page to uncharge @@ -2764,14 +2780,7 @@ void __memcg_kmem_uncharge(struct page *page, int order) return; VM_BUG_ON_PAGE(mem_cgroup_is_root(memcg), page); - - if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) - page_counter_uncharge(&memcg->kmem, nr_pages); - - page_counter_uncharge(&memcg->memory, nr_pages); - if (do_memsw_account()) - page_counter_uncharge(&memcg->memsw, nr_pages); - + __memcg_kmem_uncharge_memcg(memcg, nr_pages); page->mem_cgroup = NULL; /* slab pages do not have PageKmemcg flag set */ -- 2.20.1