From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B831C46CA3 for ; Wed, 29 Nov 2023 03:58:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234638AbjK2D6D (ORCPT ); Tue, 28 Nov 2023 22:58:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229924AbjK2D6C (ORCPT ); Tue, 28 Nov 2023 22:58:02 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A29412C for ; Tue, 28 Nov 2023 19:58:08 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B712C433C7; Wed, 29 Nov 2023 03:58:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1701230287; bh=rb8Edea6jz8sUnlU4nIjvJz6uqGA08lcnA7xA10c5NA=; h=Date:To:From:Subject:From; b=O4P/hGsyaXbbGMC6q0qoY1T5v5+Jtj9M6DOz3UDU7pAG6BKfKNPgrP3QEDpUcbsgu TjJu2pwwenTFoa7OpQFwpIGRwc95R0BYt7LoKrgGxi3FVfdLJ62XlFB03BWDpOdEpb VPCawuzkO49H7X1eFCNDq0OI4JOHxFoG4LYJxR8w= Date: Tue, 28 Nov 2023 19:58:06 -0800 To: mm-commits@vger.kernel.org, weixugc@google.com, tj@kernel.org, shakeelb@google.com, roman.gushchin@linux.dev, muchun.song@linux.dev, mkoutny@suse.com, mhocko@kernel.org, longman@redhat.com, ivan@cloudflare.com, hannes@cmpxchg.org, gthelen@google.com, chrisl@kernel.org, cerasuolodomenico@gmail.com, yosryahmed@google.com, akpm@linux-foundation.org From: Andrew Morton Subject: + mm-memcg-change-flush_next_time-to-flush_last_time.patch added to mm-unstable branch Message-Id: <20231129035807.1B712C433C7@smtp.kernel.org> Precedence: bulk Reply-To: linux-kernel@vger.kernel.org List-ID: X-Mailing-List: mm-commits@vger.kernel.org The patch titled Subject: mm: memcg: change flush_next_time to flush_last_time has been added to the -mm mm-unstable branch. Its filename is mm-memcg-change-flush_next_time-to-flush_last_time.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-memcg-change-flush_next_time-to-flush_last_time.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Yosry Ahmed Subject: mm: memcg: change flush_next_time to flush_last_time Date: Wed, 29 Nov 2023 03:21:49 +0000 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 Tested-by: Domenico Cerasuolo Acked-by: Shakeel Butt Acked-by: Chris Li (Google) Cc: Greg Thelen Cc: Ivan Babrou Cc: Johannes Weiner Cc: Michal Hocko Cc: Michal Koutny Cc: Muchun Song Cc: Roman Gushchin Cc: Tejun Heo Cc: Waiman Long Cc: Wei Xu Signed-off-by: Andrew Morton --- mm/memcontrol.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/mm/memcontrol.c~mm-memcg-change-flush_next_time-to-flush_last_time +++ a/mm/memcontrol.c @@ -593,7 +593,7 @@ static DECLARE_DEFERRABLE_WORK(stats_flu 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) @@ -653,7 +653,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); @@ -669,7 +669,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(); } _ Patches currently in -mm which might be from yosryahmed@google.com are mm-memcg-change-flush_next_time-to-flush_last_time.patch mm-memcg-move-vmstats-structs-definition-above-flushing-code.patch mm-memcg-make-stats-flushing-threshold-per-memcg.patch mm-workingset-move-the-stats-flush-into-workingset_test_recent.patch mm-memcg-restore-subtree-stats-flushing.patch