Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp714657rdb; Fri, 17 Nov 2023 10:28:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IGJ7tjQ2uYIJ9HdWOhfU5T3HhP0oigRMxTcoPa58s9VnOPBKEHq1R4+F6YPmAC/rwleg8LN X-Received: by 2002:a9d:628f:0:b0:6b9:6a96:698 with SMTP id x15-20020a9d628f000000b006b96a960698mr13992519otk.7.1700245682388; Fri, 17 Nov 2023 10:28:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700245682; cv=none; d=google.com; s=arc-20160816; b=zRWOToP2VOGXRUFKY23mX5W60pvzE0ZKXk1zruEj+rAzUWuHXr1RJaYRbwlkyCYfKJ RSijrKK7VT4rNk5VSoWBVeDc7fh8FQASd9i4UmkH9yVf60/lCe8VR1qnhGmuk/V5uKMt //2fbb4sDaY3P4RIhjYb8JgDwcAfb5wCpinkIFc9xCjCCjjqgP7YxoSWBZutSzXk5gel DO1PhNy6+yqIlqcp7rq0C+L3UKhd0+nisLWJPIOmgjuw+mqoFCDcxaT/DvbinCBbJ96W 3FK4iNYEk9U+gc+ZVWKdnXj+Jw0uGOUARtaqnx1D8jBffel2VM+w0Dxzp8e7Y5PmPv5x pEdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=IvdKNgi3UWcb1IIVeL2qsulik3uVpDE3O/GHmdcefGQ=; fh=1xw/WyapXKmgMcrTV6ypF3chbYxsm5C3xlJOVpzYRb0=; b=fEzJzVRdzepKJgX/DYkN/HiAX4iQ0PMx3jlAAM4bddgmgnnEgrIYZyHENHkjlBFOi2 2oOjcOob+eebjmws6LENvb1BRKC23+gp+wx2IZxB9PmCtp5DaEX0esrPJm6vuY8tGfjO uPKkS7uHhy5QiyElYGZPC6tgl/w0kCNTOIrnkUeGAj9CZe7ckCX5ioPvrd3/OOwGm+60 lk1S1e+ahBPhOcgt5tYOJKSu7TQzhRrdJFu8iRj2eixXu2Crxg4PlLfCQ1RJUTXGkn4Q OG+YbljDWZyrlUXQ2kZwKQBOOlVG+J0dA7tWjV45tfUdEDSAnse0bkX4Gqq4GwqBY8mX wuOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oXWrazzd; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id s3-20020a656443000000b005b16e351343si2374268pgv.241.2023.11.17.10.28.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 10:28:02 -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=@kernel.org header.s=k20201202 header.b=oXWrazzd; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 0E34B82A7543; Fri, 17 Nov 2023 10:28:01 -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 S231430AbjKQS2A (ORCPT + 99 others); Fri, 17 Nov 2023 13:28:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229535AbjKQS17 (ORCPT ); Fri, 17 Nov 2023 13:27:59 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE59EB0 for ; Fri, 17 Nov 2023 10:27:56 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5ED6FC433AD for ; Fri, 17 Nov 2023 18:27:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700245676; bh=H2YJzXZHeJMrqobov57j5Mo2OH4tf0fbT7tTCJHnXIo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=oXWrazzdj4fEldueS4rULJ5F/DAW9Te1RVNyHNBdkoXhUW9Wx3X6kYxQikIFgJnJL s0ZnPj+Ha+FnZCKm+LB+yErJsPvh/5MVORN17pUuGEfTB4nhK8XBXYrdWCkocGxKiu RVm0g7wPCbb5iDcsj4hjM/VQzx/i0RG7NYWEun1lUOJ8w+BBFt0As6Pqfw/+KOAtLX i6m6wQRMKxUZLxdxBw5jcihA15/9my3kZphYYEOprR0sRp4VmflVd0KUCsYqe12qcy 5gqcXAuaM2iEHQiin2LYU6Q/pjxqR6qfAu9dgz8RUW7Hakb2huEHBYGauzrizQGB/d yALJaa0qh581w== Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-27ff83feb29so1970417a91.3 for ; Fri, 17 Nov 2023 10:27:56 -0800 (PST) X-Gm-Message-State: AOJu0YwZqZmXr+UHtYU1iimd4+i/jyTqOYHH/X4ZXbx2mtCFOPgUxdzQ OM3i/8YiOVXxsu+Dr4h1ytvluxEFDplyn4UIEnW0Cw== X-Received: by 2002:a17:90b:1c83:b0:27d:b3d:5c33 with SMTP id oo3-20020a17090b1c8300b0027d0b3d5c33mr386546pjb.28.1700245675572; Fri, 17 Nov 2023 10:27:55 -0800 (PST) MIME-Version: 1.0 References: <20231116022411.2250072-1-yosryahmed@google.com> <20231116022411.2250072-2-yosryahmed@google.com> In-Reply-To: <20231116022411.2250072-2-yosryahmed@google.com> From: Chris Li Date: Fri, 17 Nov 2023 10:27:44 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 1/5] mm: memcg: change flush_next_time to flush_last_time To: Yosry Ahmed Cc: Andrew Morton , 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 , Domenico Cerasuolo , linux-mm , cgroups@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: 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]); Fri, 17 Nov 2023 10:28:01 -0800 (PST) Hi Yosry, Acked-by: Chris Li (Google) Chris On Wed, Nov 15, 2023 at 6:24=E2=80=AFPM 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 > Tested-by: Domenico Cerasuolo > --- > 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, flu= sh_memcg_stats_dwork); > static DEFINE_PER_CPU(unsigned int, stats_updates); > static atomic_t stats_flush_ongoing =3D ATOMIC_INIT(0); > static atomic_t stats_flush_threshold =3D 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 > >