[Devel] [PATCH rh7 0/8] mm/mem_cgroup_iter: Reduce the number of iterator restarts upon cgroup removals

Konstantin Khorenko khorenko at virtuozzo.com
Sat Feb 20 12:23:28 MSK 2021


May thanks to Kirill Tkhai for his bright ideas and review!

Problem description from the user point of view:
  * the Node is slow
  * the Node has a lot of free RAM
  * the Node has a lot of swapin/swapout
  * kswapd is always running

Problem in a nutshell from technical point of view:
  * kswapd is looping in shrink_zone() inside the loop
      do {} while ((memcg = mem_cgroup_iter(root, memcg, &reclaim)));
    (and never goes trough the outer loop)
  * there are a quite a number of memory cgroups of the Node (~1000)
  * some cgroups are hard to reclaim (reclaim may take ~3 seconds),
    this is because of very busy disk due to permanent swapin/swapout
  * mem_cgroup_iter() does not have success scanning all cgroups
    in a row, it restarts from the root cgroup one time after
    another (after different number of cgroups scanned)

Q: Why does mem_cgroup_iter() restart from the root memcg?
A: Because it is invalidated once some memory cgroup is
   destroyed on the Node.
   Note: ANY memory cgroup destroy on the Node leads to iter
   restart.

The following patchset solves this problem in the following way:
there is no need to restart the iter until we see the iter has
the position which is exactly the memory cgroup being destroyed.

The patchset ensures the iter->last_visited is NULL-ified on
invalidation and thus restarts only in the unlikely case when
the iter points to the memcg being destroyed.

Konstantin Khorenko (8):
  mm/mem_cgroup_iter: Make 'iter->last_visited' a bit more stable
  mm/mem_cgroup_iter: Always assign iter->last_visited under seqlock
  mm/mem_cgroup_iter: NULL-ify 'last_visited' for invalidated iterators
  mm/mem_cgroup_iter: Provide _iter_invalidate() the dying memcg as an
    argument
  mm/mem_cgroup_iter: Invalidate iterators only if needed
  mm/mem_cgroup_iter: Don't bother checking 'dead_count' anymore
  mm/mem_cgroup_iter: Cleanup mem_cgroup_iter_load()
  mm/mem_cgroup_iter: Drop dead_count related infrastructure

 mm/memcontrol.c | 125 +++++++++++++++++++++++++++++++-----------------
 1 file changed, 80 insertions(+), 45 deletions(-)

-- 
2.24.3



More information about the Devel mailing list