[RFC][PATCH 2/2] memcgl: Remove dead code now that all tasks of an mm share a memcg

From: Eric W. Biederman
Date: Fri Jun 01 2018 - 10:53:56 EST



get_mem_cgroup_from_mm no longer needs to deal with offline memory cgroups.

mem_cgroup_can_attach no longer needs to worry about cgroup leaders
as all tasks of an mm will migrate together.

Signed-off-by: "Eric W. Biederman" <ebiederm@xxxxxxxxxxxx>
---
mm/memcontrol.c | 43 +++++++++----------------------------------
1 file changed, 9 insertions(+), 34 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 078ef562bb90..a05c1253ad87 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -666,7 +666,7 @@ static void memcg_check_events(struct mem_cgroup *memcg, struct page *page)

static struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm)
{
- struct mem_cgroup *memcg, *omemcg;
+ struct mem_cgroup *memcg;

rcu_read_lock();
/*
@@ -677,37 +677,18 @@ static struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm)
if (unlikely(!mm))
goto root_memcg;

- /* Loop trying to get a reference while mm->memcg is changing */
- for (omemcg = NULL;; omemcg = memcg) {
+ do {
memcg = rcu_dereference(mm->memcg);
if (unlikely(!memcg))
goto root_memcg;
- if (likely(css_tryget_online(&memcg->css)))
- goto found;
- if ((memcg == omemcg) && css_tryget(&omemcg->css))
- break;
- }
+ } while (!css_tryget_online(&memcg->css));
+ rcu_read_unlock();
+ return memcg;

- /* Walk up and find a live memory cgroup */
- while (memcg != root_mem_cgroup) {
- memcg = mem_cgroup_from_css(memcg->css.parent);
- if (css_tryget_online(&memcg->css))
- goto found_parent;
- }
- css_put(&omemcg->css);
root_memcg:
css_get(&root_mem_cgroup->css);
rcu_read_unlock();
return root_mem_cgroup;
-
-found_parent:
- css_get(&memcg->css);
- mm_update_memcg(mm, memcg);
- css_put(&omemcg->css);
-found:
- rcu_read_unlock();
- return memcg;
-
}

/**
@@ -4847,7 +4828,7 @@ static int mem_cgroup_can_attach(struct cgroup_taskset *tset)
struct cgroup_subsys_state *css;
struct mem_cgroup *memcg = NULL; /* unneeded init to make gcc happy */
struct mem_cgroup *from;
- struct task_struct *leader, *p;
+ struct task_struct *p;
struct mm_struct *mm;
unsigned long move_flags;
int ret;
@@ -4863,18 +4844,12 @@ static int mem_cgroup_can_attach(struct cgroup_taskset *tset)

/*
* Multi-process migrations only happen on the default hierarchy
- * where charge immigration is not used. Perform charge
- * immigration if @tset contains a leader and whine if there are
- * multiple.
+ * where charge immigration is not used.
*/
- p = NULL;
- cgroup_taskset_for_each_leader(leader, css, tset) {
- WARN_ON_ONCE(p);
- p = leader;
- memcg = mem_cgroup_from_css(css);
- }
+ p = cgroup_taskset_first(tset, &css);
if (!p)
return 0;
+ memcg = mem_cgroup_from_css(css);

/*
* We are now commited to this value whatever it is. Changes in this
--
2.14.1