* [PATCH V1] mm/list_lru: make the case where mlru is NULL as unlikely
@ 2025-02-27 8:22 Jingxiang Zeng
2025-02-27 12:19 ` Muchun Song
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jingxiang Zeng @ 2025-02-27 8:22 UTC (permalink / raw)
To: linux-mm
Cc: akpm, hannes, mhocko, roman.gushchin, shakeel.butt, muchun.song,
chengming.zhou, kasong, lkp, Zeng Jingxiang
From: Zeng Jingxiang <linuszeng@tencent.com>
In the following memcg_list_lru_alloc() function, mlru here is almost
always NULL, so in most cases this should save a function call, mark
mlru as unlikely to optimize the code, and reusing the mlru for the
next attempt when the tree insertion fails.
do {
xas_lock_irqsave(&xas, flags);
if (!xas_load(&xas) && !css_is_dying(&pos->css)) {
xas_store(&xas, mlru);
if (!xas_error(&xas))
mlru = NULL;
}
xas_unlock_irqrestore(&xas, flags);
} while (xas_nomem(&xas, GFP_KERNEL));
> if (mlru)
kfree(mlru);
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202412290924.UTP7GH2Z-lkp@intel.com/
Signed-off-by: Zeng Jingxiang <linuszeng@tencent.com>
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
---
mm/list_lru.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/mm/list_lru.c b/mm/list_lru.c
index 7d69434c70e0..490473af3122 100644
--- a/mm/list_lru.c
+++ b/mm/list_lru.c
@@ -510,7 +510,7 @@ int memcg_list_lru_alloc(struct mem_cgroup *memcg, struct list_lru *lru,
gfp_t gfp)
{
unsigned long flags;
- struct list_lru_memcg *mlru;
+ struct list_lru_memcg *mlru = NULL;
struct mem_cgroup *pos, *parent;
XA_STATE(xas, &lru->xa, 0);
@@ -535,9 +535,11 @@ int memcg_list_lru_alloc(struct mem_cgroup *memcg, struct list_lru *lru,
parent = parent_mem_cgroup(pos);
}
- mlru = memcg_init_list_lru_one(lru, gfp);
- if (!mlru)
- return -ENOMEM;
+ if (!mlru) {
+ mlru = memcg_init_list_lru_one(lru, gfp);
+ if (!mlru)
+ return -ENOMEM;
+ }
xas_set(&xas, pos->kmemcg_id);
do {
xas_lock_irqsave(&xas, flags);
@@ -548,10 +550,11 @@ int memcg_list_lru_alloc(struct mem_cgroup *memcg, struct list_lru *lru,
}
xas_unlock_irqrestore(&xas, flags);
} while (xas_nomem(&xas, gfp));
- if (mlru)
- kfree(mlru);
} while (pos != memcg && !css_is_dying(&pos->css));
+ if (unlikely(mlru))
+ kfree(mlru);
+
return xas_error(&xas);
}
#else
--
2.43.5
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH V1] mm/list_lru: make the case where mlru is NULL as unlikely
2025-02-27 8:22 [PATCH V1] mm/list_lru: make the case where mlru is NULL as unlikely Jingxiang Zeng
@ 2025-02-27 12:19 ` Muchun Song
2025-02-27 14:42 ` Johannes Weiner
2025-02-27 18:54 ` Shakeel Butt
2 siblings, 0 replies; 4+ messages in thread
From: Muchun Song @ 2025-02-27 12:19 UTC (permalink / raw)
To: Jingxiang Zeng
Cc: linux-mm, akpm, hannes, mhocko, roman.gushchin, shakeel.butt,
chengming.zhou, kasong, lkp
> On Feb 27, 2025, at 16:22, Jingxiang Zeng <jingxiangzeng.cas@gmail.com> wrote:
>
> From: Zeng Jingxiang <linuszeng@tencent.com>
>
> In the following memcg_list_lru_alloc() function, mlru here is almost
> always NULL, so in most cases this should save a function call, mark
> mlru as unlikely to optimize the code, and reusing the mlru for the
> next attempt when the tree insertion fails.
> do {
> xas_lock_irqsave(&xas, flags);
> if (!xas_load(&xas) && !css_is_dying(&pos->css)) {
> xas_store(&xas, mlru);
> if (!xas_error(&xas))
> mlru = NULL;
> }
> xas_unlock_irqrestore(&xas, flags);
> } while (xas_nomem(&xas, GFP_KERNEL));
>> if (mlru)
> kfree(mlru);
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202412290924.UTP7GH2Z-lkp@intel.com/
> Signed-off-by: Zeng Jingxiang <linuszeng@tencent.com>
> Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Muchun Song <muchun.song@linux.dev>
Thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH V1] mm/list_lru: make the case where mlru is NULL as unlikely
2025-02-27 8:22 [PATCH V1] mm/list_lru: make the case where mlru is NULL as unlikely Jingxiang Zeng
2025-02-27 12:19 ` Muchun Song
@ 2025-02-27 14:42 ` Johannes Weiner
2025-02-27 18:54 ` Shakeel Butt
2 siblings, 0 replies; 4+ messages in thread
From: Johannes Weiner @ 2025-02-27 14:42 UTC (permalink / raw)
To: Jingxiang Zeng
Cc: linux-mm, akpm, mhocko, roman.gushchin, shakeel.butt,
muchun.song, chengming.zhou, kasong, lkp
On Thu, Feb 27, 2025 at 04:22:23PM +0800, Jingxiang Zeng wrote:
> From: Zeng Jingxiang <linuszeng@tencent.com>
>
> In the following memcg_list_lru_alloc() function, mlru here is almost
> always NULL, so in most cases this should save a function call, mark
> mlru as unlikely to optimize the code, and reusing the mlru for the
> next attempt when the tree insertion fails.
> do {
> xas_lock_irqsave(&xas, flags);
> if (!xas_load(&xas) && !css_is_dying(&pos->css)) {
> xas_store(&xas, mlru);
> if (!xas_error(&xas))
> mlru = NULL;
> }
> xas_unlock_irqrestore(&xas, flags);
> } while (xas_nomem(&xas, GFP_KERNEL));
> > if (mlru)
> kfree(mlru);
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202412290924.UTP7GH2Z-lkp@intel.com/
> Signed-off-by: Zeng Jingxiang <linuszeng@tencent.com>
> Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH V1] mm/list_lru: make the case where mlru is NULL as unlikely
2025-02-27 8:22 [PATCH V1] mm/list_lru: make the case where mlru is NULL as unlikely Jingxiang Zeng
2025-02-27 12:19 ` Muchun Song
2025-02-27 14:42 ` Johannes Weiner
@ 2025-02-27 18:54 ` Shakeel Butt
2 siblings, 0 replies; 4+ messages in thread
From: Shakeel Butt @ 2025-02-27 18:54 UTC (permalink / raw)
To: Jingxiang Zeng
Cc: linux-mm, akpm, hannes, mhocko, roman.gushchin, muchun.song,
chengming.zhou, kasong, lkp
On Thu, Feb 27, 2025 at 04:22:23PM +0800, Jingxiang Zeng wrote:
> From: Zeng Jingxiang <linuszeng@tencent.com>
>
> In the following memcg_list_lru_alloc() function, mlru here is almost
> always NULL, so in most cases this should save a function call, mark
> mlru as unlikely to optimize the code, and reusing the mlru for the
> next attempt when the tree insertion fails.
> do {
> xas_lock_irqsave(&xas, flags);
> if (!xas_load(&xas) && !css_is_dying(&pos->css)) {
> xas_store(&xas, mlru);
> if (!xas_error(&xas))
> mlru = NULL;
> }
> xas_unlock_irqrestore(&xas, flags);
> } while (xas_nomem(&xas, GFP_KERNEL));
> > if (mlru)
> kfree(mlru);
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202412290924.UTP7GH2Z-lkp@intel.com/
> Signed-off-by: Zeng Jingxiang <linuszeng@tencent.com>
> Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-02-27 18:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-27 8:22 [PATCH V1] mm/list_lru: make the case where mlru is NULL as unlikely Jingxiang Zeng
2025-02-27 12:19 ` Muchun Song
2025-02-27 14:42 ` Johannes Weiner
2025-02-27 18:54 ` Shakeel Butt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox