The current stats flushing approach is very simple. Everyone tries to flush the entire tree, and only a single flusher is allowed. Concurrent flushers just skip the flush completely. This approach has problems that manifest in both flushing latency and stats accuracy (or freshness). This series introduces a more sophisticated approach that aims to find a better trade-off between accuracy and performance. Essentially we try to get the best accuracy with the minimal amount of work done when possible (fast path), and we fallback to more expensive or less accurate flushes only when necessary. Details are in the commit message of patch 3, which is really the core of this series. Patches 1 & 2 are just cleanups with no functional change intended. This series replaces v4 of "memcg: non-unified flushing for userspace stats" series [1]. I did not send this as v5 as it completely deviates from what that patchset is doing (but still trying to solve the same problem). The approach followed in this series attempts to provide a more generic framework for flushing for both userspace readers and in-kernel flushers, to avoid having a lot of different flushing flavors. It also benefits in-kernel flushers as well as userspace readers. This series is a result of the discussions held in [1], and various suggestions by Wei Xu <weixugc@xxxxxxxxxx>. [1] https://lore.kernel.org/lkml/20230831165611.2610118-1-yosryahmed@xxxxxxxxxx/ Yosry Ahmed (3): mm: memcg: change flush_next_time to flush_last_time mm: memcg: rename stats_flush_threshold to stats_updates_order mm: memcg: optimize stats flushing for latency and accuracy include/linux/memcontrol.h | 4 +- mm/memcontrol.c | 125 ++++++++++++++++++++++++++----------- mm/vmscan.c | 2 +- mm/workingset.c | 8 ++- 4 files changed, 98 insertions(+), 41 deletions(-) -- 2.42.0.283.g2d96d420d3-goog