Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2264635rdb; Mon, 9 Oct 2023 20:22:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH3YrDACP7TJQd4wlGTuYuN0SgyMMChNEbGvk8AmWYK2JejCvJPayjPT5cbiqGUlF+I7YUo X-Received: by 2002:a05:6808:2220:b0:3a9:cfb5:4637 with SMTP id bd32-20020a056808222000b003a9cfb54637mr22439675oib.38.1696908123716; Mon, 09 Oct 2023 20:22:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696908123; cv=none; d=google.com; s=arc-20160816; b=NPkg6+7J7Py9a6mD8tTw572vgLxS9JLoQbSsDbO0Kk1oU8cBlySTxcrl3PG5SN6teP Z+0u+lFFI2AqtXDDZRAEZLODcd767uRsvXmjLUv9kna+3NUo4yPl0PAhM+Kve8ZyxXMU q2w8Z/g2oMTa5TC1JNcmD4I/FQWDzWV7DsJEQgvARmfWj2331byppe3LKPvAIsEsytO8 wFemoiAUVfKskfs70qhK/rn2dxXWnAYhOuNd1WucI/3uNn3w20rErt9yAW1HoK4uyWUu ZmgaustSTJE/fisaP+eyqhZ1WMrecFPtYmgE8DmXV1oBW+n0dBxsMwpZFpEezQvJplgO m4JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=Txx2Z/24+3F8Cj+NRtOMU7JL27MtRQwWcbI2dA3u7/E=; fh=i6r7D8Tbv5L0V2RUiJXfGU+sNI1eFV0UjCNL0oNyQ80=; b=KWTPtwP6GaIrGCuJntkW4anIXPientaUPWqYAcXcH8mdr23waAPflCBUJnCCCBq0C+ I9gyMumxtbQPStM2rvRlETsWgw66f77jxKbksW7qnZiBSqGU20sWJKecPvEqSO230Hqo 9lrGqutb9b69vGp3gaFUYWxXkICBhMv57jCmfQFdLkNLxzt61N88rTkcMMmsrhaTo3OD 0qxj1qwBBIDjVe4LPx9mr9pZMWjjlGXm0AxKSdlWCkUbVo3KakFMNnckYxacAthR1jm0 RuFULbcxJsyqhl6KnR+FEojk9fjHIAn+uM7wcSjpCpApwkPm0T6DP0ga5uyAMIh73HLP vlDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=hy3FXdt8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id b6-20020a633406000000b0058b056e76c2si7618202pga.250.2023.10.09.20.22.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 20:22:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=hy3FXdt8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 41C5F80C4D59; Mon, 9 Oct 2023 20:21:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441968AbjJJDV1 (ORCPT + 99 others); Mon, 9 Oct 2023 23:21:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1441959AbjJJDVY (ORCPT ); Mon, 9 Oct 2023 23:21:24 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0C1BA6 for ; Mon, 9 Oct 2023 20:21:22 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-c647150c254so4608763276.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=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=Txx2Z/24+3F8Cj+NRtOMU7JL27MtRQwWcbI2dA3u7/E=; b=hy3FXdt8nWVJipZ9sJI1zwZLXulM+5YQg9PMfnYfavjXBk8VGzkYlmS8Qb125iXUSl g6PicacYZEPQwKF+4trujJz25wAL1a2U834PrTEI43SKtjX2DaT+cs90cca+vBxo38FB XJwsFsg1ORFgE/3KICaUNMJPqvUUqK/JIj4rzqC6C25SPFs6YxaNnkAPS/wD8H5mg136 Gact1W1Mw5lNbkByEYOyHkmUSGkf48rQSS8cAbG3beVTSPuambGxRiojimDiYIrC39ZK YxiWLnPTQ3epuFWNhEfuQBxTVnsgl9KA1FUci227Sp3W9eafgObnJISqSVEzjP2/itYr HavQ== 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=TTKXgXNn9zJulFxjA2xqQnZB88r3+bONQPzH7858K4cYlAtJZ0QeH35MXjeUEVRbkG FCbqtkqU2OInzmGpKkeR0Z6BgjTLCZ5uiKO2637kAa3vEAuAqhRT+S+Sp089H57L7FAi nFNHSXi4ChrBsNezBcLh7VFVVVvjEB4NKDvXtCDNQsZr26wF7iGMgoLk2VFPp41QB0zB p1iBrJVhTx7jAe6Mym+UO0uTJP7l0wBocoX1Ws4PKfo0KTP5+7hL7QJW7OefCWgZpbPD +yT7oYVTPSjO+//lNK61PUqnN0jkAvlz9viKHyoXdk1OdNaev6n+QfwaCDQseTLfQqo1 rx9w== X-Gm-Message-State: AOJu0YyJ1TBfZztR+8bkrJWYd+Z9q4WnfG4WfjojqaIQF1Y8jX+06Z5W r0NIXHGkyjIEY25HJY/VDS+psqrVPR2WepBe 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=20Koutn=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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-4.8 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 09 Oct 2023 20:21:52 -0700 (PDT) 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(); } -- 2.42.0.609.gbb76f46606-goog