From patchwork Tue Nov 5 11:34:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13862854 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 84C23D1268C for ; Tue, 5 Nov 2024 11:35:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A9116B0099; Tue, 5 Nov 2024 06:35:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 056E56B009A; Tue, 5 Nov 2024 06:35:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E13536B009B; Tue, 5 Nov 2024 06:35:13 -0500 (EST) 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 C107D6B0099 for ; Tue, 5 Nov 2024 06:35:13 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 6B481ACAC8 for ; Tue, 5 Nov 2024 11:35:13 +0000 (UTC) X-FDA: 82751834970.29.9779B89 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf12.hostedemail.com (Postfix) with ESMTP id 2E2C54001A for ; Tue, 5 Nov 2024 11:34:55 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=XjbpOwk0; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=AW+KzJgM; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=e9ysap8l; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=jeYzC7c2; spf=pass (imf12.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730806375; 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:references:dkim-signature; bh=VAWlwyAfV2mxLnX0LEmdok4kAQcKEp4qObHYGBmDVlw=; b=5BTesmKrIv2d4RYUquuODGZTYVSZbfw9mEUzKmAKDnQ70MkXIMWs4VT1wsYVb67KQR4pVS 6Bhdq/n/4fBS1lcdsByTRhV4EX5yx44xpx94HubP/9vuFjPbQ4fMsQpEvwJJAZ0YBZCrqx 6tzXFzltjpGQqUX1Ypk2DSmUQcjKB+g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730806375; a=rsa-sha256; cv=none; b=3pbt5KWtaHoZrS79qSu7Anip2rgg2QlbgW7Grh4L6F9BT2CNUmmguRZVwOEq77zL9pMYjh KOyeWN2YU5zrNkKd0CO9Hg2+1iu1rSkzuAiMPvVpPh7/j5qZg3fVqhIaCPMbGsrOjSqWxQ 37Tt3UEDIGqY6zm/SI8DW5oaGe7CDao= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=XjbpOwk0; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=AW+KzJgM; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=e9ysap8l; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=jeYzC7c2; spf=pass (imf12.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id AA6E521B96; Tue, 5 Nov 2024 11:35:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1730806509; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=VAWlwyAfV2mxLnX0LEmdok4kAQcKEp4qObHYGBmDVlw=; b=XjbpOwk0WSUOLlwCi3gac/j6BoDa/N2CrBgJaTqTAOKqk9AI5PUlTWXYaahKx5ehsyOsDU rtAMM8J4e5NVgj+UP/I2U3k2c27/raiz+JR6aNb5Jx8ztjXCGQm01mLfZwvT9Q1RG5Z40j TocNT0PNS5Y+8sO1/uQfBT0qVMlf98Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1730806509; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=VAWlwyAfV2mxLnX0LEmdok4kAQcKEp4qObHYGBmDVlw=; b=AW+KzJgMbdavrEitp4vuPdsLOmI2vFt66a1XL5rj0nmubIjCv8K0OaNLP9gpIeTR2nd7hS b8xsP0cFKeOHFzAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1730806508; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=VAWlwyAfV2mxLnX0LEmdok4kAQcKEp4qObHYGBmDVlw=; b=e9ysap8lI8XgIFoY/GgFvtDhrLcc5o00IfTrA3EWEQ1xLsNwWGqvEKmjhaT2vu7A/W5R6s ZfDKTamIGeFbNZdBkvCZrkb17SnINtg+gXcL8hV6M3+QFedSj01C8UFw0BPzJwkowqU6LG cuoOYec0hnon5oukK1Bv66b7CvZtiHw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1730806508; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=VAWlwyAfV2mxLnX0LEmdok4kAQcKEp4qObHYGBmDVlw=; b=jeYzC7c2C6/wXtyK5LVlnl/pj/CnRvrCUz2qRDv6SONfyx1Ze0FVHg4CDaevHlHwIBqNbP TUBEyTrpYUM/xjAw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 97E3B1394A; Tue, 5 Nov 2024 11:35:08 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 31C/JOwCKmciZwAAD6G6ig (envelope-from ); Tue, 05 Nov 2024 11:35:08 +0000 From: Vlastimil Babka To: Andrew Morton Cc: linux-mm@kvack.org, Vlastimil Babka , Tetsuo Handa , Axel Rasmussen , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers Subject: [PATCH] mm: mmap_lock: check trace_mmap_lock_$type_enabled() instead of regcount Date: Tue, 5 Nov 2024 12:34:57 +0100 Message-ID: <20241105113456.95066-2-vbabka@suse.cz> X-Mailer: git-send-email 2.47.0 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 2E2C54001A X-Stat-Signature: 6aqxea49m9jk43wn4zb7fbu9rckxwjur X-HE-Tag: 1730806495-613201 X-HE-Meta: U2FsdGVkX18YurFDOPvEcM/0OoiOx6MCNICsVxoQY107/WJP6U3aR+RsSxwMrcVamyvYxSZQtUaDc6Q3Gd+WBN3jMv3Tdol7L3KPSZmQYsRaYH1ILXhgFtWHHO9Ul+LLVoDyiP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Se7gAE5s620NNOca56P91EC0XbbKJTNHBLos4/fizWAmRAVpAMtz/zqSOff3gWPzhBgbET+UQixInblr+mVBialiWCd2iIL+HouIDPQ2OeT8QePfDgjpucA8NXL3Swe4Na+xLcHwZMAXZUtZDTSD3KKO1+AJaInshCcuziV/jtvtdx6JaDhMiNGnUXXWIIk8WuQUX3fThMceF3K5CK6m7NpKZWaKHksncxXJX/DkVDV0LBwEgBNnXe9LEHYyBthjRZjAYhOFPbPEacU= 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: List-Subscribe: List-Unsubscribe: Since 7d6be67cfdd4 ("mm: mmap_lock: replace get_memcg_path_buf() with on-stack buffer") we use trace_mmap_lock_reg()/unreg() only to maintain an atomic reg_refcount which is checked to avoid performing get_mm_memcg_path() in case none of the tracepoints using it is enabled. This can be achieved directly by putting all the work needed for the tracepoint behind the trace_mmap_lock_$type_enabled(), as suggested by Documentation/trace/tracepoints.rst and with the following advantages: - uses the tracepoint's static key instead of evaluating a branch - the check tracepoint specific, not shared by all of them - we can get rid of trace_mmap_lock_reg()/unreg() completely Thus use the trace_..._enabled() check and remove unnecessary code. Cc: Tetsuo Handa Cc: Axel Rasmussen Cc: Steven Rostedt Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Signed-off-by: Vlastimil Babka Reviewed-by: Axel Rasmussen --- include/trace/events/mmap_lock.h | 14 ++++-------- mm/mmap_lock.c | 39 +++++++------------------------- 2 files changed, 12 insertions(+), 41 deletions(-) diff --git a/include/trace/events/mmap_lock.h b/include/trace/events/mmap_lock.h index f2827f98a44f..bc2e3ad787b3 100644 --- a/include/trace/events/mmap_lock.h +++ b/include/trace/events/mmap_lock.h @@ -10,9 +10,6 @@ struct mm_struct; -extern int trace_mmap_lock_reg(void); -extern void trace_mmap_lock_unreg(void); - DECLARE_EVENT_CLASS(mmap_lock, TP_PROTO(struct mm_struct *mm, const char *memcg_path, bool write), @@ -40,16 +37,15 @@ DECLARE_EVENT_CLASS(mmap_lock, ); #define DEFINE_MMAP_LOCK_EVENT(name) \ - DEFINE_EVENT_FN(mmap_lock, name, \ + DEFINE_EVENT(mmap_lock, name, \ TP_PROTO(struct mm_struct *mm, const char *memcg_path, \ bool write), \ - TP_ARGS(mm, memcg_path, write), \ - trace_mmap_lock_reg, trace_mmap_lock_unreg) + TP_ARGS(mm, memcg_path, write)) DEFINE_MMAP_LOCK_EVENT(mmap_lock_start_locking); DEFINE_MMAP_LOCK_EVENT(mmap_lock_released); -TRACE_EVENT_FN(mmap_lock_acquire_returned, +TRACE_EVENT(mmap_lock_acquire_returned, TP_PROTO(struct mm_struct *mm, const char *memcg_path, bool write, bool success), @@ -76,9 +72,7 @@ TRACE_EVENT_FN(mmap_lock_acquire_returned, __get_str(memcg_path), __entry->write ? "true" : "false", __entry->success ? "true" : "false" - ), - - trace_mmap_lock_reg, trace_mmap_lock_unreg + ) ); #endif /* _TRACE_MMAP_LOCK_H */ diff --git a/mm/mmap_lock.c b/mm/mmap_lock.c index 368b840e7508..f186d57df2c6 100644 --- a/mm/mmap_lock.c +++ b/mm/mmap_lock.c @@ -19,43 +19,23 @@ EXPORT_TRACEPOINT_SYMBOL(mmap_lock_released); #ifdef CONFIG_MEMCG -static atomic_t reg_refcount; - /* * Size of the buffer for memcg path names. Ignoring stack trace support, * trace_events_hist.c uses MAX_FILTER_STR_VAL for this, so we also use it. */ #define MEMCG_PATH_BUF_SIZE MAX_FILTER_STR_VAL -int trace_mmap_lock_reg(void) -{ - atomic_inc(®_refcount); - return 0; -} - -void trace_mmap_lock_unreg(void) -{ - atomic_dec(®_refcount); -} - -#define TRACE_MMAP_LOCK_EVENT(type, mm, ...) \ - do { \ - char buf[MEMCG_PATH_BUF_SIZE]; \ - get_mm_memcg_path(mm, buf, sizeof(buf)); \ - trace_mmap_lock_##type(mm, buf, ##__VA_ARGS__); \ +#define TRACE_MMAP_LOCK_EVENT(type, mm, ...) \ + do { \ + if (trace_mmap_lock_##type##_enabled()) { \ + char buf[MEMCG_PATH_BUF_SIZE]; \ + get_mm_memcg_path(mm, buf, sizeof(buf)); \ + trace_mmap_lock_##type(mm, buf, ##__VA_ARGS__); \ + } \ } while (0) #else /* !CONFIG_MEMCG */ -int trace_mmap_lock_reg(void) -{ - return 0; -} - -void trace_mmap_lock_unreg(void) -{ -} - #define TRACE_MMAP_LOCK_EVENT(type, mm, ...) \ trace_mmap_lock_##type(mm, "", ##__VA_ARGS__) @@ -65,16 +45,13 @@ void trace_mmap_lock_unreg(void) #ifdef CONFIG_MEMCG /* * Write the given mm_struct's memcg path to a buffer. If the path cannot be - * determined or the trace event is being unregistered, empty string is written. + * determined, empty string is written. */ static void get_mm_memcg_path(struct mm_struct *mm, char *buf, size_t buflen) { struct mem_cgroup *memcg; buf[0] = '\0'; - /* No need to get path if no trace event is registered. */ - if (!atomic_read(®_refcount)) - return; memcg = get_mem_cgroup_from_mm(mm); if (memcg == NULL) return;