linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] memcg: use root_mem_cgroup when css is inherited
@ 2022-08-19 11:29 zhaoyang.huang
  2022-08-19 16:29 ` Tejun Heo
  0 siblings, 1 reply; 22+ messages in thread
From: zhaoyang.huang @ 2022-08-19 11:29 UTC (permalink / raw)
  To: Johannes Weiner, Michal Hocko, Zhaoyang Huang, linux-mm,
	linux-kernel, cgroups, ke.wang, Tejun Heo, Zefan Li,
	Roman Gushchin, Shakeel Butt, Muchun Song

From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>

It is observed in android system where per-app cgroup is demanded by freezer
subsys and part of groups require memory control. The hierarchy could be simplized
as bellowing where memory charged on group B abserved while we only want have
group E's memory be controlled and B's descendants compete freely for memory.
This should be the consequences of unified hierarchy.
Under this scenario, less efficient memory reclaim is observed when comparing
with no memory control. It is believed that multi LRU scanning introduces some
of the overhead. Furthermore, page thrashing is also heavier than global LRU
which could be the consequences of partial failure of WORKINGSET mechanism as
LRU is too short to protect the active pages.

A(subtree_control = memory) - B(subtree_control = NULL) - C()
							\ D()
			    - E(subtree_control = memory) - F()
							  \ G()

Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
---
 include/linux/cgroup.h |  1 +
 kernel/cgroup/cgroup.c | 11 +++++++++++
 mm/memcontrol.c        |  5 ++++-
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 0d1ada8..747f0f4 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -136,6 +136,7 @@ extern void cgroup_post_fork(struct task_struct *p,
 
 int cgroup_parse_float(const char *input, unsigned dec_shift, s64 *v);
 
+struct cgroup *get_task_cgroup(struct task_struct *task);
 /*
  * Iteration helpers and macros.
  */
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 1779ccd..3f34c58 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -1457,6 +1457,17 @@ struct cgroup *task_cgroup_from_root(struct task_struct *task,
 	return cset_cgroup_from_root(task_css_set(task), root);
 }
 
+struct cgroup *get_task_cgroup(struct task_struct *task)
+{
+	struct cgroup *src_cgrp;
+	/* find the source cgroup */
+	spin_lock_irq(&css_set_lock);
+	src_cgrp = task_cgroup_from_root(task, &cgrp_dfl_root);
+	spin_unlock_irq(&css_set_lock);
+
+	return src_cgrp;
+}
+
 /*
  * A task must hold cgroup_mutex to modify cgroups.
  *
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index abec50f..c81012b 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -930,6 +930,7 @@ static __always_inline struct mem_cgroup *active_memcg(void)
 struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm)
 {
 	struct mem_cgroup *memcg;
+	struct cgroup *cgrp;
 
 	if (mem_cgroup_disabled())
 		return NULL;
@@ -956,9 +957,11 @@ struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm)
 	}
 
 	rcu_read_lock();
+	cgrp = get_task_cgroup(rcu_dereference(mm->owner));
 	do {
 		memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
-		if (unlikely(!memcg))
+		if (unlikely(!memcg)
+			|| !(cgroup_ss_mask(cgrp) & (1 << memory_cgrp_id)))
 			memcg = root_mem_cgroup;
 	} while (!css_tryget(&memcg->css));
 	rcu_read_unlock();
-- 
1.9.1



^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2022-08-25 13:35 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-19 11:29 [RFC PATCH] memcg: use root_mem_cgroup when css is inherited zhaoyang.huang
2022-08-19 16:29 ` Tejun Heo
2022-08-19 17:08   ` Shakeel Butt
2022-08-19 17:10     ` Tejun Heo
     [not found]       ` <YwNpI1ydy0yDnBH0@dhcp22.suse.cz>
2022-08-23  2:31         ` Zhaoyang Huang
     [not found]           ` <YwRjyx6wFLk8WTDe@dhcp22.suse.cz>
2022-08-23  6:03             ` Zhaoyang Huang
2022-08-23  8:33               ` Michal Hocko
2022-08-23  9:20                 ` Zhaoyang Huang
2022-08-23 11:51                   ` Michal Hocko
2022-08-23 16:21                     ` Suren Baghdasaryan
2022-08-24  7:59                       ` Michal Hocko
2022-08-24 17:13                         ` Suren Baghdasaryan
2022-08-24  2:23                     ` Zhaoyang Huang
2022-08-24  7:50                       ` Michal Hocko
2022-08-24  9:34                         ` Zhaoyang Huang
2022-08-24 10:27                           ` Michal Hocko
2022-08-25  0:43                             ` Zhaoyang Huang
2022-08-25  6:40                               ` Michal Hocko
2022-08-25  8:34                                 ` Zhaoyang Huang
2022-08-25  8:50                                   ` Michal Hocko
2022-08-25 10:11                                     ` Zhaoyang Huang
2022-08-25 13:35                                       ` Johannes Weiner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox