From patchwork Wed Aug 30 17:53:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13370364 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 CDC01C83F18 for ; Wed, 30 Aug 2023 17:53:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B4DE28005D; Wed, 30 Aug 2023 13:53:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4661A28005A; Wed, 30 Aug 2023 13:53:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E0DF28005D; Wed, 30 Aug 2023 13:53:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 1AF5728005A for ; Wed, 30 Aug 2023 13:53:48 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C57F7802FC for ; Wed, 30 Aug 2023 17:53:47 +0000 (UTC) X-FDA: 81181518894.11.AAD5550 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf24.hostedemail.com (Postfix) with ESMTP id 0FC1418001F for ; Wed, 30 Aug 2023 17:53:45 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=WZUaUyMi; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3KYLvZAoKCBoOEIHO07C436EE6B4.2ECB8DKN-CCAL02A.EH6@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3KYLvZAoKCBoOEIHO07C436EE6B4.2ECB8DKN-CCAL02A.EH6@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693418026; 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=rnl+F2n1kOs4P011p6EJFvzkt9Ylx9T9gDi6gAnNyhk=; b=gp/lPK8ZSgLHI8DkI/aXgsDXxdroEVG35AfePDnL9coUjjDZLner4eMG9pqFTcrBxSu1X1 qK+JRYY58CsOrF1OvErt5B5NO8gpBCSllAUOuQrgdAft0x8qSeC1CXSqBHPHTTUXksjzkO RnISHJVUlIhHcNWresW8QEeQELdv+xA= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=WZUaUyMi; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3KYLvZAoKCBoOEIHO07C436EE6B4.2ECB8DKN-CCAL02A.EH6@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3KYLvZAoKCBoOEIHO07C436EE6B4.2ECB8DKN-CCAL02A.EH6@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693418026; a=rsa-sha256; cv=none; b=UhbWdjDVq0nEOzQxghrv1jBPFXPkZjF+bA7wENYIOsCbM3UPG7Ge85qKcnzuUTeGtMhiZQ ONLhkO6p2RrnEiTYf1YqB60MH51/jJfTnhCwmORAmNGVPTeqCW/jE4p+xSkU1PS/kuAbby p7jO/5j7z8a8y+fijU/pNgvncvFKu2w= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-594e8207103so626847b3.2 for ; Wed, 30 Aug 2023 10:53:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693418025; x=1694022825; darn=kvack.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=WZUaUyMiY21N/7cZlwHeGR2FyQJRk9oAjuZRb3M+WQFbUvXQMDh+McKaYuzDX5d2Gp ME/qJJw9SMsgC6cxUYYJWue8JwSlhak90/s9euwFF8uopAOIZsd2ZLdR5RnCgP+gz7lW 1uLsvfQTuly0jLTJhL4O3X1odJjBNJDGwlsM5+R4CSBCQPQEWbJQ/9/93N5r7O3/9FnZ MZ1Qv4t75HX3049ETjRbKt38U1vhy56oQuATO4dEcC4NuB3nB1o0OGCiQJJhhdsqcuO+ qYPXnhtkDsGz+0e75AUh7kGJF1M3IkavqFl5W0f3zQPhPfiPKx+ko4YsmMimoOhW410p t4uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693418025; x=1694022825; 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=J6nAj7PlRe1ATGsZTTju6FJCjvLhBP/XWXffvvkrElzT0C3dqpfcVbKqTsylnH7p/a VkQAsvkB8WYgiXYg75NXJQnre/lSw6Wk1juSWEbLXgNCvDh9wrcmtVGBY8rdIVPzswGT G4JYy4utHt6BsGywSB4s/3deZ0LJe4QVxRbC/v5ZYu7gskFBYMQSWcR9df4RGxIviGyq 2F5F9CrT1Nz7xbejYqTIi3Dwy/mGu+lmDm6Sn1ys1ScpWB2zkPeLxcjtOP0WkZijQGJ4 8jY1ZdlbGt7lwxzkRHMw3tJq3zP9jIA9NI1QXGrSmXyVIBi85Vjaga0sQdP4YNB2i16u 6iGA== X-Gm-Message-State: AOJu0Yx01fGDk8VEriqumOX4lXHiSH/qRu2cTjkKfcTBT3a55UKxyNPo hyybJ0prm3S5YdfMbluuR1K2MF/7OBKkTiZL X-Google-Smtp-Source: AGHT+IHjIqmfPjmTzc3deZ3rYH8rl5Cq8a3bjQb9PwMna3dMgbfSrozthOyv79aDKkmUzbdghxJcDIanu7pcbRLb X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a25:34c3:0:b0:d0e:e780:81b3 with SMTP id b186-20020a2534c3000000b00d0ee78081b3mr78518yba.2.1693418025151; Wed, 30 Aug 2023 10:53:45 -0700 (PDT) Date: Wed, 30 Aug 2023 17:53:33 +0000 In-Reply-To: <20230830175335.1536008-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230830175335.1536008-1-yosryahmed@google.com> X-Mailer: git-send-email 2.42.0.rc2.253.gd59a3bf2b4-goog Message-ID: <20230830175335.1536008-3-yosryahmed@google.com> Subject: [PATCH v3 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-Queue-Id: 0FC1418001F X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: sogpww3ei934era3pyfkuhowfty8uu6w X-HE-Tag: 1693418025-375011 X-HE-Meta: U2FsdGVkX18XjefCymEwVZbGMlwCG9W430O1fTlI2N8E4k0fqZoUDbunF5uPq18UeDnyga82UGgf9uOXHx5rxnP12hIV29frLnafGd5qn9xvoaWxNUCVv25oJTliETVfxorT/aHNbOPTPxih3gTrd3M8R2q3wKvJObm7zVh3aVtyMcwRMZeKbF0lydJqYsWCrxGqgkmTQ+7pEZ1qEgP/ciBtLm3/ASUeI5edtSQvM3yxgS8GF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mBZMk/IH+MWP3tDF7DL9EoJGjqKx390rVChu0a7sERnvBxVvzzozqBdeRqwcajhIorU6fNdMHXYBPtFVKFP0Jo66ndfEUnz5glumw8jwZfzncrgdm8dMiY/q/bBvUPF/52f14sm37qv8VjicSacx5DYPPY9ZV6xJfqylY40JPFX1vm8NpcjFDv0bqoS+Kr30vxiE3SL3pcJ0ZVsO/t2evAsImAYeGcg5v0367Elq0TBHu4evcjxwSgRoQGivo7JwGebRDkZKfqaNnx2wc6tVmCvN4I6EZ9Xos/IjZDMsu/s7NzDNCL4bPybdvfhUTZCB9zqIQLPJ/BQr9fYvVtNA23Hhd01yRUIT/nA= 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 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)