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 1/3] mm: shrinker: introduce new function get_shrinker_id()
Date: Fri, 6 Mar 2026 15:57:54 +0800 [thread overview]
Message-ID: <20260306075757.198887-2-haifeng.xu@shopee.com> (raw)
In-Reply-To: <20260306075757.198887-1-haifeng.xu@shopee.com>
Use get_shrinker_id() to retrieve the id of shrinker. No functional change.
Signed-off-by: Haifeng Xu <haifeng.xu@shopee.com>
---
mm/shrinker.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/mm/shrinker.c b/mm/shrinker.c
index 7b61fc0ee78f..f0c6dfa026b0 100644
--- a/mm/shrinker.c
+++ b/mm/shrinker.c
@@ -193,6 +193,11 @@ static inline int calc_shrinker_id(int index, int offset)
return index * SHRINKER_UNIT_BITS + offset;
}
+static inline int get_shrinker_id(struct mem_cgroup *memcg, struct shrinker *shrinker)
+{
+ return shrinker->id;
+}
+
void set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id)
{
if (shrinker_id >= 0 && memcg && !mem_cgroup_is_root(memcg)) {
@@ -255,11 +260,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 = get_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 +278,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 = get_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-06 7:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-06 7:57 [PATCH 0/3] record non-slab shrinkers for non-root memcgs when kmem is disabled Haifeng Xu
2026-03-06 7:57 ` Haifeng Xu [this message]
2026-03-06 8:24 ` [PATCH 1/3] mm: shrinker: introduce new function get_shrinker_id() Qi Zheng
2026-03-06 11:21 ` Haifeng Xu
2026-03-06 7:57 ` [PATCH 2/3] mm: shrinker: optimize the allocation of shrinker_info when setting cgroup_memory_nokmem Haifeng Xu
2026-03-06 7:57 ` [PATCH 3/3] 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=20260306075757.198887-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