On 2025/10/28 21:58, Qi Zheng wrote:
> From: Muchun Song <songmuchun@bytedance.com>
>
> Since the no-hierarchy mode has been deprecated after the commit:
>
> commit bef8620cd8e0 ("mm: memcg: deprecate the non-hierarchical mode").
>
> As a result, parent_mem_cgroup() will not return NULL except when passing
> the root memcg, and the root memcg cannot be offline. Hence, it's safe to
> remove the check on the returned value of parent_mem_cgroup(). Remove the
> corresponding dead code.
>
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
> Acked-by: Roman Gushchin <roman.gushchin@linux.dev>
> Acked-by: Johannes Weiner <hannes@cmpxchg.org>
> Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
> ---
> mm/memcontrol.c | 5 -----
> mm/shrinker.c | 6 +-----
> 2 files changed, 1 insertion(+), 10 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 93f7c76f0ce96..d5257465c9d75 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3339,9 +3339,6 @@ static void memcg_offline_kmem(struct mem_cgroup *memcg)
> return;
>
> parent = parent_mem_cgroup(memcg);
> - if (!parent)
> - parent = root_mem_cgroup;
> -
> memcg_reparent_list_lrus(memcg, parent);
>
> /*
> @@ -3632,8 +3629,6 @@ struct mem_cgroup *mem_cgroup_id_get_online(struct mem_cgroup *memcg)
> break;
> }
> memcg = parent_mem_cgroup(memcg);
> - if (!memcg)
> - memcg = root_mem_cgroup;
> }
> return memcg;
> }
> diff --git a/mm/shrinker.c b/mm/shrinker.c
> index 4a93fd433689a..e8e092a2f7f41 100644
> --- a/mm/shrinker.c
> +++ b/mm/shrinker.c
> @@ -286,14 +286,10 @@ void reparent_shrinker_deferred(struct mem_cgroup *memcg)
> {
> int nid, index, offset;
> long nr;
> - struct mem_cgroup *parent;
> + struct mem_cgroup *parent = parent_mem_cgroup(memcg);
> struct shrinker_info *child_info, *parent_info;
> struct shrinker_info_unit *child_unit, *parent_unit;
>
> - parent = parent_mem_cgroup(memcg);
> - if (!parent)
> - parent = root_mem_cgroup;
> -
> /* Prevent from concurrent shrinker_info expand */
> mutex_lock(&shrinker_mutex);
> for_each_node(nid) {
LGTM.
Reviewed-by: Chen Ridong <chenridong@huawei.com>
--
Best regards,
Ridong