From patchwork Tue Oct 29 02:11:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JP Kobryn X-Patchwork-Id: 13854339 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 0BA2BD5B865 for ; Tue, 29 Oct 2024 02:11:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E815C6B00C6; Mon, 28 Oct 2024 22:11:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DD7066B00C7; Mon, 28 Oct 2024 22:11:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDF276B00C8; Mon, 28 Oct 2024 22:11:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8F0A86B00C6 for ; Mon, 28 Oct 2024 22:11:20 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 47F8D140A28 for ; Tue, 29 Oct 2024 02:11:20 +0000 (UTC) X-FDA: 82725011796.06.7A7CE06 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf30.hostedemail.com (Postfix) with ESMTP id DFE0B8000E for ; Tue, 29 Oct 2024 02:10:32 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Tif0iZ5L; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of inwardvessel@gmail.com designates 209.85.210.169 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=1730167703; 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=62ijouUXGdPsDpTOyUYsa0hTBBZ19BQGZ0b2Cjo/M5w=; b=13Iz9MTVSIk73K0LUsk3SGYXCGNYREIFQV7ZOZheATvXZ+veDhKVXcB8FYTzuUQiOR/u0c zjB05QHLxXNmbW/6K+W71IDt1fZqOMk293tCh5Kn+Ti7cT1uOdH6AsfNgpCzCT7lq+0YeU W8Ju0+vpXb3EZBzL1QQVJYvhj3YoRo4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730167703; a=rsa-sha256; cv=none; b=kXWCPeTyPxaCFbyHAjtg9GlKRZrJOtHCOcNBq2/l+ZpKoFM8h32zjWSeduxq3MK+b0Yun6 W/KivmSV0hHg8G4fjfc9rcZ1KxXBaaO9c775MPOS92QxsV6qx++c/XoNmKYN1Fy++kNNXK lTZr9w9VntKsz/vJuNqWV79zfnkHdgw= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Tif0iZ5L; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of inwardvessel@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=inwardvessel@gmail.com Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-71ea2643545so4050151b3a.3 for ; Mon, 28 Oct 2024 19:11:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730167877; x=1730772677; 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=62ijouUXGdPsDpTOyUYsa0hTBBZ19BQGZ0b2Cjo/M5w=; b=Tif0iZ5L35adaJwvGzH6yOic/VKc+Wlke9Yo55w5tYQtbWvMMJjIQJXqclUzKDroKw eq+5EfoIn6oEN8M6Du7TH/PZDauhvrDF40rXCpFy14Z+dZ3d9kObYp/UsOzmOVdjPatu Ggq6UyLCxsYUxe5+ZbDU2GPZgIp4HQ+eMl05eIRZpCMOtB5ovnW3JVqdG/XEO/4m+Buh GxpWHsZgPKhwVYYqvzHAinkvF5qhkGJaeqmUVQBERSzrPNVuLexE4/p2D4/36ZOaP2RJ u6CN0QqJQnCmBLe8cPuibIgd0KWHftPUd1l40j12TNuISE1mxTtS38VKPjpLfIefL+pX jgZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730167877; x=1730772677; 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=62ijouUXGdPsDpTOyUYsa0hTBBZ19BQGZ0b2Cjo/M5w=; b=YBdhqM86OujfFz8rKcrHD84/HNIKeBvCeCqEB1ZNelUsgH5qVqBn0cMZQbrRh6/0ht EOBlLcXBrELQVKMbsPYAm75aZDsPZ21wH8Rr4Tjp5L56hjGjgcZqdDb8JnyI8zoStiBI h2NyVsQIvNmczD+f/8BW65i7ghg60deuZ04wfWsI/W1gB79Jy5hy65WGqoMsXXHoJ5ke Di07DJbyP0mCo01+DJ9m08R2s2TLVZhPrs5nWFzoEk46A7iWDISvUk3smpvVcJjnD6SH DMw+B+iSZ0ZnckXDmRELOQZ3yQEw1ptw2Dw0xWLX2FeZOBUPVSPdWhSVAgevHdid8qir ScYA== X-Gm-Message-State: AOJu0YyNMt78kDJEm0EEmsC9dWZA4+y2MqsUfghFVVRV0+fjK0xI4ThP 9Y2fcl1BUU4rvIrUQSiPJjAoVNcWiQRzsGgV8JzyCILkv2jj4mdy X-Google-Smtp-Source: AGHT+IGCLf5U4+sFsqYb2ermCrY/7iLSB5IEVW+42bLnZfp2+/qnyRqlJW8VvMH+sXRXZ71UqhS2cA== X-Received: by 2002:a05:6a00:3929:b0:71e:2a0:b0d0 with SMTP id d2e1a72fcca58-72062fd4b4bmr15741361b3a.13.1730167877101; Mon, 28 Oct 2024 19:11:17 -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 d2e1a72fcca58-72057a0df99sm6500884b3a.118.2024.10.28.19.11.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 19:11:16 -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 v3] memcg: add flush tracepoint Date: Mon, 28 Oct 2024 19:11:06 -0700 Message-ID: <20241029021106.25587-3-inwardvessel@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241029021106.25587-1-inwardvessel@gmail.com> References: <20241029021106.25587-1-inwardvessel@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: DFE0B8000E X-Stat-Signature: xjntdmnsf4px9dbtuhh5yfbiuo1yzixk X-Rspam-User: X-HE-Tag: 1730167832-449177 X-HE-Meta: U2FsdGVkX19MFW47bU3/gHkHmkLFScdCJuk9wc3zBjaQZZZsHSpQ3rss4iNnT/wRDExNjRoRGziiAss6ALqia/EihskzuT3zmKMbBvDp6Pa4YU7OWSjuBVQ8d8CuMoW9mvJTwqxPb1hMawiGi51DaEZoKmSUt/CzvQ9r9deOlDWqwAQcnoUkEeouWKwWsZVFb+KkkV+r5SAo2NHBx85TkZ7WREzGrgG2Orkt8exNwJHU8E+lTtKcBvfZKa/qjl6iWfSl+E9geXHmjyjlyrlwXdlK1e/ImxtLM8D8YZApVJxqD80sxioO6GrX5O4cUI0t42mflWe45gx/XDkZZRr9SBomzw4HHx6ygOuQdzPcRw8xL3yka11zp0AvoIMTEeP+cKzMLzr7gA4e1XmCCgJD/QFf+ecFDX+YXl2t4/8gX5lLsxys64geqQ9K1FM7GO4f3v+ow5eq8nuDGJl2WSRbWJbV71FEskfhG7mF7nA/OVp2qcEHh8RlA22YUTh37oCgYdBabx3r6fNSdTfHlK6Fl59wTT9N/pM1aMFdj/+oYV3bNVG05t9lSQFjBUb4rJo+vFF7i5IykHYN5jTvIr0OHYKkgT1WSUfQcqvsQzzznQp+9ICD+SbE3UmQWIkMwuvvObklqYPXnXrEfT08RVp4Ud8s3vBhc83HbTTsXmDKte7UuG4/8LsKD8yTduz26/XVibu5flJPbnzMlvHpZKMJjpiViYo+MAo9DVsYmVi0a7m+fFq5UwlYZwHAbM7ScVEZL5QaGn/DvTv4Yw2mlpt9lOMRWICStQhNZaBI75l0Av/4JGNiVDxDEezEEe8kEMkSK1MTcsIGqZj5ipc9IF4pwLT/IfEa3ZMxsDRtLBpT0l5yWzqWi/pmV6jXDof5+uQluZGH9HMKMjHG/t00GlJvbuHE/YuDVbmr9bwg7ArsAAvTi5G8WaydRuwHCHiIMp75HR0JLe2lRrECj9OzZ/B W+HimIir 5XNLwxAyVdYE1qBttFWmSLNwWPmmg09P0XcAqr1rlePBAeyDQZl+a7jq1KMnIKfc7oijWK2oWtOew7vG1JwHOUNAWYvlrdzGhvJN9R372XUqP/57ax0aOz4kPExXLGqI4+RHvwoiCiJptVFT1iRsPKGa3iXvEZs+qwIfHFOpaMaya2lLBedWZtkvTymSkcUmgcYrh3JMAYVl6pWoZuo5GgGY32lyzzcIWlNhWGKlWQcknAPrCf0xkMNmyA8qDgrxrSeM+QxWqPHcjXRRO/9pRWI1PlVPp4dPolcveUwpHNOYEsAC4TfpxHFnojk5drgynROlZO4DhWy0xFDVMHppVMh2Z8nUjiAAM1bg0pJQivezUmWsWXRdyHGkkAA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000051, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This tracepoint gives visibility on how often the flushing of memcg stats occurs and contains info on whether it was forced, skipped, and the value of stats updated. It can help with understanding how readers are affected by having to perform the flush, and the effectiveness of the flush by inspecting the number of stats updated. Paired with the recently added tracepoints for tracing rstat updates, it can also help show correlation where stats exceed thresholds frequently. Signed-off-by: JP Kobryn Reviewed-by: Yosry Ahmed Acked-by: Shakeel Butt --- include/trace/events/memcg.h | 25 +++++++++++++++++++++++++ mm/memcontrol.c | 7 ++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/include/trace/events/memcg.h b/include/trace/events/memcg.h index 8667e57816d2..dfe2f51019b4 100644 --- a/include/trace/events/memcg.h +++ b/include/trace/events/memcg.h @@ -74,6 +74,31 @@ DEFINE_EVENT(memcg_rstat_events, count_memcg_events, TP_ARGS(memcg, item, val) ); +TRACE_EVENT(memcg_flush_stats, + + TP_PROTO(struct mem_cgroup *memcg, s64 stats_updates, + bool force, bool needs_flush), + + TP_ARGS(memcg, stats_updates, force, needs_flush), + + TP_STRUCT__entry( + __field(u64, id) + __field(s64, stats_updates) + __field(bool, force) + __field(bool, needs_flush) + ), + + TP_fast_assign( + __entry->id = cgroup_id(memcg->css.cgroup); + __entry->stats_updates = stats_updates; + __entry->force = force; + __entry->needs_flush = needs_flush; + ), + + TP_printk("memcg_id=%llu stats_updates=%lld force=%d needs_flush=%d", + __entry->id, __entry->stats_updates, + __entry->force, __entry->needs_flush) +); #endif /* _TRACE_MEMCG_H */ diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 59f6f247fc13..c3d6163aaa1c 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -590,7 +590,12 @@ static inline void memcg_rstat_updated(struct mem_cgroup *memcg, int val) static void __mem_cgroup_flush_stats(struct mem_cgroup *memcg, bool force) { - if (!force && !memcg_vmstats_needs_flush(memcg->vmstats)) + 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))