Received: by 2002:a05:7412:f584:b0:e2:908c:2ebd with SMTP id eh4csp1942480rdb; Tue, 5 Sep 2023 09:23:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEsdxgfdRy0NDaxO4Qdmbh62H8mNrs7X5a/tSajc2eMDIA1FXIocHJNICBo1DMTKQrwKEPd X-Received: by 2002:a05:6402:1ac7:b0:52c:a382:e0d5 with SMTP id ba7-20020a0564021ac700b0052ca382e0d5mr227504edb.34.1693931038602; Tue, 05 Sep 2023 09:23:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693931038; cv=none; d=google.com; s=arc-20160816; b=d1J8gZ3Vnk8be7sVgtLU1oYyhSzGhkM4YL/SSDY7rd4S5nOhryg2kY0jua6yBGoK4f bCU1dm/RLsOLc86Oq78hYP0+XGr47YH/l6RZ+/KdRaQGKlHdbHToBAM/ZN5S1LfhvmSe +pAQN5gEUgXaakfOX3nOqIVXU2+sZvC1hdvhlXMlyc1eE3KKm4yDUEyFQqkc405+KwHa Feox6SHt+NhDHWSccQaJ1Nl64yeel/yhdi3o+PehrjbctbtWCnqwqlOoQiza1d5whW0o 8QL6rY4Gl/FELUqNM78sg+oxwLGO1uis1J3RsRAWONDCWEQFdIMljMNE65bzF/vgZ8q4 0GfA== 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=rnl+F2n1kOs4P011p6EJFvzkt9Ylx9T9gDi6gAnNyhk=; fh=13Ix7vfLeSxxY7+IndPKsuPdb9j9iT92GIU+yR4zsJo=; b=mUHqYQr6JdydiwdCGq8e2DfyWKzZcX90X8tAEY18iI18A4StUf8NbywYcVjkyy23bM FT/O0kS717UYiuTyBeg6G3Z1gVpZ1iJ7F2t0jd2lqTioCsX6Skr3DThLMsiSMgnC248w DQnySchVYMgqLrTzn6LMnFLST7XFyHN0eTHX97SwvQYQfRSp0Xjswtl5mSd6NgcGqWPj hTxcEsK1Kl1F5/+/rlgNlTmL2RMPH459BjH8J3LlvTEAz3mv2OxyQtbtoY+TfAxFkPcZ ZZxQ3Z8w+IPEKp+eoW/ezwoIkYESkqxAq2WKl9aZi6iaFINJ2fA8HGOzHMZ/+0L+0sCJ Jtvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=1UCvVlVx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u20-20020a056402065400b00523346514dasi8024329edx.240.2023.09.05.09.23.53; Tue, 05 Sep 2023 09:23:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=1UCvVlVx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244626AbjHaQ4X (ORCPT + 8 others); Thu, 31 Aug 2023 12:56:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345539AbjHaQ4W (ORCPT ); Thu, 31 Aug 2023 12:56:22 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A8E0107 for ; Thu, 31 Aug 2023 09:56:19 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-68bf27251b7so1190157b3a.0 for ; Thu, 31 Aug 2023 09:56:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693500979; x=1694105779; 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=rnl+F2n1kOs4P011p6EJFvzkt9Ylx9T9gDi6gAnNyhk=; b=1UCvVlVxvkygSVCtxlJldpmxZZ67IB+D3cLFko+rqK7fWxwKANEVqrTdC3bdO2hdQH es4uWKrUOUc8aVbcp8xSS1KwmTpi/VUunr1dky9yrxfXXKA6o+7o0xJsILS9R2XpoxhM NtXHPvPjAHDx4taXuhGP6vQyl6yU3LrO2RXgzvEySqz5drf9C5xNd72rhbuO2GR/2h4+ bRoie1iJ0SoIsZZe3GO9LDJ40SPvoP3UnexBDicGWOepvnAHDpVQdYlbRLzDVKvIO5FH JItRgGwGgqPMo0Hf60APaYqSN43igGQZHeF793cnsx+gA9w3Do290y6qvYKE1gG1QK8u yFZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693500979; x=1694105779; 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=rnl+F2n1kOs4P011p6EJFvzkt9Ylx9T9gDi6gAnNyhk=; b=Ahng+UFTDWme1L+xtTYGWSc+jgjvdgKgwTKQEc0viDpz+wwfIxYPoD1fZ94qIDfOM8 tFlS9n2RO44b5YbJ0ZoBl4leCOohxIOJ6Mw7e+m4nUpXZk2giTyzOxzeuNYd23MhcMPs KBcHPoeuY0vXG9Tu6SSYUes2v2A2bLRxSStku1AFyTlmJqhXqDxhYbVYf7L3nTjRroeQ iVVYUOYl5bHiAKXBqw1fuv2dW86qzR3b20lJpPRQXmUFGFI3cQFV3av2yx6+dUcTVQXM 8k+HZktODIX/a/v+/l/3t+rkfC8ZbtyMg4RVQgtYbqxRGJVtuZ2ln7/1H+OkGPIXdifg SJLw== X-Gm-Message-State: AOJu0YxDtNQn/8FxQ+Vbfn9c/s9ksOHr34kHrGPpa/4MDXcHHFvKDtfF 4Ugb64Fij+q06/P/oF8Xhe2GNjEuLl/eiWvA X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a05:6a00:2d87:b0:68b:dbbc:dd00 with SMTP id fb7-20020a056a002d8700b0068bdbbcdd00mr86084pfb.0.1693500978729; Thu, 31 Aug 2023 09:56:18 -0700 (PDT) Date: Thu, 31 Aug 2023 16:56:09 +0000 In-Reply-To: <20230831165611.2610118-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230831165611.2610118-1-yosryahmed@google.com> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog Message-ID: <20230831165611.2610118-3-yosryahmed@google.com> Subject: [PATCH v4 2/4] mm: memcg: add a helper for non-unified stats flushing 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 , 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=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,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: X-Mailing-List: linux-kernel@vger.kernel.org Some contexts flush memcg stats outside of unified flushing, directly using cgroup_rstat_flush(). Add a helper for non-unified flushing, a counterpart for do_unified_stats_flush(), and use it in those contexts, as well as in do_unified_stats_flush() itself. This abstracts the rstat API and makes it easy to introduce modifications to either unified or non-unified flushing functions without changing callers. No functional change intended. Signed-off-by: Yosry Ahmed --- mm/memcontrol.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 2d0ec828a1c4..8c046feeaae7 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -639,6 +639,17 @@ static inline void memcg_rstat_updated(struct mem_cgroup *memcg, int val) } } +/* + * do_stats_flush - do a flush of the memory cgroup statistics + * @memcg: memory cgroup to flush + * + * Only flushes the subtree of @memcg, does not skip under any conditions. + */ +static void do_stats_flush(struct mem_cgroup *memcg) +{ + cgroup_rstat_flush(memcg->css.cgroup); +} + /* * do_unified_stats_flush - do a unified flush of memory cgroup statistics * @@ -656,7 +667,7 @@ static void do_unified_stats_flush(void) WRITE_ONCE(flush_next_time, jiffies_64 + 2*FLUSH_TIME); - cgroup_rstat_flush(root_mem_cgroup->css.cgroup); + do_stats_flush(root_mem_cgroup); atomic_set(&stats_flush_threshold, 0); atomic_set(&stats_unified_flush_ongoing, 0); @@ -7790,7 +7801,7 @@ bool obj_cgroup_may_zswap(struct obj_cgroup *objcg) break; } - cgroup_rstat_flush(memcg->css.cgroup); + do_stats_flush(memcg); pages = memcg_page_state(memcg, MEMCG_ZSWAP_B) / PAGE_SIZE; if (pages < max) continue; @@ -7855,8 +7866,10 @@ void obj_cgroup_uncharge_zswap(struct obj_cgroup *objcg, size_t size) static u64 zswap_current_read(struct cgroup_subsys_state *css, struct cftype *cft) { - cgroup_rstat_flush(css->cgroup); - return memcg_page_state(mem_cgroup_from_css(css), MEMCG_ZSWAP_B); + struct mem_cgroup *memcg = mem_cgroup_from_css(css); + + do_stats_flush(memcg); + return memcg_page_state(memcg, MEMCG_ZSWAP_B); } static int zswap_max_show(struct seq_file *m, void *v) -- 2.42.0.rc2.253.gd59a3bf2b4-goog