From patchwork Mon Aug 21 20:54:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13359807 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35C22EE49A6 for ; Mon, 21 Aug 2023 20:55:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BFDDF940012; Mon, 21 Aug 2023 16:55:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B86588E0012; Mon, 21 Aug 2023 16:55:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D926940012; Mon, 21 Aug 2023 16:55:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 8850B8E0012 for ; Mon, 21 Aug 2023 16:55:23 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 61AC7A0CD7 for ; Mon, 21 Aug 2023 20:55:23 +0000 (UTC) X-FDA: 81149317326.21.9F91D66 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf02.hostedemail.com (Postfix) with ESMTP id 98A8C8000A for ; Mon, 21 Aug 2023 20:55:21 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=BxE45txI; spf=pass (imf02.hostedemail.com: domain of 3OM_jZAoKCJMLBFELx49103BB381.zB985AHK-997Ixz7.BE3@flex--yosryahmed.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3OM_jZAoKCJMLBFELx49103BB381.zB985AHK-997Ixz7.BE3@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692651321; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=EWXap7NsEgOymMxjxsCXNzpaZzVX2vYEXhkkwglYb2w=; b=KZyI+LF6R7VBlYj43A2c+DLBj14YNCcW4LW24INgkf0e2IVOWQsw6i4rGNykGsDwJgOJj0 6cfFy+xT0y5pJE/xJAiztxKciRAy5mVROqP7xhLanLAaIpmj1Vc/fWWt/cw3WaywVvcX7I lQA3BmSgYFTqREIwATw/ov1SOJ6Lrgs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692651321; a=rsa-sha256; cv=none; b=zaVd6YrLRUGzdFpdMjEp7aa9eMN4JzQP9UlNSxFUmixhlIv7Hk6fchCSODbDhPhYtwZ0lM toREfDhmJK85qV7RUSScisxtmsPaNJnVHsvVspdiqGk0CFktyKrOeEnHLZ1P+0qPZDyde2 5le/SiO8FWLAAH1kwKWJMLOyJ796CXo= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=BxE45txI; spf=pass (imf02.hostedemail.com: domain of 3OM_jZAoKCJMLBFELx49103BB381.zB985AHK-997Ixz7.BE3@flex--yosryahmed.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3OM_jZAoKCJMLBFELx49103BB381.zB985AHK-997Ixz7.BE3@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-1bde7998451so57389525ad.2 for ; Mon, 21 Aug 2023 13:55:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692651320; x=1693256120; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=EWXap7NsEgOymMxjxsCXNzpaZzVX2vYEXhkkwglYb2w=; b=BxE45txI7COiK2llaPLekWLKmnwKvbfF2s+ErO15DE6ofDgcY41orJSnC1lxnC5xSD ns0NI3CFDeBKOgHffDfz8J+snMVDi/Bm1Z7XQP+gB/BJurXrc210wa7+HakGaRIeyfrR gkyrBvxIdVL0w6/wEiEjuj80edhWhBOarSLoMLG6xilaOxakqnBgLMne6hlBqjVYfs4v ENXPjTfI0g332oAIouzQJ4gw4Eqbnd43rlLTg2T4GFT3PPeE9f1Qb7UfSFQpFlOSlXs8 BweEjiJ9C0STVkzlpyv7rd/z4Ep9F8B9BTFfyXqsH3AJsnekq8bnFOZfOryTXvrS+E+8 DCMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692651320; x=1693256120; 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=EWXap7NsEgOymMxjxsCXNzpaZzVX2vYEXhkkwglYb2w=; b=lnwG3YSN/RamYEjex41KBGXijStYM3pXaKJwT6VBbdncTr6oF1T/qbfCZOq31noXbQ gI5tLXu/JJfD939QOoGCSJJUoRjQjPITu6SvToJD5RCnEGw3Yhm6FJ5Yc+KLh29HzmAn 4U96AxG+rGRnqbikSQ+O3e7GkCJx02Q36km30ZOFMmdBo8PLmt+Y394sOLoCkhqDlYw5 5/8PCebS+lRiLdKYjjJy7jL1fEzE6LhiWFaEBY+29VnvDJdZ2bU06O7i9leL34apPMbF vsbv9fiiDe2N2N72iX7HxtFTuftFhEv56WmhJIHMWTUKm3hTZwKpGJPiwEw2n+on0LaN 7CdA== X-Gm-Message-State: AOJu0Yyw9X5mDGnPmCLzpJ05wVjwXOvEPt4hq7/88hw33ZSNMdwWtHgF 8W3VQKXnWeggIOHHCCT+6n+JrL/JcgwWhOM8 X-Google-Smtp-Source: AGHT+IFrW4DDu5hPoWYHSg5YRuSc/PnkgVYk/IScMtefDrv62gvp7vZ2XxWBYhOW7vd5z08FD5JBCBz/m5ZQr4DG X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:903:2806:b0:1bc:5182:1ddb with SMTP id kp6-20020a170903280600b001bc51821ddbmr2949941plb.3.1692651320527; Mon, 21 Aug 2023 13:55:20 -0700 (PDT) Date: Mon, 21 Aug 2023 20:54:57 +0000 In-Reply-To: <20230821205458.1764662-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230821205458.1764662-1-yosryahmed@google.com> X-Mailer: git-send-email 2.42.0.rc1.204.g551eb34607-goog Message-ID: <20230821205458.1764662-3-yosryahmed@google.com> Subject: [PATCH 2/3] 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 , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspamd-Queue-Id: 98A8C8000A X-Rspam-User: X-Stat-Signature: p1hfzbpccbdmkffezqmxpep9pe3piaht X-Rspamd-Server: rspam03 X-HE-Tag: 1692651321-259847 X-HE-Meta: U2FsdGVkX19kxw1e0o+Nt6xFZzeG/uGsxgInU3sGzwVbA8AUJGI3NTM3bpPm/WaXwObDk88yqfiYfyFSXklS1H6foklz+nofmUmcpTGCD+kBOEZwfBAJLGVR8DFSQZSsK+8zdFLHshsXdwSCrJnmpBacaGGQuWi+DgsEELx3D7FtmY2DbNxtliBE+F4z6lLQFATt18d3B9Gp92hOcEesyRseS5VwgqubJHKM0fHdAe45gV0o5R7NG2pKwRxcZG3wmxXAOojBayp0ZNbAm325guVhYvhUu6ATV9rhXuI8J5NKJ1eXwYbI594mGEynJMm1M4wrrjX9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fsknm5g1yHWKjtL7KDft75EMZ5/cVmk0bnsOIvwU9UeBKLJSvWu9IEe3sR33pDVqe08HIis09L+zzNxPRx5RwxZcw0eYb4un6aGSu3gPkRytQSo/8tWXGpYez2m1LvM5AKD/LaUEoeYI7g2EavZ1nnbUCKdnbD6fNLzBN14FzFMKk+P9RlICN51FODsMYLO2EOsBTyV7z0eHQuhP2QWDTKn+Sf2Wi2ar2TbaWKEiJdGt1kf+qNRMxzsmZozBOO0nlXiUb1U10LSJQBHtabADmCxlE6yxA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 c6150ea54d48..90f08b35fa77 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_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)