From: Haifeng Xu <haifeng.xu@shopee.com>
To: akpm@linux-foundation.org, david@fromorbit.com, roman.gushchin@linux.dev
Cc: zhengqi.arch@bytedance.com, muchun.song@linux.dev,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Haifeng Xu <haifeng.xu@shopee.com>
Subject: [PATCH V2 1/4] mm: shrinker: add one more parameter in shrinker_id()
Date: Tue, 10 Mar 2026 11:12:47 +0800 [thread overview]
Message-ID: <20260310031250.289851-2-haifeng.xu@shopee.com> (raw)
In-Reply-To: <20260310031250.289851-1-haifeng.xu@shopee.com>
Add a parameter points to target memory cgroup in shrinker_id().
The following patch will use it to decide the id of shrinker.
No functional change here.
Signed-off-by: Haifeng Xu <haifeng.xu@shopee.com>
---
include/linux/memcontrol.h | 4 ++--
mm/huge_memory.c | 4 ++--
mm/shrinker.c | 12 ++++++++----
3 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 70b685a85bf4..a583dbc0adcc 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -1634,7 +1634,7 @@ void free_shrinker_info(struct mem_cgroup *memcg);
void set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id);
void reparent_shrinker_deferred(struct mem_cgroup *memcg);
-static inline int shrinker_id(struct shrinker *shrinker)
+static inline int shrinker_id(struct mem_cgroup *memcg, struct shrinker *shrinker)
{
return shrinker->id;
}
@@ -1670,7 +1670,7 @@ static inline void set_shrinker_bit(struct mem_cgroup *memcg,
{
}
-static inline int shrinker_id(struct shrinker *shrinker)
+static inline int shrinker_id(struct mem_cgroup *memcg, struct shrinker *shrinker)
{
return -1;
}
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 8e2746ea74ad..6050f8d71587 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -4353,7 +4353,7 @@ void deferred_split_folio(struct folio *folio, bool partially_mapped)
ds_queue->split_queue_len++;
if (memcg)
set_shrinker_bit(memcg, folio_nid(folio),
- shrinker_id(deferred_split_shrinker));
+ shrinker_id(memcg, deferred_split_shrinker));
}
split_queue_unlock_irqrestore(ds_queue, flags);
}
@@ -4509,7 +4509,7 @@ void reparent_deferred_split_queue(struct mem_cgroup *memcg)
ds_queue->split_queue_len = 0;
for_each_node(nid)
- set_shrinker_bit(parent, nid, shrinker_id(deferred_split_shrinker));
+ set_shrinker_bit(parent, nid, shrinker_id(parent, deferred_split_shrinker));
unlock:
spin_unlock(&parent_ds_queue->split_queue_lock);
diff --git a/mm/shrinker.c b/mm/shrinker.c
index 7b61fc0ee78f..61dbb6afae52 100644
--- a/mm/shrinker.c
+++ b/mm/shrinker.c
@@ -255,11 +255,13 @@ static long xchg_nr_deferred_memcg(int nid, struct shrinker *shrinker,
struct shrinker_info *info;
struct shrinker_info_unit *unit;
long nr_deferred;
+ int id;
rcu_read_lock();
+ id = shrinker_id(memcg, shrinker);
info = rcu_dereference(memcg->nodeinfo[nid]->shrinker_info);
- unit = info->unit[shrinker_id_to_index(shrinker->id)];
- nr_deferred = atomic_long_xchg(&unit->nr_deferred[shrinker_id_to_offset(shrinker->id)], 0);
+ unit = info->unit[shrinker_id_to_index(id)];
+ nr_deferred = atomic_long_xchg(&unit->nr_deferred[shrinker_id_to_offset(id)], 0);
rcu_read_unlock();
return nr_deferred;
@@ -271,12 +273,14 @@ static long add_nr_deferred_memcg(long nr, int nid, struct shrinker *shrinker,
struct shrinker_info *info;
struct shrinker_info_unit *unit;
long nr_deferred;
+ int id;
rcu_read_lock();
+ id = shrinker_id(memcg, shrinker);
info = rcu_dereference(memcg->nodeinfo[nid]->shrinker_info);
- unit = info->unit[shrinker_id_to_index(shrinker->id)];
+ unit = info->unit[shrinker_id_to_index(id)];
nr_deferred =
- atomic_long_add_return(nr, &unit->nr_deferred[shrinker_id_to_offset(shrinker->id)]);
+ atomic_long_add_return(nr, &unit->nr_deferred[shrinker_id_to_offset(id)]);
rcu_read_unlock();
return nr_deferred;
--
2.43.0
next prev parent reply other threads:[~2026-03-10 3:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-10 3:12 [PATCH V2 0/4] record non-slab shrinkers for non-root memcgs when kmem is disabled Haifeng Xu
2026-03-10 3:12 ` Haifeng Xu [this message]
2026-03-10 3:12 ` [PATCH V2 2/4] mm: shrinker: move shrinker_id() code block below memcg_kmem_online() Haifeng Xu
2026-03-10 3:12 ` [PATCH V2 3/4] mm: shrinker: optimize the allocation of shrinker_info when setting cgroup_memory_nokmem Haifeng Xu
2026-03-10 11:05 ` Usama Arif
2026-03-11 2:21 ` Haifeng Xu
2026-03-11 22:14 ` Dave Chinner
[not found] ` <bc08d009-fa43-44d0-880f-a37cc200a3b9@shopee.com>
2026-03-12 5:52 ` Dave Chinner
2026-03-13 3:04 ` Haifeng Xu
2026-03-10 3:12 ` [PATCH V2 4/4] mm: shrinker: remove unnecessary check in shrink_slab_memcg() Haifeng Xu
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=20260310031250.289851-2-haifeng.xu@shopee.com \
--to=haifeng.xu@shopee.com \
--cc=akpm@linux-foundation.org \
--cc=david@fromorbit.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=zhengqi.arch@bytedance.com \
/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