[Devel] [PATCH rh7 1/8] mm/mem_cgroup_iter: Make 'iter->last_visited' a bit more stable

Konstantin Khorenko khorenko at virtuozzo.com
Sat Feb 20 12:24:07 MSK 2021


In fact this patch does not change the logic, but after it
we can state that iter->last_visited _always_ contains valid
pointer until the iter is "break-ed".

Why? Because 'last_visited' is always assigned in _update()
to the memcg which has passed css_tryget(), so css won't be
ever offlined (and moreover - destroyed) until we css_put() it.

And if now we call css_put() after iter->last_visited is
assigned a new cgroup, the only case when 'last_visited' may
contain invalid entry is "break-ed" mem_cgroup_iter().

https://jira.sw.ru/browse/PSBM-123655

Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
 mm/memcontrol.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index e0a430908138..5be8fbfe0308 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1622,9 +1622,6 @@ static void mem_cgroup_iter_update(struct mem_cgroup_reclaim_iter *iter,
 				   struct mem_cgroup *root,
 				   int sequence)
 {
-	/* root reference counting symmetric to mem_cgroup_iter_load */
-	if (last_visited && last_visited != root)
-		css_put(&last_visited->css);
 	/*
 	 * We store the sequence count from the time @last_visited was
 	 * loaded successfully instead of rereading it here so that we
@@ -1635,6 +1632,10 @@ static void mem_cgroup_iter_update(struct mem_cgroup_reclaim_iter *iter,
 	iter->last_visited = new_position;
 	iter->last_dead_count = sequence;
 	write_sequnlock(&iter->last_visited_lock);
+
+	/* root reference counting symmetric to mem_cgroup_iter_load */
+	if (last_visited && last_visited != root)
+		css_put(&last_visited->css);
 }
 
 /**
-- 
2.24.3



More information about the Devel mailing list