From: Yosry Ahmed yosryahmed@google.com
mainline inclusion from mainline-v6.8-rc1 commit 508bed884767a8eb394640bae9edcdf082816c43 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I9RPY4 CVE: NA
--------------------------------
Patch series "mm: memcg: subtree stats flushing and thresholds", v4.
This series attempts to address shortages in today's approach for memcg stats flushing, namely occasionally stale or expensive stat reads. The series does so by changing the threshold that we use to decide whether to trigger a flush to be per memcg instead of global (patch 3), and then changing flushing to be per memcg (i.e. subtree flushes) instead of global (patch 5).
This patch (of 5):
flush_next_time is an inaccurate name. It's not the next time that periodic flushing will happen, it's rather the next time that ratelimited flushing can happen if the periodic flusher is late.
Simplify its semantics by just storing the timestamp of the last flush instead, flush_last_time. Move the 2*FLUSH_TIME addition to mem_cgroup_flush_stats_ratelimited(), and add a comment explaining it. This way, all the ratelimiting semantics live in one place.
No functional change intended.
Link: https://lkml.kernel.org/r/20231129032154.3710765-1-yosryahmed@google.com Link: https://lkml.kernel.org/r/20231129032154.3710765-2-yosryahmed@google.com Signed-off-by: Yosry Ahmed yosryahmed@google.com Tested-by: Domenico Cerasuolo cerasuolodomenico@gmail.com Acked-by: Shakeel Butt shakeelb@google.com Acked-by: Chris Li chrisl@kernel.org (Google) Tested-by: Bagas Sanjaya bagasdotme@gmail.com Cc: Greg Thelen gthelen@google.com Cc: Ivan Babrou ivan@cloudflare.com Cc: Johannes Weiner hannes@cmpxchg.org Cc: Michal Hocko mhocko@kernel.org Cc: Michal Koutny mkoutny@suse.com Cc: Muchun Song muchun.song@linux.dev Cc: Roman Gushchin roman.gushchin@linux.dev Cc: Tejun Heo tj@kernel.org Cc: Waiman Long longman@redhat.com Cc: Wei Xu weixugc@google.com Signed-off-by: Andrew Morton akpm@linux-foundation.org Signed-off-by: Lu Jialin lujialin4@huawei.com --- mm/memcontrol.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index f903714eacb1..06cf3ff59540 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -621,7 +621,7 @@ static DECLARE_DEFERRABLE_WORK(stats_flush_dwork, flush_memcg_stats_dwork); static DEFINE_PER_CPU(unsigned int, stats_updates); static atomic_t stats_flush_ongoing = ATOMIC_INIT(0); static atomic_t stats_flush_threshold = ATOMIC_INIT(0); -static u64 flush_next_time; +static u64 flush_last_time;
#define FLUSH_TIME (2UL*HZ)
@@ -681,7 +681,7 @@ static void do_flush_stats(void) atomic_xchg(&stats_flush_ongoing, 1)) return;
- WRITE_ONCE(flush_next_time, jiffies_64 + 2*FLUSH_TIME); + WRITE_ONCE(flush_last_time, jiffies_64);
cgroup_rstat_flush(root_mem_cgroup->css.cgroup);
@@ -697,7 +697,8 @@ void mem_cgroup_flush_stats(void)
void mem_cgroup_flush_stats_ratelimited(void) { - if (time_after64(jiffies_64, READ_ONCE(flush_next_time))) + /* Only flush if the periodic flusher is one full cycle late */ + if (time_after64(jiffies_64, READ_ONCE(flush_last_time) + 2*FLUSH_TIME)) mem_cgroup_flush_stats(); }