From patchwork Sat Oct 26 00:48:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JP Kobryn X-Patchwork-Id: 13852001 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 07910D149F8 for ; Sat, 26 Oct 2024 00:48:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B51FB6B00B0; Fri, 25 Oct 2024 20:48:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE60A6B00B2; Fri, 25 Oct 2024 20:48:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 891456B00B3; Fri, 25 Oct 2024 20:48:40 -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 657F96B00B0 for ; Fri, 25 Oct 2024 20:48:40 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 67229ACEB3 for ; Sat, 26 Oct 2024 00:48:00 +0000 (UTC) X-FDA: 82713917412.24.85542E7 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) by imf23.hostedemail.com (Postfix) with ESMTP id 3DF0A14000A for ; Sat, 26 Oct 2024 00:48:25 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ux0JGirV; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of inwardvessel@gmail.com designates 209.85.216.43 as permitted sender) smtp.mailfrom=inwardvessel@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729903678; a=rsa-sha256; cv=none; b=4IJ3f92lJwB3yLBKsEIELlZoNA2Hsy1z9s8vZAF6WXst096g1+DGmjllN1CAvVu6fKySyT uo/pr6vbWPVQBZiRZAI4lCqP6y+73d7KRiFN8NiHAVLjlIyetKQ5Omn/USyg7MHXyhIXJo 2gLaBeZLX/oeNu7chdCb2LvaPu9smyM= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ux0JGirV; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of inwardvessel@gmail.com designates 209.85.216.43 as permitted sender) smtp.mailfrom=inwardvessel@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729903678; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=B7wkW5g8TgqYKms/EFJSg4ezSMWpKMTpB9wnMr55mBM=; b=xlQg37cGsC2rbv49NkAlAG5cLXUfkijG2Eis+6eJ6USdkshLPsPxd2XRUS3ourKwCxGcAl d2G+FJSwlpHR9tO41Fqeqs4ZM4tn0g12b0FpNwCUTz+BwLeIqy0DdkRFnMP+UR04s1iYdD qZ13UnV4ulLfW7ebZnzylptY6qAp0vw= Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-2e56df894d4so1975363a91.3 for ; Fri, 25 Oct 2024 17:48:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729903717; x=1730508517; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=B7wkW5g8TgqYKms/EFJSg4ezSMWpKMTpB9wnMr55mBM=; b=Ux0JGirVlt3oYAxA8tNLmofZt7vHu6yTOOcKQkWOK4Gat8dcnsMEdirFKPlAuSOw99 gtDRBMIWYlsM2w4sSFNGhIONYuYZyuapMapCEne2aX1PebUmBAxS4loqAG4JoCecSV3u hwLc9ryEjYH1rELbLoqpWBMCeHQly+1cYy9Cph7grh3JXp7aTRVN5SCnyddRQl98Y3OK BIHAU59mb22abHZHiHfyCHmtvUNVnzxMigrQRPTj4BlA0frq3kwAMP41/bx79n+29/LF ehdWkWF2wJQS1LKEqZNWtO3HXCbwWyrNMqH05aL0oBKdxVrv7EtXKpRTRNeoLpId3BdG 0xgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729903717; x=1730508517; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=B7wkW5g8TgqYKms/EFJSg4ezSMWpKMTpB9wnMr55mBM=; b=sU0Yf9oM9RZmIbYkzef+rrrXD3F+NLXi4O8PjCetXOm3Ip+/XTJQBOEeCNhF05oW7O 7RN8ljCBNCjsdzMUDTU7QWdmX2z3JtzAGZyD9Vc9Au+G1jeR6HQJXpd+8SX5Q+6444L2 LuaEaWSdSmXIl2W9qWXWy3eZB7Ty5rc5XJ3HWIYk4Le38n+3sVD4QtImLc2+bzi6Wbcs w4geZHxRelxUs6IktUDgrflx1vmu8REGNNn1WWLwyHsLEbCSi0e23bM4uIKSknzEkmcH NRhsmgb+uSqUj0rmfCbXPs68z/rQvdAqUAC6bXzoet9eo9UPHo0NsuS0zxUTVEd0L48X 0WNA== X-Gm-Message-State: AOJu0Yzch5G4G6+kMmE6pXvkNUYuAYAfKs3u8cAY8xSFKJvrfJxY8xef gUM7JntQ1jhJmF48WYHol2tvRNfWEDY02CB16aP6HnBayD1Fxa+p X-Google-Smtp-Source: AGHT+IGRa7wyJzb72DXQWRWTr+119ZVVaA6HoCFe7k1c8dGjMI4ZUfJOYX++19OXxKJqpUeCJq4grg== X-Received: by 2002:a17:90a:ca07:b0:2e2:e597:6cdc with SMTP id 98e67ed59e1d1-2e8f107c680mr1496488a91.22.1729903717298; Fri, 25 Oct 2024 17:48:37 -0700 (PDT) Received: from saturn.. (c-67-188-127-15.hsd1.ca.comcast.net. [67.188.127.15]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e77e48ad66sm4249738a91.4.2024.10.25.17.48.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 17:48:36 -0700 (PDT) From: JP Kobryn To: shakeel.butt@linux.dev, hannes@cmpxchg.org, yosryahmed@google.com, akpm@linux-foundation.org, rostedt@goodmis.org Cc: linux-mm@kvack.org, cgroups@vger.kernel.org Subject: [PATCH 2/2 v2] memcg: use memcg flush tracepoint Date: Fri, 25 Oct 2024 17:48:26 -0700 Message-ID: <20241026004826.55351-3-inwardvessel@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241026004826.55351-1-inwardvessel@gmail.com> References: <20241026004826.55351-1-inwardvessel@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 5paztqowkxs6cchawanobbwefsk7884b X-Rspamd-Queue-Id: 3DF0A14000A X-Rspamd-Server: rspam02 X-HE-Tag: 1729903705-16274 X-HE-Meta: U2FsdGVkX1+QdMOT/ZvepgFSXLwZxkIsVLYXy3HWyWD/MopaNGXzHqAa97Knl1aCRb35YLAKtA0gTwzwA9oGTgixaioUBB8NDRu1E2E1yHVmhr7qyl72ijK0KXgs3vZGrr4sy4i3gjdU9aNgpaU9v+rc9mgIDcrFqiCHKyeKJ/eDAUmhTigILYYKoE8rtT5qcg5AFg9ykIDhlI/HY3HZilSuWmJ6yXf0FRQtuyHmRsJH2z/8Pq+sEXxEaAvxkVUiK5rPyF8iwvaCrrVDNg4ZDLVBGL8tW7txQMfJwtbsInshY/tasJdNGIPmeH9/fMLSSN0Mta1sxSJOb1ku1evW+rsI6AO7Nt6t170hnZcA0qoyWBfuNh3WVIi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loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Make use of the memcg flush tracepoint within memcontrol. Signed-off-by: JP Kobryn --- mm/memcontrol.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 18c3f513d766..c3d6163aaa1c 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -588,8 +588,16 @@ static inline void memcg_rstat_updated(struct mem_cgroup *memcg, int val) } } -static void do_flush_stats(struct mem_cgroup *memcg) +static void __mem_cgroup_flush_stats(struct mem_cgroup *memcg, bool force) { + bool needs_flush = memcg_vmstats_needs_flush(memcg->vmstats); + + trace_memcg_flush_stats(memcg, atomic64_read(&memcg->vmstats->stats_updates), + force, needs_flush); + + if (!force && !needs_flush) + return; + if (mem_cgroup_is_root(memcg)) WRITE_ONCE(flush_last_time, jiffies_64); @@ -613,8 +621,7 @@ void mem_cgroup_flush_stats(struct mem_cgroup *memcg) if (!memcg) memcg = root_mem_cgroup; - if (memcg_vmstats_needs_flush(memcg->vmstats)) - do_flush_stats(memcg); + __mem_cgroup_flush_stats(memcg, false); } void mem_cgroup_flush_stats_ratelimited(struct mem_cgroup *memcg) @@ -630,7 +637,7 @@ static void flush_memcg_stats_dwork(struct work_struct *w) * Deliberately ignore memcg_vmstats_needs_flush() here so that flushing * in latency-sensitive paths is as cheap as possible. */ - do_flush_stats(root_mem_cgroup); + __mem_cgroup_flush_stats(root_mem_cgroup, true); queue_delayed_work(system_unbound_wq, &stats_flush_dwork, FLUSH_TIME); } @@ -5281,11 +5288,8 @@ bool obj_cgroup_may_zswap(struct obj_cgroup *objcg) break; } - /* - * mem_cgroup_flush_stats() ignores small changes. Use - * do_flush_stats() directly to get accurate stats for charging. - */ - do_flush_stats(memcg); + /* Force flush to get accurate stats for charging */ + __mem_cgroup_flush_stats(memcg, true); pages = memcg_page_state(memcg, MEMCG_ZSWAP_B) / PAGE_SIZE; if (pages < max) continue;