From: Yosry Ahmed Subject: [PATCH 1/3] mm: memcg: change flush_next_time to flush_last_time Date: Wed, 13 Sep 2023 07:38:44 +0000 Message-ID: <20230913073846.1528938-2-yosryahmed@google.com> References: <20230913073846.1528938-1-yosryahmed@google.com> Mime-Version: 1.0 Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694591129; x=1695195929; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=JvedlnHbJ7Xvblewl93Q0+oTKItg5cpjvq/m6HrJuqg=; b=E6YfUakV7w6M2u/r0jr2OyHqrJHxxlNM3xYYDwoQ+8RhkVLMVSdhBOl30Sglf4XZpd dvZxdJdhkNMkt0xIfVjqWYXU81HoZyGSU3oOq/mVp6pVBFIOlqGevcbRPBpNCVJDqn7Q pZpj2MLNHT5vGwL0xuHkGZcW6y+rEOR+hLyF+kcBExgOjpzCtPIQwbFKXsEhzpybHb/h 9r96t+2Yx1TdEG2RaQo66UyRvZI8sHtRkjnFKNy4YwJx5Wh8kUrD+cOJdlQA8q3+qS1t zQw2++vjjxWIXUNhy3O85l/2wBHO5PxLWHUf3k2DHif7hz/WqUwNLzQ9fK8aWAwBTJlc axTg== In-Reply-To: <20230913073846.1528938-1-yosryahmed-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org> List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Andrew Morton Cc: Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Ivan Babrou , Tejun Heo , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Waiman Long , kernel-team-lDpJ742SOEtZroRs9YW3xA@public.gmane.org, Wei Xu , Greg Thelen , linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Yosry Ahmed 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. Signed-off-by: Yosry Ahmed --- mm/memcontrol.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index b29b850cf399..35a9c013d755 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -590,7 +590,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) @@ -650,7 +650,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); @@ -666,7 +666,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(); } -- 2.42.0.283.g2d96d420d3-goog