From patchwork Tue Oct 10 03:21:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13414777 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F238CCD68EB for ; Tue, 10 Oct 2023 03:21:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 355396B00BF; Mon, 9 Oct 2023 23:21:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2DA536B00C5; Mon, 9 Oct 2023 23:21:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 17B8D6B00CC; Mon, 9 Oct 2023 23:21:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id EFF906B00BF for ; Mon, 9 Oct 2023 23:21:24 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C2FE280525 for ; Tue, 10 Oct 2023 03:21:24 +0000 (UTC) X-FDA: 81328101288.07.AD2430A Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf22.hostedemail.com (Postfix) with ESMTP id 0C4EAC0022 for ; Tue, 10 Oct 2023 03:21:22 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=l4bpwvQM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of 3MsMkZQoKCHsxnrqxZgldcfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3MsMkZQoKCHsxnrqxZgldcfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696908083; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Txx2Z/24+3F8Cj+NRtOMU7JL27MtRQwWcbI2dA3u7/E=; b=3vlbwFYonAdNu34ei8R6OCMiXGQuiLFDdr8ZpPJ8UHYIkwN/LIsj6S3Mr19OB8US0NvZ4N l1/VUm2fgFbmz8dfNnHqc5y38ezYdmJyoFm2qDceIw7hK0Vt+gP9Q2xypWXAcz7DX3YDqw R9apCYS9Sj+ChsXDDrb1TakMPug/6ZA= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=l4bpwvQM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of 3MsMkZQoKCHsxnrqxZgldcfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3MsMkZQoKCHsxnrqxZgldcfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696908083; a=rsa-sha256; cv=none; b=JdMPZR9PDKNrbYHk3k9kg2fLk81nKUKh7RQOu05osgsh++aqmusK5DspDsT3Oujds8+oN3 0t5FTMb8hoH+ladfgN8+NF5uiO1ekXGFDQUmUCwN1R12BtOtjFTJhf5cw55ZJZSfj1rrJZ s79dnVc70CVFHKybzmK6eZyaG5mYqaM= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-c647150c254so4608765276.1 for ; Mon, 09 Oct 2023 20:21:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696908082; x=1697512882; darn=kvack.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=Txx2Z/24+3F8Cj+NRtOMU7JL27MtRQwWcbI2dA3u7/E=; b=l4bpwvQM7b0PWBjCQ+KrqegPePcY2JHTL66TNjGJDpXbQF25Q6kxVxQFuyJBXQNn5R xKNdIeb6O2ijJGO54NSkdqwNGFm5bC0NEY9Lghi85KzssKLi/My2mukPiFYPLFKBt12J 21rfzLNkibFGqPopX0cMyw0cX/vAX7i+FR8e0DVeQ/lQMZ18kSm6i9k/bCNS9m3On4GO je0/hkjtYXpoF6tRoT32UIIVG34XWpdyVKKkjYJ0lEBCXU5KctzhJ5fLPUwKCbjrlvmy jWYhvJphw7yMLyIpyCCVXq3cwZpQ55Pg4j1AF22jqjyRkCuk69NDAofq6k3zAmy5iXAm cL4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696908082; x=1697512882; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Txx2Z/24+3F8Cj+NRtOMU7JL27MtRQwWcbI2dA3u7/E=; b=qm1N7KUggLHf6weFjgOn0Pc59qXTYKD5ubgGHntJWQZv4Iyn7aifS7vEm8OYwuiG0/ NgQjqhNZvRAbHZTGpv2h7xx4xhfvutgYR0ZgXEWPp8T4ccIP9wGUAw9TC4FhuBTK8bQY 6cNDpf/qYs5p4xkOvYnuEyR8+Slzey+fTz35PVDCVgg/4JtV7TkO4CmsCJm3ofWAd9Il m7iswxhyUtrsmW589eyyvM/Jyme+Zxzk4JZHaQuPV0Rv/vRWfRERg3xK1TcLuq4ZOCWm Xwpzy2QE7g3RRYDHatOwR4YmM7n7vUKrdruZFqKN63Pz1fyl99nOsE7ITMR0e8/lZz9U fwxw== X-Gm-Message-State: AOJu0Yw6+ydo+e6ks81dMpK+B7G6/+v+K7K+99Ta/oFCB+H4HMiui8iL aOAL0AyPmjkfLZA/gUy7FLi7+s4nMAMr2ErM X-Google-Smtp-Source: AGHT+IHSbb76MuDQgDE4hYiCssfBhZ3erWto8iacOIEWAeUiJ3Vxcha6qRANQmltbAbW17YqbUuNXt2O9PobRH8R X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a25:824f:0:b0:d9a:66eb:b516 with SMTP id d15-20020a25824f000000b00d9a66ebb516mr1411ybn.6.1696908082104; Mon, 09 Oct 2023 20:21:22 -0700 (PDT) Date: Tue, 10 Oct 2023 03:21:12 +0000 In-Reply-To: <20231010032117.1577496-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20231010032117.1577496-1-yosryahmed@google.com> X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog Message-ID: <20231010032117.1577496-2-yosryahmed@google.com> Subject: [PATCH v2 1/5] mm: memcg: change flush_next_time to flush_last_time From: Yosry Ahmed To: Andrew Morton Cc: Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Ivan Babrou , Tejun Heo , " =?utf-8?q?Michal_Koutn=C3=BD?= " , Waiman Long , kernel-team@cloudflare.com, Wei Xu , Greg Thelen , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspamd-Queue-Id: 0C4EAC0022 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: u36g4cprcatirxc31oyf5tjoh64paecj X-HE-Tag: 1696908082-924051 X-HE-Meta: U2FsdGVkX19RuhDSU9HtXzSSuxmWg/ZDTOFQK5LRx+vg+9lPxe8CH7g2wj2wTIc5JCV0UIPGL1N06NqjBYLm9Jsje6JPth8beVMYpCCJXwCzXlWNzXYnjMge7um70YW2u7eO+PYNkruijDfdL5tyUz9Rzu4Tc545OAdaoD1SopFXBLcHP9E6q6Ok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BylGXNfe7SfxE70nJ+fG3PcPvJ6kQwbBrxz8Krh6wk2XpMhNQYyM96io+2eMTzEIO1LaWBWeAEfRNWW7Mu8o7NBsOVsI0JWCNM9mbelKl/Lz+PCgMV5DfKlUExZ4wIRa+wbVPcS0CQPDx/HwV+/uITLn0/ms7L0tBGRn0YPLyV0Hczz8QuvxMjw4+MsLOOv9QBLxMYTYQJ3BcERabk9ExjRmUbrY8C16mOOHeq+UJTVdOqbhK3IKy3vZaxO0yykFwW0UXpOPWQ0UjJ0V6GItcbZiwMLd0n7YtrP/Hr10KwqRHCXJezmLn9Ec3ds/mmV1te1cGaPrTHWjqMrsM+EN8COCy6fnANDeGEtmvd61ReLMDUatbV0koWQvrBdINUe6j116uzbwbMckp39E2QW4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 2fb30abaf267..4a194fcc9533 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(); }