From patchwork Mon Aug 28 23:33:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13368409 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 CDE5CC83F11 for ; Mon, 28 Aug 2023 23:33:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E5CAB28002B; Mon, 28 Aug 2023 19:33:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E0BC38E001E; Mon, 28 Aug 2023 19:33:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C876728002B; Mon, 28 Aug 2023 19:33:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B223A8E001E for ; Mon, 28 Aug 2023 19:33:29 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8860B14066C for ; Mon, 28 Aug 2023 23:33:28 +0000 (UTC) X-FDA: 81175117296.19.27CA5A5 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf03.hostedemail.com (Postfix) with ESMTP id CD50F2000C for ; Mon, 28 Aug 2023 23:33:26 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=sSpYPt7r; spf=pass (imf03.hostedemail.com: domain of 3xS7tZAoKCAY4uyx4gnskjmuumrk.iusrot03-ssq1giq.uxm@flex--yosryahmed.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3xS7tZAoKCAY4uyx4gnskjmuumrk.iusrot03-ssq1giq.uxm@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693265606; a=rsa-sha256; cv=none; b=aich4zunBQjjUgICmyFn4wCV3/8p5S4M9TBp+UZyTn6koid1I/oWFdORm+WpLW1WoR59M8 RPKq3K5fFuA4TIn47hx8XWQ9+3Gfmc0JL0G4EygitXrr0l0OvH/q56Kqo6sqcM+VR28Bzb ceUctMhiujbBjpLO49sr7iRXDJW1lDY= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=sSpYPt7r; spf=pass (imf03.hostedemail.com: domain of 3xS7tZAoKCAY4uyx4gnskjmuumrk.iusrot03-ssq1giq.uxm@flex--yosryahmed.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3xS7tZAoKCAY4uyx4gnskjmuumrk.iusrot03-ssq1giq.uxm@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=1693265606; 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=I5n9hS9q/cqFV2qh34A2AZEA4DGYELaonjfoFoCAI8g=; b=T39vURDEs2ZRIu/zlF/fV5YWxqEE+q1rjVeIINijNcLWY6kCSMC4/wxeFMCAEOjPiT7R0R +k9SQbdihP/bZvvUas+iRDB2YQwf8t+9bNIgwwEK2Pqz03ZOH3yAHas3N52++PUAxGJWxp NibG9Gb/9npv4bChl+F29Nrjm3tZdq0= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-c8f360a07a2so4461482276.2 for ; Mon, 28 Aug 2023 16:33:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693265606; x=1693870406; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=I5n9hS9q/cqFV2qh34A2AZEA4DGYELaonjfoFoCAI8g=; b=sSpYPt7rKW3DtUM15JcLQJplUoRrPMx95M/aXCWUkUGG4gZ450QgwVE4yFUm7CogQH zFv9UI4D9YSxvW6bodhDxj3Ik66YmhEKFtQN01JiGkk9R6pRwoVFGBpQEhzaG5mXyhg+ 7vKrj39/+K2fsqeCBVG9cqcEQsLe/O8dA6loSupqE+p8mxgQd1Y/Cch38q9mTgfWAdOU Mi/PT8DoWdqlQunEGCPiAM+0xArU4vTZKSIUUhJFt8vF/ApSZdUHhIi/YFoCfVUArao7 1xkMsp1FV1LDKVh9Dm5/i7gS4Zp0X1DnugiYstil6izVooJ18sBWRLBaLBmogvidXImj ZLUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693265606; x=1693870406; 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=I5n9hS9q/cqFV2qh34A2AZEA4DGYELaonjfoFoCAI8g=; b=KCYMqJ9vP3xfHttpyBHE/enhQTAJlCyzieuOw11YjluxcylbGJy6b3qhYzVjmlP6q3 yW7EIeVamVwEuoLcc8kyAy9K1t90RcmrJ4meCnoXeusXe0yZNnJgoBjjJjuFrzVfo7e+ 40xqAo3UIFfqEJ6/W8sysjOhI6+Na0lQRPm/zPKNqK4pVPKUxr4cegsz+Q5DSmF+MADk pSYv35gM93+9lhQKZRwKXGPUOXATAD0WW2jqbYVD/s0feqtdDiBvxkox91qN3aZ82mvC UM7SJevkvuoqLt2ScAmmlvsxdd4+RF8eJ4LFbGLH7fxWdjRChiPew5Kt3p/BtgmOIQ5x PPWQ== X-Gm-Message-State: AOJu0YzdMBKn3+rAhvz5GFs+ZQNMu12lLnjRev+4TJMUSVK7NSQisZaH p+8YW+3mYDHVE1jPsBbzQelWLBWKIhlRLolf X-Google-Smtp-Source: AGHT+IHgw1Dv81YEOafHari2+haF5L0KUBFcH2n6KPrSQNlL17+4o9VM2wgivkwVdbEOE7or4T1k1wZFPbeokEu2 X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:1788:b0:d78:3a29:214f with SMTP id ca8-20020a056902178800b00d783a29214fmr506633ybb.10.1693265605965; Mon, 28 Aug 2023 16:33:25 -0700 (PDT) Date: Mon, 28 Aug 2023 23:33:16 +0000 In-Reply-To: <20230828233319.340712-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230828233319.340712-1-yosryahmed@google.com> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog Message-ID: <20230828233319.340712-3-yosryahmed@google.com> Subject: [PATCH v2 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_Koutn=C3=BD?= " , Waiman Long , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: CD50F2000C X-Stat-Signature: gm3gwi1a5byxhk85znu95ybmiumj1dab X-Rspam-User: X-HE-Tag: 1693265606-839644 X-HE-Meta: U2FsdGVkX19FbEDCXEH00GvsR3K789Gmv+plp8L9TU/0pbplr4A4VwAcsIQvnswUxhmNB1DK6/0/G4ItQsbVtF1Gc/HpXe/3lNfCOPPltIEsgrmlX1HvNnzbZ4OW2ocS8GSLNGKhXwORzTpIeKoKjoME6wSXKqB1tgLP4ykeaEX3+sYabzM4D8ZF4ra31ZMUkcnrsaD5cwTjAEwSFrGKCJ5luWKbS8FmCWjdCMGK+b9CuodMAVMoqk2VBSyQ/+tBjCoPRxleb1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tCw7pDFJBZMmgul85R2+zkGd/0d0yLcRxn+vQ1O0agJqw1gbOjnaMf0ZNPU5UmRqSsptUvVtR5zUCga/SWubENKD29AwkdXYSymJcEPvdPMfheYEu1furBUrM/2dCpO0FNrWWHXxKp4Mco/NEBmyIR/H4v0kwCFyliph04ADu7E2DphoIzSCBuLbuM/0UePu9dfOIlgp9EZCl5cEcj9xeK77azkdRvXWHfB0stYa4ZsqHz3UQZuoDnHzQnF3DwHbzPbA7/R4o9C5wkXdhoa/IsWGow7SRxDGFwklcGL7AAJg4GKB6sLQi7VLZTwF9JSx4xiYvo5ZM/8XB9eRvYZmC2G1PNV1T1Q== 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)