LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Yafang Shao <laoar.shao@gmail.com>
To: Kees Cook <keescook@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Petr Mladek <pmladek@suse.com>,
	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 4/5] kernel: increase the size of kthread's comm
Date: Thu, 30 Sep 2021 20:53:27 +0800	[thread overview]
Message-ID: <CALOAHbD3HUqUnjMYKX7NGwVWiS4K7OvS6uPNWucnOA5Cy3pn9w@mail.gmail.com> (raw)
In-Reply-To: <202109291113.6DE8D6F3D@keescook>

On Thu, Sep 30, 2021 at 2:20 AM Kees Cook <keescook@chromium.org> wrote:
>
> On Wed, Sep 29, 2021 at 11:50:35AM +0000, Yafang Shao wrote:
> > This patch increases the size of ktread's comm from 16 to 24, which is
> > the same with workqueue's, to improve this situation. After this cahnge,
> > [...]
> > Because there're only a few of kthreads, so it won't increase too much
> > memory.
>
> Even without the performance impact changes, the math here doesn't hold
> either, since using kmalloc means there are slabs being allocated to hold
> the task "comm"s now (which comes with overhead), and every task added
> a pointer to those 16 bytes (i.e. 8 more bytes on 64-bit systems). So
> this change, even if there was 0 overhead in using slabs, would be
> identical to having just raised TASK_COMM_LEN to 24. 8 byte pointer,
> 16 byte allocation == 24 bytes.
>

Right, thanks for the explanation. I missed the pointer before.

What about reusing the kthread_data() to store the the comm if the
kthread is not a kworker?

struct kthread {
     ...
     void *data;  // reuse this pointer
     ...
}

The logic will be something as follows,

    if (kthread_is_kworker) {
          store_worker_desc_into_kthread_data(); // already did in the kernel
     } else {
          store_comm_into_kthread_data();   // that is what we should change
    }

And then we modify the  proc_task_name() correspondingly.

-- 
Thanks
Yafang

  reply	other threads:[~2021-09-30 12:54 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29 11:50 [PATCH 0/5] kthread: " 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
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 [this message]
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=CALOAHbD3HUqUnjMYKX7NGwVWiS4K7OvS6uPNWucnOA5Cy3pn9w@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 4/5] kernel: increase the size of kthread'\''s comm' \
    /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).