Linux userland API discussions
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: David Laight <david.laight.linux@gmail.com>
Cc: "André Almeida" <andrealmeid@igalia.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Juri Lelli" <juri.lelli@redhat.com>,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	"Christian Brauner" <brauner@kernel.org>,
	"Kees Cook" <kees@kernel.org>, "Shuah Khan" <shuah@kernel.org>,
	willy@infradead.org, mathieu.desnoyers@efficios.com,
	"Linus Torvalds" <torvalds@linux-foundation.org>,
	akpm@linux-foundation.org, "Yafang Shao" <laoar.shao@gmail.com>,
	andrii.nakryiko@gmail.com, arnaldo.melo@gmail.com,
	"Petr Mladek" <pmladek@suse.com>,
	linux-kernel@vger.kernel.org, kernel-dev@igalia.com,
	linux-mm@kvack.org, linux-api@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v8 2/6] treewide: Replace memcpy(..., current->comm) with copy_task_comm()
Date: Sat, 31 Oct 2026 10:30:08 -0400	[thread overview]
Message-ID: <20261031103008.6849760c@gandalf.local.home> (raw)
In-Reply-To: <20261030223435.0e802eb7@pumpkin>

On Fri, 30 Oct 2026 22:34:35 +0000
David Laight <david.laight.linux@gmail.com> wrote:

> I suspect the trace code would be faster it is just copied the (first)
> 16 characters and worried about whether it was terminated later on.
> It does far more 'saves' than trace reads and their performance is
> much more important.

I'm assuming that the compiler would optimize:

+/*
+ * Copy task name to a buffer. Final result is always a NUL-terminated string.
+ */
+static __always_inline void copy_task_comm(char *dst, struct task_struct *tsk, size_t len)
+{
+	const char *_src = tsk->comm;
+	size_t _len = min(len, TASK_COMM_LEN);
+
+	if (!_len)
+		return;
+
+	memcpy(dst, _src, _len);
+	dst[_len - 1] = '\0';
+}
+

to basically:

	memcpy(dst, src, _len);
	dst[_len - 1] = '\0';

Where it already figured out _len at build time. Adding a single write of
the nul byte without any branches would likely be a couple of cycles at
max. It's all hot cache (from the memcpy) and writing a immediate.

I'm not worried that one line will cause any measurable overhead to the
tracing.

-- Steve

  reply	other threads:[~2026-10-31 14:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 21:38 [PATCH v8 0/6] sched: Add support for long task name André Almeida
2026-10-30 21:38 ` [PATCH v8 1/6] treewide: Get rid of get_task_comm() André Almeida
2026-10-30 21:38 ` [PATCH v8 2/6] treewide: Replace memcpy(..., current->comm) with copy_task_comm() André Almeida
2026-10-30 22:34   ` David Laight
2026-10-31 14:30     ` Steven Rostedt [this message]
2026-10-30 21:38 ` [PATCH v8 3/6] lib/string_kunit: Add test for copy_task_comm() André Almeida
2026-10-30 21:38 ` [PATCH v8 4/6] sched: Extend task command name with TASK_COMM_EXT_LEN André Almeida
2026-10-30 21:38 ` [PATCH v8 5/6] prctl: Add support for long user thread names André Almeida
2026-10-30 21:38 ` [PATCH v8 6/6] selftests: prctl: Add test for long " André Almeida

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261031103008.6849760c@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=andrealmeid@igalia.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=arnaldo.melo@gmail.com \
    --cc=brauner@kernel.org \
    --cc=david.laight.linux@gmail.com \
    --cc=juri.lelli@redhat.com \
    --cc=kees@kernel.org \
    --cc=kernel-dev@igalia.com \
    --cc=laoar.shao@gmail.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=shuah@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=vincent.guittot@linaro.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox