From patchwork Thu Sep 21 08:10:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13393758 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 2AF50E706E3 for ; Thu, 21 Sep 2023 08:11:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7CF6E6B018A; Thu, 21 Sep 2023 04:11:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 780996B0195; Thu, 21 Sep 2023 04:11:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6478F6B0198; Thu, 21 Sep 2023 04:11:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 50B306B018A for ; Thu, 21 Sep 2023 04:11:07 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 268101CADBD for ; Thu, 21 Sep 2023 08:11:07 +0000 (UTC) X-FDA: 81259884174.02.BA2D19F Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf07.hostedemail.com (Postfix) with ESMTP id 4C4B94002A for ; Thu, 21 Sep 2023 08:11:04 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="2SHBAfY/"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 3l_oLZQoKCOokaedkMTYQPSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3l_oLZQoKCOokaedkMTYQPSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695283864; 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=FIm0UyACNB+n/akQREWxQWjORl9GVEfiVT/RezLXAow=; b=eQ+4VbxELzbf9C2Vzf/c+2ZTa2Vl04fOxL+0KF5HQS7e3MBcOkn+pG++hS+i8ymAyH9wS2 eyyXaQjaqGhNXcr/sDOIWc/Uxm6o0F0eMO66fuJAsbrDQY7RigUv2kwyzhmiAaU/3gDjQQ r5t0lCfh+x/xFY68y37z8cphYz3i6aI= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="2SHBAfY/"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 3l_oLZQoKCOokaedkMTYQPSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3l_oLZQoKCOokaedkMTYQPSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695283864; a=rsa-sha256; cv=none; b=E4RM+sdauMCn00Q8HhlAWD4L47wVMr0rEWTsb0t+9pdvyIQzZoxL/6xacT9cCATDIc5ouj jM/oKV/eEAMiJ92W2oxQeftL4Atvyfr9qaagBGEkO5wtzDxWnepK0KawMFFwMSnBvJUtFM PyD0Agwh0/ZmfxHGfJw1LoSyAbTA10c= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-d81841ef79bso1087806276.1 for ; Thu, 21 Sep 2023 01:11:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695283863; x=1695888663; 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=FIm0UyACNB+n/akQREWxQWjORl9GVEfiVT/RezLXAow=; b=2SHBAfY/SuQLH1013sNn1FGjz7pjvWPm6Qitog3c6lZ9GFFnyMJgcnOcPId0BhOCFf 0N6wTE21ztM68MLWIgny84aoEHDKs+Qh4Es4Nn+rPC+qkHc2+0NUHMJDF4JsCOO2hORO 2dfznztSY5WWgvRSm1CJyvK7gSLMwjKeIycnJu2MhaIEYoW/1Uty9eEiE4aRFJTI4bzm HtOSfgFrdjAxr5VQNbbqpSBh1/CthEk6T2vfbiy8iqTZQb1m3f1x6XMHhRbEGja0MauM YTwMIDK7PIdO+++eishUYhEaCq2UQ8+vJfzwNwyiEWmHX9REUqKSTCME/RqSg+/3L/MK ztYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695283863; x=1695888663; 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=FIm0UyACNB+n/akQREWxQWjORl9GVEfiVT/RezLXAow=; b=bM3Wvbm2+lDYjlflT4gQroklMS/DIy+ILk1jo3/kMqmmsmieRDM1XuYE5SQe+UdDBk 5wwxgPGf4d/ZK89n5aPWxF3Ib+xpFaVW26yr1irmNyXrVF5i8PLf/0UxLyAeX2DBCaRG GiX6rcmPFPy6hMWIp02vIZjHo9lsDqBQPbiNhb1Wv+c4E3xcoWe5+H1LT4WZHW1m4H3W dbpj+qn83qA6AZki82sYnMxAycjKOYtBEh6Vv21Xz/AAfhTKXyNSlImqjhxwz79i56gf 6YOSKTUZYWPu4TPE555f5wmDct6DXT+9injqEfNf24moEXhyspaBeQo8xa1xmpv0A/7G CBOQ== X-Gm-Message-State: AOJu0Yw20j5Qp6Aryt+WTDexsXsdfn0+434mr49PebwYXei3zHOhEenk SzIVK383BD/b+KiFHU+D/ecAuQ39HepSnD0J X-Google-Smtp-Source: AGHT+IFPrnsBcOBrlhPC5hJYwVV2PE3AiCfsgKWx3CsvgDAaTduMINork77xXDD5F6NyG97FAk+4bBmhLTyqQlsm X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a25:4c8:0:b0:d0e:d67d:6617 with SMTP id 191-20020a2504c8000000b00d0ed67d6617mr67400ybe.4.1695283863247; Thu, 21 Sep 2023 01:11:03 -0700 (PDT) Date: Thu, 21 Sep 2023 08:10:53 +0000 In-Reply-To: <20230921081057.3440885-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230921081057.3440885-1-yosryahmed@google.com> X-Mailer: git-send-email 2.42.0.459.ge4e396fd5e-goog Message-ID: <20230921081057.3440885-2-yosryahmed@google.com> Subject: [PATCH 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: 4C4B94002A X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: u69ij7mzojnj7je6p8xyhugpoa5ft1iu X-HE-Tag: 1695283864-532977 X-HE-Meta: U2FsdGVkX18S6HOIQAalVy8YONKwSnMGva9c5xGMLSqGUvJ54GbEwwOXi5UyybJ2oFSGmx4r3uEdQLNIdI62tRSqkwP8ly7iTFQobVHy4j/9zuX42gu1BiL5q0Do3mu5iERht4JZGKLjD9d6bgyYysS89IrLPY5OCLMhOoGmvgSQcJlbHHx72EdtoS4+VkYspaRycmI1k63OtET6cx0ebjq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sZE4VToFpsBkJNUwqh9JvVZc5Znkjg7bdwckfXkBMNreFS/L6d+8wFu2PUi0obthok/lSLxilg72fN1ay+Me2RpB5MOBVAfsfjXBZ/BeFUBQaZsaLN0RJkDECZsJLFqGi9V3IkI89JfI8gqRjIdtVnnkCBwwKdtMoa3ARDzi92laIywkmAGRjL6GFWninX7s40yz6puW/qBkO2RKmyUAEo/uo2D4xWBdnXNSj8Fg6Lh9JlcAmHAlePgGG7X4NhbqzvM3UzMO2z8rVTdXLqvwA6xAfwpyYeqLgTWB2PFGpa2d36PbcpiAk1p9QTGqsoOmD/8M9Its2TwI3RUqfyvAhZp1tkKAq9t1N/vUYlkRzTrt2s3gt9VvzAg4WVKU8lOQwvnMVpw== 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 927c64d3cbcb..49562dfdeab2 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(); }