Re: [PATCH v2 3/6] treewide: Replace memcpy(..., current->comm) with strscpy()

From: André Almeida

Date: Fri May 29 2026 - 12:53:48 EST


Em 27/05/2026 06:18, David Laight escreveu:
On Tue, 26 May 2026 19:06:25 -0400
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:

On Sun, 24 May 2026 19:38:53 -0300
André Almeida <andrealmeid@xxxxxxxxxx> wrote:

In order to increase the size of current->comm[] and to avoid breaking any
existing code, replace memcpy() with strscpy(). The later function makes
sure that the copy is NUL terminated. This is crucial given that the
source buffer might be larger than the destination buffer and could
truncate the NUL character out of it.
...
As tracing now slows it down by 3.9% which is a significant increase from 2.7%

I really rather keep memcpy() here.

Thanks Steve for taking the time for benchmarking this!


I suspect the copies could/should be replaced by a copy_task_comm()
function that can perform optimisations that strscpy[_pad]() can't
do because it can (for example) assume that the source is terminated.

When the src and dst are the same size it can also degenerate to
memcpy() - which should get inlined.
The cost of copying 64 bytes might still be rather more than copying
just 16.
A compromise of 32 may be better.

Ok, I will work on something like this for the v3.