From: Shakeel Butt <shakeel.butt@linux.dev>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: linux-mm@kvack.org
Subject: Re: question on memcg_stats_[un]lock in memcg code
Date: Thu, 13 Mar 2025 18:46:53 -0700 [thread overview]
Message-ID: <cmvmnaosbamr3wzep6nxp5fa5ve6huy6hoerkestpuiwmjmdhu@d6eh2eicqvv2> (raw)
In-Reply-To: <5eqyqywhpgtpulqgnqyvpjivwfasbytgfrmum75ikvmsyhsjzu@xudzfvenzhzl>
On Thu, Mar 13, 2025 at 06:11:30PM -0700, Shakeel Butt wrote:
> Hi Sebastian,
>
> The commit be3e67b54b43 ("mm/memcg: protect per-CPU counter by disabling
> preemption on PREEMPT_RT where needed.") added memcg_stats_lock() and
> other variants in memcontrol.c. There usage were added in
> __mod_memcg_lruvec_state, __count_memcg_events and mem_cgroup_swapout. I
> am wondering why __mod_memcg_state was excluded?
>
Basically I wanted to know if the reason was that there were no direct
caller for __mod_memcg_state and something like the following patch is
fine with new direct caller:
From 6506b9463e2a96d1e9681dcaf6dece75e7050513 Mon Sep 17 00:00:00 2001
From: Shakeel Butt <shakeel.butt@linux.dev>
Date: Thu, 13 Mar 2025 18:27:41 -0700
Subject: [PATCH] memcg: use __mod_memcg_state in drain_obj_stock
For non-PREEMPT_RT kernels, drain_obj_stock() is always called with irq
disabled, so we can use __mod_memcg_state() instead of
mod_memcg_state(). For PREEMPT_RT, we need to add memcg_stats_[un]lock
in __mod_memcg_state().
Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
---
mm/memcontrol.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 4de6acb9b8ec..8ddb9c94db7d 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -700,10 +700,12 @@ void __mod_memcg_state(struct mem_cgroup *memcg, enum memcg_stat_item idx,
if (WARN_ONCE(BAD_STAT_IDX(i), "%s: missing stat item %d\n", __func__, idx))
return;
+ memcg_stats_lock();
__this_cpu_add(memcg->vmstats_percpu->state[i], val);
val = memcg_state_val_in_pages(idx, val);
memcg_rstat_updated(memcg, val);
trace_mod_memcg_state(memcg, idx, val);
+ memcg_stats_unlock();
}
/* idx can be of type enum memcg_stat_item or node_stat_item. */
@@ -2791,7 +2793,7 @@ static struct obj_cgroup *drain_obj_stock(struct memcg_stock_pcp *stock)
memcg = get_mem_cgroup_from_objcg(old);
- mod_memcg_state(memcg, MEMCG_KMEM, -nr_pages);
+ __mod_memcg_state(memcg, MEMCG_KMEM, -nr_pages);
memcg1_account_kmem(memcg, -nr_pages);
__refill_stock(memcg, nr_pages);
--
2.47.1
next prev parent reply other threads:[~2025-03-14 1:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-14 1:11 Shakeel Butt
2025-03-14 1:46 ` Shakeel Butt [this message]
2025-03-14 10:12 ` Sebastian Andrzej Siewior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cmvmnaosbamr3wzep6nxp5fa5ve6huy6hoerkestpuiwmjmdhu@d6eh2eicqvv2 \
--to=shakeel.butt@linux.dev \
--cc=bigeasy@linutronix.de \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox