Message ID | 20231116022411.2250072-2-yosryahmed@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2943599vqg; Wed, 15 Nov 2023 18:24:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFeEqHgJhE9Qseulpv15O2RRUW9JSvBmnv9k1npy+reLc5LOwj9cZMlIsbUzj2gt0kUT9R7 X-Received: by 2002:a0d:ce45:0:b0:5a8:1d2e:e3e4 with SMTP id q66-20020a0dce45000000b005a81d2ee3e4mr14938181ywd.35.1700101472216; Wed, 15 Nov 2023 18:24:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700101472; cv=none; d=google.com; s=arc-20160816; b=HO8XlraMZm29qxkKTS+siNxPjqsaPgqbsfDFNSvjeo9qYs8TU18XEY3hDkf5s9NbGQ /ldrt2jlKgkJMtonPzxi4oe7jeLG0XS970apnn8AWiqRqng1DGHERq5Zkgi63U3VnD6w umwTk7ub9wEUMk4qu8hGv7MF1Enxu19nY2ZTGXOdfmjwijCtHjvnzNuZsRaoUZwERnsp 1QQ3UHzDcZxJFo11LIqgTV0kTXwdKKJpdgFyKr+4PlsLuVYtzFPlUDH3rfSzJ+wbRvSt oTNHOEqSzER/hUKV3h+b6G62fc35E51AWGvoOlBMigXje4WGds4VUaIQtDBcXZSXV9WM ze5Q== 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=BcE9vJD0hOv2TBpe3ivca8OUmRQ1FOEoUuzJXTFrwQU=; fh=IfBS1eUR4Ph2d1rlykJm3WUUhflOgyoV/WQxPmHrs48=; b=qCaBI3kx784+MqF/74JbHD2aM3uKEoAEvsBE195S/+WW7m61nIvx9cFVnljQQmSBIs XZdRfmU2/Q/or7kb2BcmmjvDfsk1pODpc5t9t77WjeYKlOM1HWrMIhIrRwU8iutKP7wy Cr1YpnB/mpnqjUvMshsXgEuz0d51MZO4E9kDDGc6doNIlNR4PgAmwCApDszkg/rzaaAd NwKzLcx/sYT7kd2tkyNhAFyya6IE6Fy/SA1q5KgJPyeJz7R091036LdoAU5VUdJT0tV5 19RptqtUp/hUoeIM4IN2xkHNH9Ttn1pu+UG9ndjcS2WeJXeXXeGv8/PW/RH4gEU4KxtG f2hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xe5MtW0w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id e25-20020aa78c59000000b006bd78b99aa5si10888060pfd.334.2023.11.15.18.24.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 18:24:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xe5MtW0w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 7529280C8D60; Wed, 15 Nov 2023 18:24:31 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344517AbjKPCY0 (ORCPT <rfc822;lhua1029@gmail.com> + 28 others); Wed, 15 Nov 2023 21:24:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232310AbjKPCYT (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 15 Nov 2023 21:24:19 -0500 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 EBD3C1A5 for <linux-kernel@vger.kernel.org>; Wed, 15 Nov 2023 18:24:16 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9ab79816a9so401617276.3 for <linux-kernel@vger.kernel.org>; Wed, 15 Nov 2023 18:24:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700101456; x=1700706256; 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=BcE9vJD0hOv2TBpe3ivca8OUmRQ1FOEoUuzJXTFrwQU=; b=xe5MtW0wJjFy8d59ZlUsqx91/pLiIvBH1MJeyaAasPiwtQqJCd6jwX49qQ1h70vghI 3WCKs5vPHO9p3WE74yGqXixldwo7ea3GX2j/zYG63t8sgV4D8TCM41oN1ILr5opRDq05 A2r2XGny+xev5ka+WgAXc4fyD4cCDVXkRzly3bMvHTmaQWfKTxOMRWbWoBZAbmeljHrK tsGAx4oLV/mEj0u5BGWis4ET1stjBpfvgpUIxFqm5JdjEe+d+glwpLcHgosogA9yVU8/ bHDwB4H58NI2/8xBxNYoOzjZEkLVLApzAnk2NzeqtC9RpE5oCQom99LKC68s/eVGDwS0 7JIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700101456; x=1700706256; 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=BcE9vJD0hOv2TBpe3ivca8OUmRQ1FOEoUuzJXTFrwQU=; b=O2DszXs/9K4LGM3IGnTxTluBI+O/Z8AXzFZ3Bb8Qx5ARrz/nr9KfXxVtDZpSDSLV47 iMI1FEsjLNzEIb5AuXKX+jgWEuW0loGk/Y+ZahUbKJfqaYZnbx2pm36tASjCrM6qAJSy fo7nfNAZPXwqCnAlqMjsoOZ3KZXIvGPvhxbQ4ak2bzEUfJWf5+SiFTl8Wb/G5Mf5H4FH 3gJk+iOg3fguFV31JBilgTqWw44wq2eeeM95vBl2uAMYjYb5YQbSiN/FrCM8EykPRhQ+ ehgbZjN1j0wfafkzNVpMrzeEQRirhlxu36acdfBV2uCnjqoGOPBawMtYPTFwlqU3e2ey HnvQ== X-Gm-Message-State: AOJu0YyvnZH77kXiymOZzaIyMrgdTFT+aK4cpDSvwc5tfS/VMJO60kxb JNOQMKNZwheDLEaNAd2YKvb8Ik8c0LPPVF3R X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:285:b0:d9a:d272:ee58 with SMTP id v5-20020a056902028500b00d9ad272ee58mr402081ybh.9.1700101456166; Wed, 15 Nov 2023 18:24:16 -0800 (PST) Date: Thu, 16 Nov 2023 02:24:06 +0000 In-Reply-To: <20231116022411.2250072-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20231116022411.2250072-1-yosryahmed@google.com> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog Message-ID: <20231116022411.2250072-2-yosryahmed@google.com> Subject: [PATCH v3 1/5] mm: memcg: change flush_next_time to flush_last_time From: Yosry Ahmed <yosryahmed@google.com> To: Andrew Morton <akpm@linux-foundation.org> Cc: Johannes Weiner <hannes@cmpxchg.org>, Michal Hocko <mhocko@kernel.org>, Roman Gushchin <roman.gushchin@linux.dev>, Shakeel Butt <shakeelb@google.com>, Muchun Song <muchun.song@linux.dev>, Ivan Babrou <ivan@cloudflare.com>, Tejun Heo <tj@kernel.org>, " =?utf-8?q?M?= =?utf-8?q?ichal_Koutn=C3=BD?= " <mkoutny@suse.com>, Waiman Long <longman@redhat.com>, kernel-team@cloudflare.com, Wei Xu <weixugc@google.com>, Greg Thelen <gthelen@google.com>, Domenico Cerasuolo <cerasuolodomenico@gmail.com>, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed <yosryahmed@google.com> Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 15 Nov 2023 18:24:31 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782685601245188415 X-GMAIL-MSGID: 1782685601245188415 |
Series |
mm: memcg: subtree stats flushing and thresholds
|
|
Commit Message
Yosry Ahmed
Nov. 16, 2023, 2:24 a.m. UTC
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 <yosryahmed@google.com> Tested-by: Domenico Cerasuolo <cerasuolodomenico@gmail.com> --- mm/memcontrol.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
Comments
On Thu, Nov 16, 2023 at 02:24:06AM +0000, Yosry Ahmed wrote: > 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 <yosryahmed@google.com> > Tested-by: Domenico Cerasuolo <cerasuolodomenico@gmail.com> Acked-by: Shakeel Butt <shakeelb@google.com>
Hi Yosry, Acked-by: Chris Li <chrisl@kernel.org> (Google) Chris On Wed, Nov 15, 2023 at 6:24 PM Yosry Ahmed <yosryahmed@google.com> wrote: > > 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 <yosryahmed@google.com> > Tested-by: Domenico Cerasuolo <cerasuolodomenico@gmail.com> > --- > mm/memcontrol.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 774bd6e21e278..18931d82f108f 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -593,7 +593,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) > > @@ -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(); > } > > -- > 2.43.0.rc0.421.g78406f8d94-goog > >
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 774bd6e21e278..18931d82f108f 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -593,7 +593,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) @@ -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(); }