From: Yosry Ahmed <yosryahmed@google.com> To: Andrew Morton <akpm@linux-foundation.org> Cc: "Johannes Weiner" <hannes@cmpxchg.org>, "Michal Hocko" <mhocko@kernel.org>, "Roman Gushchin" <roman.gushchin@linux.dev>, "Shakeel Butt" <shakeelb@google.com>, "Muchun Song" <muchun.song@linux.dev>, "Ivan Babrou" <ivan@cloudflare.com>, "Tejun Heo" <tj@kernel.org>, "Michal Koutný" <mkoutny@suse.com>, "Waiman Long" <longman@redhat.com>, kernel-team@cloudflare.com, "Wei Xu" <weixugc@google.com>, "Greg Thelen" <gthelen@google.com>, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, "Yosry Ahmed" <yosryahmed@google.com> Subject: [PATCH 1/3] mm: memcg: change flush_next_time to flush_last_time Date: Wed, 13 Sep 2023 07:38:44 +0000 [thread overview] Message-ID: <20230913073846.1528938-2-yosryahmed@google.com> (raw) In-Reply-To: <20230913073846.1528938-1-yosryahmed@google.com> 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 <yosryahmed@google.com> --- 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
WARNING: multiple messages have this Message-ID (diff)
From: Yosry Ahmed <yosryahmed-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org> To: Andrew Morton <akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org> Cc: "Johannes Weiner" <hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org>, "Michal Hocko" <mhocko-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>, "Roman Gushchin" <roman.gushchin-fxUVXftIFDnyG1zEObXtfA@public.gmane.org>, "Shakeel Butt" <shakeelb-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>, "Muchun Song" <muchun.song-fxUVXftIFDnyG1zEObXtfA@public.gmane.org>, "Ivan Babrou" <ivan-lDpJ742SOEtZroRs9YW3xA@public.gmane.org>, "Tejun Heo" <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>, "Michal Koutný" <mkoutny-IBi9RG/b67k@public.gmane.org>, "Waiman Long" <longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>, kernel-team-lDpJ742SOEtZroRs9YW3xA@public.gmane.org, "Wei Xu" <weixugc-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>, "Greg Thelen" <gthelen-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, "Yosry Ahmed" <yosryahmed-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org> Subject: [PATCH 1/3] mm: memcg: change flush_next_time to flush_last_time Date: Wed, 13 Sep 2023 07:38:44 +0000 [thread overview] Message-ID: <20230913073846.1528938-2-yosryahmed@google.com> (raw) In-Reply-To: <20230913073846.1528938-1-yosryahmed-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org> 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 <yosryahmed-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org> --- 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
next prev parent reply other threads:[~2023-09-13 7:46 UTC|newest] Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-09-13 7:38 [PATCH 0/3] memcg: more sophisticated stats flushing Yosry Ahmed 2023-09-13 7:38 ` Yosry Ahmed [this message] 2023-09-13 7:38 ` [PATCH 1/3] mm: memcg: change flush_next_time to flush_last_time Yosry Ahmed 2023-09-13 7:38 ` [PATCH 2/3] mm: memcg: rename stats_flush_threshold to stats_updates_order Yosry Ahmed 2023-09-13 7:38 ` Yosry Ahmed 2023-09-13 7:38 ` [PATCH 3/3] mm: memcg: optimize stats flushing for latency and accuracy Yosry Ahmed 2023-09-13 15:37 ` Johannes Weiner 2023-09-13 15:37 ` Johannes Weiner 2023-09-13 16:26 ` Yosry Ahmed 2023-09-13 16:26 ` Yosry Ahmed 2023-09-14 16:06 ` Johannes Weiner 2023-09-14 16:06 ` Johannes Weiner 2023-09-14 17:22 ` Yosry Ahmed 2023-09-14 17:22 ` Yosry Ahmed 2023-09-14 17:26 ` Yosry Ahmed 2023-09-19 5:46 ` Yosry Ahmed 2023-09-19 5:46 ` Yosry Ahmed 2023-09-14 17:19 ` Waiman Long 2023-09-14 17:23 ` Yosry Ahmed 2023-09-14 17:23 ` Yosry Ahmed 2023-09-14 17:36 ` Waiman Long 2023-09-14 17:36 ` Waiman Long 2023-09-14 17:36 ` Shakeel Butt 2023-09-14 17:36 ` Shakeel Butt 2023-09-14 17:56 ` Yosry Ahmed 2023-09-14 17:56 ` Yosry Ahmed 2023-09-14 22:58 ` Shakeel Butt 2023-09-14 22:58 ` Shakeel Butt 2023-09-14 23:30 ` Yosry Ahmed 2023-09-14 23:30 ` Yosry Ahmed 2023-09-15 1:01 ` Shakeel Butt 2023-09-15 1:01 ` Shakeel Butt 2023-09-19 5:29 ` Yosry Ahmed 2023-09-19 5:29 ` Yosry Ahmed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230913073846.1528938-2-yosryahmed@google.com \ --to=yosryahmed@google.com \ --cc=akpm@linux-foundation.org \ --cc=cgroups@vger.kernel.org \ --cc=gthelen@google.com \ --cc=hannes@cmpxchg.org \ --cc=ivan@cloudflare.com \ --cc=kernel-team@cloudflare.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=longman@redhat.com \ --cc=mhocko@kernel.org \ --cc=mkoutny@suse.com \ --cc=muchun.song@linux.dev \ --cc=roman.gushchin@linux.dev \ --cc=shakeelb@google.com \ --cc=tj@kernel.org \ --cc=weixugc@google.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.