From patchwork Wed Nov 29 03:21:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 171046 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp93729vqn; Tue, 28 Nov 2023 19:22:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IFR1srCdMEcsX0ot+mhP0siruVLPKohFFnmpSf6VAQc85HdrKKTWluHAP0n2w0wtS5evJNu X-Received: by 2002:a05:6a20:1612:b0:185:9de4:fd31 with SMTP id l18-20020a056a20161200b001859de4fd31mr20751804pzj.18.1701228139099; Tue, 28 Nov 2023 19:22:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701228139; cv=none; d=google.com; s=arc-20160816; b=eORrW2hqHtziT4gjgsH9q3gXcKzyPuz9xw9u/YFYAq9r4FZwnEAtSOkMeTqeuVGO83 M8wjcoOVW+wFyh+OtEeB0eIM+enVNBXVj/WJOZP5bceDBkvf+PTy45zdp3L2ypCrqZW3 QIUuVvYi6QsF6SFq8cc7hR9Ebr+PuND6jPxxKMRQFH0wACnJXPHhbZKu0/oOWqzbVtM/ E7pOqvFR2aFNIa1bvx2HFFkMuamEFWuGlEOroufbvT2moAlK0w/MlD6xEpuY17kMo63g OzgC1ZrVTAo6F1nc5sRoOVryqVRpM8GqEmc8jKrm4CdRr+qVFub6ArwdAHqCMPCSD9DG vXHQ== 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=fp/riADQZ1JFvdRujo1i1RQ8s//WQnrX4uDVuQ0rm8w=; fh=Pm9SgGzNjCEqL0otM1q16UGxNMZD1s8fy9+tqXRmHkk=; b=q1EYSZURqcdsJ4PLcIFdEoCfrQovHvVZxRkBDHOqOhroSUonceSl/teT1y9C3KqsTe hTnXaFeN6IzjS5k8Z+c618EOBZMVT4c/UdLkBQk1yeJQqfw51SfN2GVi+R79dXuXLeDZ cPNtd5ml9wFu0WE4SjLOxX6u4+K52qvadGqigWO6ZJg1ETe7rgyF4/I/i5va58vm/H7Y S6pWiW1urfRL9wjiqdYWaJ/9ni1MRCN8scpkk9VFXFZLj9o23ZY4mkohx9SPCLVMAr+D ABoT4h4GWbqYLdHymZ7pHu2F+mjmNwjSUGPJmx+JTXkcQcPbIDWElo/yq9R4jVun1UCA cANA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=sCdK98qg; 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 k140-20020a628492000000b006cd8db96c41si5920864pfd.388.2023.11.28.19.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 19:22:19 -0800 (PST) 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=sCdK98qg; 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 AF63E83265A0; Tue, 28 Nov 2023 19:22:14 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376804AbjK2DV6 (ORCPT + 99 others); Tue, 28 Nov 2023 22:21:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376781AbjK2DV5 (ORCPT ); Tue, 28 Nov 2023 22:21:57 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F139170B for ; Tue, 28 Nov 2023 19:22:03 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5cef61289fdso62231557b3.1 for ; Tue, 28 Nov 2023 19:22:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701228122; x=1701832922; 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=fp/riADQZ1JFvdRujo1i1RQ8s//WQnrX4uDVuQ0rm8w=; b=sCdK98qgWhoJR3PGUUZRPS/hHV8LDZgsKmwDVzRPz3X+n0GVx6P7nB1IKmDXqs+xQT MQILFBRjJLTYuP+aGxavV9ic8GAChQdJdyffjaJc5HsyLTg3CsNY2eLlFQhHaYASI/ok T1lk+4CpefOD0ovHv65nHLt1YL0G2lBcqblVQ3GsNpgKyk2EzbhO2zAMcYPi81zH4X+e roFsoITbpKfSUsjXl8W8i0nL44kbdW1zRZdDrXQLBH/H6ejcC6MMVUuTZGsg1zhdkvPQ mleuzex/LXPKuNgFova6wbjk+qxPYzf3PiUAc7wHpHyO3H0OGMdEKPyFpiokfo4LNMVe CGIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701228122; x=1701832922; 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=fp/riADQZ1JFvdRujo1i1RQ8s//WQnrX4uDVuQ0rm8w=; b=IkOfiXNos63Zcb9+IoiFEjmwAwHeNfrtrBXbvNSD60e7gdW+fMiaIktXy4ZwyDq/7S EB51m99fksnhlWTjAG6eS60bdj0Dbsl3fPRNdVmY4Ww2QXVko1ZGNk25dCQ8JC/29Z1x DGw1Nuc6SF40V4hH3TGJSCXbWzFRqPFFYcBwxc7+MWu/DmAJqqHpWGi0nO4zwHvZHsir IcWxkFXcBSiltIkYkPJedLe7GWoBK2cQFkQeBuakdxSL7arczw3kV4ewuhUKYAkuZpGI n7oUswescmLcMZF+wZguOdV0N6uVnrJ19AxTHN5F4tQ6nF3PSAKKExacotjZMUZyrH/b pf7Q== X-Gm-Message-State: AOJu0YxH+rDedEB4JetsDKPFyvb+RiLWz1FQ4GnenHfblUlvDxW7kUN7 i+EAgjNvIp2DFIp8UVYk/H5oXrm62kh/aU50 X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:690c:989:b0:59b:ca80:919a with SMTP id ce9-20020a05690c098900b0059bca80919amr510184ywb.0.1701228122771; Tue, 28 Nov 2023 19:22:02 -0800 (PST) Date: Wed, 29 Nov 2023 03:21:49 +0000 In-Reply-To: <20231129032154.3710765-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20231129032154.3710765-1-yosryahmed@google.com> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Message-ID: <20231129032154.3710765-2-yosryahmed@google.com> Subject: [mm-unstable v4 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 , Domenico Cerasuolo , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed , Chris Li X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable 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]); Tue, 28 Nov 2023 19:22:14 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783866997401207079 X-GMAIL-MSGID: 1783866997401207079 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 Acked-by: Shakeel Butt Acked-by: Chris Li (Google) --- mm/memcontrol.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index f88c8fd036897..61435bd037cb4 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(); }