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: 150459 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp2251853vqo; Mon, 9 Oct 2023 20:22:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGbkoViLIsvcHnzRsxkMZ39iUARzbexTlbxLieTqrskzZNriDfP41ItN1p4kcF4adcdW8dR X-Received: by 2002:a17:90b:4c03:b0:26c:f6d2:2694 with SMTP id na3-20020a17090b4c0300b0026cf6d22694mr14410997pjb.12.1696908141870; Mon, 09 Oct 2023 20:22:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696908141; cv=none; d=google.com; s=arc-20160816; b=0vRhIaXV0rWJ0dI/kwEyftTrx1k1PrQtj31EzubPaWJm0vQNhf3Jp7GxHdNgktxP4z iRO6KlNSat97PutHRRVxHBKa2B+MPB0mKwBZEDbB/AYz+hD2ps+dOok+x/j1HZA5zoWi RZ3Og9cdkS4Ts1DuqlT296YhOMPzvcWs2ZlA8KCFmVPw5Kx06wqigOiTqjG5ltN/HrFY py+mRIw/mEZA412yGt7JORehiVffCsTbmAlE8TSNwHlTP6u3FgCtO2zwTu1fabbKaJFK Dh7pqeafZFRFu78x88WAIZCBz2loOVmG5F2Wdk0PddG8xihsywNyLZLM4hXRewkdptIF 7TLg== 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 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id kj11-20020a17090306cb00b001bc162f3318si10039313plb.640.2023.10.09.20.22.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 20:22:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; 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 2620:137:e000::3:4 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 74A9C80C4D52; Mon, 9 Oct 2023 20:22:19 -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 S1441971AbjJJDV1 (ORCPT + 20 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?M?= =?utf-8?q?ichal_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-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:22:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779337151867145878 X-GMAIL-MSGID: 1779337151867145878 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(); }