[PATCH v2 0/3] Dynamically allocate memory to store task's full name

Bhupesh
2025-03-31T12:18:45Z

Changes since v1:
================
- v1 can be seen here: https://lore.kernel.org/lkml/20250314052715.610377-1-bhupesh@igalia.com/
- As suggested by Kees, added [PATCH 3/3] to have a consistent
'full_name' entry inside 'task_struct' which both tasks and
kthreads can use.
- Fixed the commit message to indicate that the existing ABI
'/proc/$pid/task/$tid/comm' remains untouched and a parallel
'/proc/$pid/task/$tid/full_name' ABI for new (interested) users.

While working with user-space debugging tools which work especially
on linux gaming platforms, I found that the task name is truncated due
to the limitation of TASK_COMM_LEN.

Now, during debug tracing, seeing truncated names is not very useful,
especially on gaming platforms where the number of tasks running can
be very high.

This patch does not touch 'TASK_COMM_LEN' at all, i.e.
'TASK_COMM_LEN' and the 16-byte design remains untouched. Which means
that all the legacy / existing ABI, continue to work as before using
'/proc/$pid/task/$tid/comm'.

This patch only adds a parallel, dynamically-allocated
'task->full_name' which can be used by interested users
via '/proc/$pid/task/$tid/full_name'.

After this change, gdb is able to show full name of the task, using a
simple app which generates threads with long names [see 1]:
# gdb ./threadnames -ex "run info thread" -ex "detach" -ex "quit" > log
# cat log

NameThatIsTooLongForComm[4662]

[1]. https://github.com/lostgoat/tasknames

Bhupesh (3):
exec: Dynamically allocate memory to store task's full name
fs/proc: Pass 'task->full_name' via 'proc_task_name()'
kthread: Use 'task_struct->full_name' to store kthread's full name

fs/exec.c | 21 ++++++++++++++++++---
fs/proc/array.c | 2 +-
include/linux/sched.h | 9 +++++++++
kernel/kthread.c | 9 +++------
4 files changed, 31 insertions(+), 10 deletions(-)

--
2.38.1