diff mbox series

[v5,01/11] mm: memcontrol: remove dead code and comments

Message ID 20220530074919.46352-2-songmuchun@bytedance.com (mailing list archive)
State New
Headers show
Series Use obj_cgroup APIs to charge the LRU pages | expand

Commit Message

Muchun Song May 30, 2022, 7:49 a.m. UTC
Since no-hierarchy mode is deprecated after

  commit bef8620cd8e0 ("mm: memcg: deprecate the non-hierarchical mode")

so parent_mem_cgroup() cannot return a NULL except root memcg, however, root
memcg cannot be offline, so it is safe to drop the check of returned value
of parent_mem_cgroup().  Remove those dead code.

The comments in memcg_offline_kmem() above memcg_reparent_list_lrus() are
out of date since

  commit 5abc1e37afa0 ("mm: list_lru: allocate list_lru_one only when needed")

There is no ordering requirement between memcg_reparent_list_lrus() and
memcg_reparent_objcgs(), so remove those outdated comments.

Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
 include/linux/memcontrol.h |  3 +--
 mm/memcontrol.c            | 16 ----------------
 mm/vmscan.c                |  6 +-----
 3 files changed, 2 insertions(+), 23 deletions(-)

Comments

Roman Gushchin June 10, 2022, 11:01 p.m. UTC | #1
On Mon, May 30, 2022 at 03:49:09PM +0800, Muchun Song wrote:
> Since no-hierarchy mode is deprecated after
> 
>   commit bef8620cd8e0 ("mm: memcg: deprecate the non-hierarchical mode")
> 
> so parent_mem_cgroup() cannot return a NULL except root memcg, however, root
> memcg cannot be offline, so it is safe to drop the check of returned value
> of parent_mem_cgroup().  Remove those dead code.
> 
> The comments in memcg_offline_kmem() above memcg_reparent_list_lrus() are
> out of date since
> 
>   commit 5abc1e37afa0 ("mm: list_lru: allocate list_lru_one only when needed")
> 
> There is no ordering requirement between memcg_reparent_list_lrus() and
> memcg_reparent_objcgs(), so remove those outdated comments.
> 
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>

Acked-by: Roman Gushchin <roman.gushchin@linux.dev>

Nice cleanup!
diff mbox series

Patch

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 89b14729d59f..0833be256134 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -851,8 +851,7 @@  static inline struct mem_cgroup *lruvec_memcg(struct lruvec *lruvec)
  * parent_mem_cgroup - find the accounting parent of a memcg
  * @memcg: memcg whose parent to find
  *
- * Returns the parent memcg, or NULL if this is the root or the memory
- * controller is in legacy no-hierarchy mode.
+ * Returns the parent memcg, or NULL if this is the root.
  */
 static inline struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg)
 {
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 598fece89e2b..13da256ff2e4 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3622,17 +3622,7 @@  static void memcg_offline_kmem(struct mem_cgroup *memcg)
 		return;
 
 	parent = parent_mem_cgroup(memcg);
-	if (!parent)
-		parent = root_mem_cgroup;
-
 	memcg_reparent_objcgs(memcg, parent);
-
-	/*
-	 * After we have finished memcg_reparent_objcgs(), all list_lrus
-	 * corresponding to this cgroup are guaranteed to remain empty.
-	 * The ordering is imposed by list_lru_node->lock taken by
-	 * memcg_reparent_list_lrus().
-	 */
 	memcg_reparent_list_lrus(memcg, parent);
 }
 #else
@@ -6593,10 +6583,6 @@  void mem_cgroup_calculate_protection(struct mem_cgroup *root,
 		return;
 
 	parent = parent_mem_cgroup(memcg);
-	/* No parent means a non-hierarchical mode on v1 memcg */
-	if (!parent)
-		return;
-
 	if (parent == root) {
 		memcg->memory.emin = READ_ONCE(memcg->memory.min);
 		memcg->memory.elow = READ_ONCE(memcg->memory.low);
@@ -7050,8 +7036,6 @@  static 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/vmscan.c b/mm/vmscan.c
index 1678802e03e7..8c6054e06087 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -409,13 +409,9 @@  void reparent_shrinker_deferred(struct mem_cgroup *memcg)
 {
 	int i, nid;
 	long nr;
-	struct mem_cgroup *parent;
+	struct mem_cgroup *parent = parent_mem_cgroup(memcg);
 	struct shrinker_info *child_info, *parent_info;
 
-	parent = parent_mem_cgroup(memcg);
-	if (!parent)
-		parent = root_mem_cgroup;
-
 	/* Prevent from concurrent shrinker_info expand */
 	down_read(&shrinker_rwsem);
 	for_each_node(nid) {