From patchwork Thu Aug 15 05:04:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 13764399 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3036C52D7F for ; Thu, 15 Aug 2024 05:05:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 43C116B008C; Thu, 15 Aug 2024 01:05:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3762F6B0092; Thu, 15 Aug 2024 01:05:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F1996B0093; Thu, 15 Aug 2024 01:05:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id F0C5D6B008C for ; Thu, 15 Aug 2024 01:05:30 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id AC763120F81 for ; Thu, 15 Aug 2024 05:05:30 +0000 (UTC) X-FDA: 82453291620.19.6F3DCB9 Received: from out-175.mta0.migadu.com (out-175.mta0.migadu.com [91.218.175.175]) by imf23.hostedemail.com (Postfix) with ESMTP id DB205140003 for ; Thu, 15 Aug 2024 05:05:28 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=SSufFwWC; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf23.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.175 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723698248; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zygVeQZHpWPOjOtuooWei0ElZsFf2qNUmjbZYRpm8Xo=; b=5/Cyy8fsSjxt35pz8A00kbub4b1+oQ0C76B43x1u9d8fMYmmSZjkmxX/E+4VXaWkL3iAzk 49Wtng8vuWei9EbJdzl8PohW9lj0OWgaV9PimBut71OokAXO+goNAzwmM2aU9c598SvQxE Hr9UgzVhmLsws49+QbiICj4lna4xGfg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723698248; a=rsa-sha256; cv=none; b=nWmn9Oex8hA8MZVvTAfghEuEI7x9Z/dRn/We7qLEGXQLTXw7j2V6jBiSGs+/RjpNXfq+zu PzmzGD5b7Rda5SvI2gB85ViSV4YUAJiQrbsUkDa4VC99ZViMWLNR/8veFUBLIY6gZMN0mY VWPCDgTw6Jbw3OumP9ZtoWvouYuP+cU= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=SSufFwWC; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf23.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.175 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1723698327; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zygVeQZHpWPOjOtuooWei0ElZsFf2qNUmjbZYRpm8Xo=; b=SSufFwWCrJB8eaH9sXXX9w33eVNxPwPO5BWCNuheXLzNVABd7WZoEprGHuGIUwlN5GrBBN bVriG0DCZ4Y2PnWVKHGPrswvS5dnKDx0K7ZRYh+l9vgp2IrJN7Zpuj595kZK5teC4UFSfz Cy3IRk3vBQKDfZD2kKNw68eArrfs2y8= From: Shakeel Butt To: Andrew Morton Cc: Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , "T . J . Mercier" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Meta kernel team , cgroups@vger.kernel.org Subject: [PATCH 3/7] memcg: move mem_cgroup_charge_statistics to v1 code Date: Wed, 14 Aug 2024 22:04:49 -0700 Message-ID: <20240815050453.1298138-4-shakeel.butt@linux.dev> In-Reply-To: <20240815050453.1298138-1-shakeel.butt@linux.dev> References: <20240815050453.1298138-1-shakeel.butt@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: DB205140003 X-Stat-Signature: i9s8xck5nztyxwgf8mri31e51ddjzzq6 X-Rspam-User: X-HE-Tag: 1723698328-320292 X-HE-Meta: U2FsdGVkX19bdblgoAZCmmUukgBartzNhLRWSWGu5cPEYYb67W92HpE6pppeU6hotxfs8i5yXcNbxdY8RRC5liCOcA4UtSWYNT1qagXIGOxfoFtNJ5xHqYgejY0xg04nK3ntplogHceQtdIzDKskLUsTu62lQWmFtv9QqpLcMtBEIHqC+Ld2aieId8DIv+Lkp6tWaRhJ17INdWw3iJZyZnhNVxbmnAekM43W1jFJws+gknoBc8QPnu2stAe+sg7Nh+l6YKJrJgoo1E7tKz4ufUuKqckSrvJEad0g7CiS+OIksogYtUo0DZlJSnPU2lT5N3azkYDCItW3GQEhnkJGEln3tCy+XkGPcuTcifNYihb0XLsqKJU625GK4zMff/99PlnD37atyQzy0OiyCSdYPs4CB0YgABZ/ZTPjq0Zjoo3sw/DaMzMxxHIrdk3BX24jnNrdzdvhr6SwtTQkb0AaAmwYk6cOkhY2KEcjMDvp9cTOVvy9Ms1SeESFHOoDAVGSLhRGgQAeuJwxPSHMr2rB6r9uhQ6f0FArImJshC/QE0XDfCPsNG7znv1RTsv5HACThXTGesvPSHKqkh5VOgcyp5id7uDrEDHNb2u9DLLrInxyZfEVEcTI7pwdQDvg2c6kM4zn0tgy131AYLHP0jq2RMtTi5jMY8Uj3XrR45Zsq6JzwmJoV3Xr4zLzpHRiYCvMVfM7kZzJb+UF+qszpWd5PNQvQE+buFd69DCgb8cJwfbQDMgU2zZKR65At5xyFcRK7n+zCeDv1U0J8oWsGE+EhdnUKKOQccFqvfO0M4I84uwh9ZuY3WpwAOzMz3zd3yjXBXU/wPBT6uNZs13mk7/qtHUoza+shUq8QscK4bm+ZPgmyv9Ktzv3zQTTfC0ANiwzpXXqsJgtQpoBDimcDJqh4/giVDwU4sH9+GAC9jOrB27aNNdf8HRaOnNnGTkeE7RqIR0K4OiVpXksQTPnXnM 1OKjI43f +rrfa9TgsfcPkby5IG3ZLhzMCtTfWhjtHX8+Qho4nNiCR1u78uzh8gm7vfKHVo+egCSg5HPJFfL1arCJDxHFyKMkxtIDXNbK4iY4yTsfSdWp2GZELpC6gb5BBJ3W+qwHHx3moIyXYoQf2aTqXXTWAFZX5oA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: There are no callers of mem_cgroup_charge_statistics() in the v2 code base, so move it to the v1 only code and rename it to memcg1_charge_statistics(). Signed-off-by: Shakeel Butt --- mm/memcontrol-v1.c | 17 +++++++++++++++-- mm/memcontrol-v1.h | 3 ++- mm/memcontrol.c | 19 +++---------------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c index 0ce1807ba468..73587e6417c5 100644 --- a/mm/memcontrol-v1.c +++ b/mm/memcontrol-v1.c @@ -853,9 +853,9 @@ static int mem_cgroup_move_account(struct folio *folio, nid = folio_nid(folio); local_irq_disable(); - mem_cgroup_charge_statistics(to, nr_pages); + memcg1_charge_statistics(to, nr_pages); memcg1_check_events(to, nid); - mem_cgroup_charge_statistics(from, -nr_pages); + memcg1_charge_statistics(from, -nr_pages); memcg1_check_events(from, nid); local_irq_enable(); out: @@ -1439,6 +1439,19 @@ static void mem_cgroup_threshold(struct mem_cgroup *memcg) } } +void memcg1_charge_statistics(struct mem_cgroup *memcg, int nr_pages) +{ + /* pagein of a big page is an event. So, ignore page size */ + if (nr_pages > 0) + __count_memcg_events(memcg, PGPGIN, 1); + else { + __count_memcg_events(memcg, PGPGOUT, 1); + nr_pages = -nr_pages; /* for event */ + } + + __this_cpu_add(memcg->events_percpu->nr_page_events, nr_pages); +} + #define THRESHOLDS_EVENTS_TARGET 128 #define SOFTLIMIT_EVENTS_TARGET 1024 diff --git a/mm/memcontrol-v1.h b/mm/memcontrol-v1.h index fb7d439f19de..ef72d0b7c5c6 100644 --- a/mm/memcontrol-v1.h +++ b/mm/memcontrol-v1.h @@ -7,7 +7,6 @@ /* Cgroup v1 and v2 common declarations */ -void mem_cgroup_charge_statistics(struct mem_cgroup *memcg, int nr_pages); int try_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp_mask, unsigned int nr_pages); @@ -116,6 +115,7 @@ bool memcg1_oom_prepare(struct mem_cgroup *memcg, bool *locked); void memcg1_oom_finish(struct mem_cgroup *memcg, bool locked); void memcg1_oom_recover(struct mem_cgroup *memcg); +void memcg1_charge_statistics(struct mem_cgroup *memcg, int nr_pages); void memcg1_check_events(struct mem_cgroup *memcg, int nid); void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s); @@ -147,6 +147,7 @@ static inline bool memcg1_oom_prepare(struct mem_cgroup *memcg, bool *locked) { static inline void memcg1_oom_finish(struct mem_cgroup *memcg, bool locked) {} static inline void memcg1_oom_recover(struct mem_cgroup *memcg) {} +static inline void memcg1_charge_statistics(struct mem_cgroup *memcg, int nr_pages) {} static inline void memcg1_check_events(struct mem_cgroup *memcg, int nid) {} static inline void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s) {} diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 7ea511119567..f8db9924d5dc 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -848,19 +848,6 @@ unsigned long memcg_events_local(struct mem_cgroup *memcg, int event) return READ_ONCE(memcg->vmstats->events_local[i]); } -void mem_cgroup_charge_statistics(struct mem_cgroup *memcg, int nr_pages) -{ - /* pagein of a big page is an event. So, ignore page size */ - if (nr_pages > 0) - __count_memcg_events(memcg, PGPGIN, 1); - else { - __count_memcg_events(memcg, PGPGOUT, 1); - nr_pages = -nr_pages; /* for event */ - } - - __this_cpu_add(memcg->events_percpu->nr_page_events, nr_pages); -} - struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p) { /* @@ -2398,7 +2385,7 @@ void mem_cgroup_commit_charge(struct folio *folio, struct mem_cgroup *memcg) commit_charge(folio, memcg); local_irq_disable(); - mem_cgroup_charge_statistics(memcg, folio_nr_pages(folio)); + memcg1_charge_statistics(memcg, folio_nr_pages(folio)); memcg1_check_events(memcg, folio_nid(folio)); local_irq_enable(); } @@ -4775,7 +4762,7 @@ void mem_cgroup_replace_folio(struct folio *old, struct folio *new) commit_charge(new, memcg); local_irq_save(flags); - mem_cgroup_charge_statistics(memcg, nr_pages); + memcg1_charge_statistics(memcg, nr_pages); memcg1_check_events(memcg, folio_nid(new)); local_irq_restore(flags); } @@ -5020,7 +5007,7 @@ void mem_cgroup_swapout(struct folio *folio, swp_entry_t entry) * only synchronisation we have for updating the per-CPU variables. */ memcg_stats_lock(); - mem_cgroup_charge_statistics(memcg, -nr_entries); + memcg1_charge_statistics(memcg, -nr_entries); memcg_stats_unlock(); memcg1_check_events(memcg, folio_nid(folio));