LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Yafang Shao <laoar.shao@gmail.com>
To: Petr Mladek <pmladek@suse.com>
Cc: Kees Cook <keescook@chromium.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Valentin Schneider <valentin.schneider@arm.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	qiang.zhang@windriver.com, robdclark@chromium.org,
	Al Viro <viro@zeniv.linux.org.uk>,
	christian@brauner.io, Dietmar Eggemann <dietmar.eggemann@arm.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/5] kernel/fork: allocate task->comm dynamicly
Date: Fri, 1 Oct 2021 19:58:24 +0800	[thread overview]
Message-ID: <CALOAHbA0t6XTvTX2b=1JZY-QBx-Ji9A6r05-y07T0e962iHdNw@mail.gmail.com> (raw)
In-Reply-To: <YVXO/hsDJQh1FOgy@alley>

On Thu, Sep 30, 2021 at 10:51 PM Petr Mladek <pmladek@suse.com> wrote:
>
> On Thu 2021-09-30 20:41:40, Yafang Shao wrote:
> > On Thu, Sep 30, 2021 at 2:11 AM Kees Cook <keescook@chromium.org> wrote:
> > >
> > > On Wed, Sep 29, 2021 at 11:50:33AM +0000, Yafang Shao wrote:
> > > > task->comm is defined as an array embedded in struct task_struct before.
> > > > This patch changes it to a char pointer. It will be allocated in the fork
> > > > and freed when the task is freed.
> > > >
> > > > Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> > > > ---
> > > >  include/linux/sched.h |  2 +-
> > > >  kernel/fork.c         | 19 +++++++++++++++++++
> > > >  2 files changed, 20 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/include/linux/sched.h b/include/linux/sched.h
> > > > index e12b524426b0..b387b5943db4 100644
> > > > --- a/include/linux/sched.h
> > > > +++ b/include/linux/sched.h
> > > > @@ -1051,7 +1051,7 @@ struct task_struct {
> > > >        * - access it with [gs]et_task_comm()
> > > >        * - lock it with task_lock()
> > > >        */
> > > > -     char                            comm[TASK_COMM_LEN];
> > > > +     char                            *comm;
> > >
> > > This, I think, is basically a non-starter. It adds another kmalloc to
> > > the fork path without a well-justified reason. TASK_COMM_LEN is small,
> > > yes, but why is growing it valuable enough to slow things down?
> > >
> > > (Or, can you prove that this does NOT slow things down? It seems like
> > > it would.)
> > >
> >
> > Right, the new kmalloc would take some extra latency.
> > Seems it is not easy to measure which one is more valuable.
>
> Honestly, I do not think that this exercise is worth it. The patchset
> adds a lot of complexity and potential problems just to extend
> comm from 16 to 24 for kthreads.
>
> Is the problem real or just cosmetic?
>

It is a problem, but not a critical problem.

Take the "cfs_migration/%u" for example.
It will be truncated to "cfs_migration/1" for CPU 10~19, which will
make the user confused.  But as it is a per-cpu thread, the user can
get its CPU information from its cpu mask.  And we can also shorten
its name to work around this issue.

But for kthreads corresponding to some other hardware devices, it may
not be easy to get the detailed information from the task's comm. For
example,
    jbd2/nvme0n1p2-
    nvidia-modeset/


> If you really want it then it would be much easier to increase
> TASK_COMM_LEN. task_struct is growing rather regularly. Extra
> 8 bytes should be acceptable.
>
> If you want to make it more acceptable then keep 16 for
> CONFIG_BASE_SMALL.
>

That seems to be a possible solution.

>
> > > > diff --git a/kernel/fork.c b/kernel/fork.c
> > > > index 38681ad44c76..227aec240501 100644
> > > > --- a/kernel/fork.c
> > > > +++ b/kernel/fork.c
> > > > @@ -753,6 +767,7 @@ void __put_task_struct(struct task_struct *tsk)
> > > >       bpf_task_storage_free(tsk);
> > > >       exit_creds(tsk);
> > > >       delayacct_tsk_free(tsk);
> > > > +     task_comm_free(tsk);
>
> Just one example of the potential problems. Are you sure that nobody
> will access tsk->comm after this point?
>

That is a risk.
Should free it in free_task(), just before free_task_struct().

> task->comm is widely used to describe the affected task_struct because
> it is user friendly.
>
> Also __put_task_struct() later calls also profile_handoff_task() that might
> get registered even by some external module.
>
> Best Regards,
> Petr
>
> PS: I think that the fork performance is important. It is tested by
> benchmarks, for example, lmbench. But for me, the reliability is even
> more important and any pointer/alloc/free just adds another weak
> point.

Many thanks for the explanation.

-- 
Thanks
Yafang

  reply	other threads:[~2021-10-01 11:59 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29 11:50 [PATCH 0/5] kthread: increase the size of kthread's comm Yafang Shao
2021-09-29 11:50 ` [PATCH 1/5] kernel: replace sizeof(task->comm) with TASK_COMM_LEN Yafang Shao
2021-09-29 18:09   ` Kees Cook
2021-09-30 12:27     ` Yafang Shao
2021-10-03  3:31   ` Al Viro
2021-10-03 14:14     ` Yafang Shao
2021-09-29 11:50 ` [PATCH 2/5] kernel/fork: allocate task->comm dynamicly Yafang Shao
2021-09-29 13:08   ` Yafang Shao
2021-09-29 18:11   ` Kees Cook
2021-09-30 12:41     ` Yafang Shao
2021-09-30 14:51       ` Petr Mladek
2021-10-01 11:58         ` Yafang Shao [this message]
2021-09-29 11:50 ` [PATCH 3/5] kernel/sched: improve the BUILD_BUG_ON() in get_task_comm() Yafang Shao
2021-09-29 18:12   ` Kees Cook
2021-09-30 12:43     ` Yafang Shao
2021-09-29 11:50 ` [PATCH 4/5] kernel: increase the size of kthread's comm Yafang Shao
2021-09-29 18:19   ` Kees Cook
2021-09-30 12:53     ` Yafang Shao
2021-09-29 11:50 ` [PATCH 5/5] kernel/kthread: show a warning if kthread's comm is still trucated Yafang Shao
2021-09-29 18:20   ` Kees Cook
2021-09-30 12:54     ` Yafang Shao
2021-09-30 15:17   ` Petr Mladek
2021-10-01 11:59     ` Yafang Shao
2021-10-03  3:41 ` [PATCH 0/5] kthread: increase the size of kthread's comm Al Viro
2021-10-03 14:20   ` Yafang Shao

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='CALOAHbA0t6XTvTX2b=1JZY-QBx-Ji9A6r05-y07T0e962iHdNw@mail.gmail.com' \
    --to=laoar.shao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=christian@brauner.io \
    --cc=dietmar.eggemann@arm.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=qiang.zhang@windriver.com \
    --cc=robdclark@chromium.org \
    --cc=valentin.schneider@arm.com \
    --cc=viro@zeniv.linux.org.uk \
    --subject='Re: [PATCH 2/5] kernel/fork: allocate task->comm dynamicly' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).