Skip to content

cgroup: eliminate atomic rstat flushing

Yosry Ahmed cgroups linux-fsdevel linux-mm lkml 2 versions – Applied

Status from this message: [merged mm-stable] cgroup-remove-cgroup_rstat_flush_atomic.patch removed from -mm tree

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest5 patches 6 repliesApplied 5/5
  2. v1 RFC5 patches 19 repliesSuperseded

RFC -> v1 from the cover letter

- Collected R-b's and A-b's (Thanks everyone!).
- Rebased onto mm-stable.
- Cosmetic changes to commit logs.

Patches in v5 All 5 applied

#Subject and filesSizeRepliesApplied
1/5writeback: move wb_over_bg_thresh() call outside lock sectionfs/fs-writeback.c+11 -52 repliesApplied
2/5memcg: flush stats non-atomically in mem_cgroup_wb_stats()mm/memcontrol.c+1 -51 replyApplied
3/5memcg: calculate root usage from global statemm/memcontrol.c+5 -190 repliesApplied
4/5memcg: remove mem_cgroup_flush_stats_atomic()include/linux/memcontrol.h mm/memcontrol.c+5 -240 repliesApplied
5/5cgroup: remove cgroup_rstat_flush_atomic()include/linux/cgroup.h kernel/cgroup/rstat.c+5 -222 repliesApplied

Reviews trailers per patch

All 5 patches have a Reviewed-by or Acked-by.

PatchMichal KoutnýJan KaraShakeel ButtTejun Heo
1/5R-b R-b A-b A-b
2/5R-b A-b A-b
3/5R-b A-b
4/5A-b
5/5A-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v5 thread

Cover letter [PATCH v5 0/5] cgroup: eliminate atomic rstat flushing

A previous patch series ([1] currently in mm-stable) changed most atomic rstat flushing contexts to become non-atomic. This was done to avoid an expensive operation that scales with # cgroups and # cpus to happen with irqs disabled and scheduling not permitted. There were two remaining atomic flushing contexts after that series. This series tries to eliminate them as well, eliminating atomic rstat flushing completely.

The two remaining atomic flushing contexts are:
(a) wb_over_bg_thresh()->mem_cgroup_wb_stats()
(b) mem_cgroup_threshold()->mem_cgroup_usage()

For (a), flushing needs to be atomic as wb_writeback() calls wb_over_bg_thresh() with a spinlock held. However, it seems like the call to wb_over_bg_thresh() doesn't need to be protected by that spinlock, so this series proposes a refactoring that moves the call outside the lock criticial section and makes the stats flushing in mem_cgroup_wb_stats() non-atomic.

For (b), flushing needs to be atomic as mem_cgroup_threshold() is called with irqs disabled. We only flush the stats when calculating the root usage, as it is approximated as the sum of some memcg stats (file, anon, and optionally swap) instead of the conventional page counter. This series proposes changing this calculation to use the global stats instead, eliminating the need for a memcg stat flush.

After these 2 contexts are eliminated, we no longer need mem_cgroup_flush_stats_atomic() or cgroup_rstat_flush_atomic(). We can remove them and simplify the code.

[1] https://lore.kernel.org/linux-mm/20230330191801.1967435-1-yosryahmed-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org/

RFC -> v1:
- Collected R-b's and A-b's (Thanks everyone!).
- Rebased onto mm-stable.
- Cosmetic changes to commit logs.

RFC: https://lore.kernel.org/linux-mm/20230403220337.443510-1-yosryahmed-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org/

Yosry Ahmed (5):
writeback: move wb_over_bg_thresh() call outside lock section
memcg: flush stats non-atomically in mem_cgroup_wb_stats()
memcg: calculate root usage from global state
memcg: remove mem_cgroup_flush_stats_atomic()
cgroup: remove cgroup_rstat_flush_atomic()

 fs/fs-writeback.c          | 16 +++++++----
 include/linux/cgroup.h     |  1 -
 include/linux/memcontrol.h |  5 ----
 kernel/cgroup/rstat.c      | 26 ++++--------------
 mm/memcontrol.c            | 54 ++++++++------------------------------
 5 files changed, 27 insertions(+), 75 deletions(-)
Signature · 1 line
2.40.0.634.g4ca3ef3211-goog