All of lore.kernel.org
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: Barret Rhoden <brho@google.com>
Cc: Christian Brauner <christian.brauner@ubuntu.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Alexey Gladkov <legion@kernel.org>,
	William Cohen <wcohen@redhat.com>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Chris Hyser <chris.hyser@oracle.com>,
	Peter Collingbourne <pcc@google.com>,
	Xiaofeng Cao <caoxiaofeng@yulong.com>,
	David Hildenbrand <david@redhat.com>,
	Cyrill Gorcunov <gorcunov@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rlimits: do not grab tasklist_lock for do_prlimit on current
Date: Mon, 13 Dec 2021 16:34:04 -0600	[thread overview]
Message-ID: <8735mww2w3.fsf@email.froward.int.ebiederm.org> (raw)
In-Reply-To: <20211213220401.1039578-1-brho@google.com> (Barret Rhoden's message of "Mon, 13 Dec 2021 17:04:01 -0500")

Barret Rhoden <brho@google.com> writes:

> The tasklist_lock can be a scalability bottleneck.  For current tasks,
> we don't need the tasklist_lock to protect tsk->sighand or tsk->signal.
> If non-current callers become a bottleneck, we could use
> lock_task_sighand().

Do you have any numbers?  As the entire point of this change is
performance it would be good to see how the performance changes.

Especially as a read_lock should not be too bad as it allows sharing,
nor do I expect reading or writing the rlimit values to be particularly
frequent.  So some insight into what kinds of userspace patterns make
this a problem would be nice.

This change is a bit scary as it makes taking a lock conditional and
increases the probability of causing a locking mistake.

If you are going to make this change I would say that do_prlimit should
become static and taking the tasklist_lock should move into prlimit64.


Looking a little closer it looks like that update_rlimit_cpu should use
lock_task_sighand, and once lock_task_sighand is used there is actually
no need for the tasklist_lock at all.  As holding the reference to tsk
guarantees that tsk->signal remains valid.

So I completely agree there are cleanups that can happen in this area.
Please make those and show numbers in how they improve things, instead
of making the code worse with a conditional lock.

Eric


> Signed-off-by: Barret Rhoden <brho@google.com>
> ---
>  kernel/sys.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/sys.c b/kernel/sys.c
> index 8fdac0d90504..e56d1ae910af 100644
> --- a/kernel/sys.c
> +++ b/kernel/sys.c
> @@ -1576,7 +1576,8 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
>  	}
>  
>  	/* protect tsk->signal and tsk->sighand from disappearing */
> -	read_lock(&tasklist_lock);
> +	if (tsk != current)
> +		read_lock(&tasklist_lock);
>  	if (!tsk->sighand) {
>  		retval = -ESRCH;
>  		goto out;
> @@ -1611,7 +1612,8 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
>  	     IS_ENABLED(CONFIG_POSIX_TIMERS))
>  		update_rlimit_cpu(tsk, new_rlim->rlim_cur);
>  out:
> -	read_unlock(&tasklist_lock);
> +	if (tsk != current)
> +		read_unlock(&tasklist_lock);
>  	return retval;
>  }

  reply	other threads:[~2021-12-13 22:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-13 22:04 [PATCH] rlimits: do not grab tasklist_lock for do_prlimit on current Barret Rhoden
2021-12-13 22:34 ` Eric W. Biederman [this message]
2021-12-15 19:00   ` Barret Rhoden
2021-12-15 19:42     ` Eric W. Biederman
2021-12-19 21:30       ` Cyrill Gorcunov
2022-01-05 21:31       ` Barret Rhoden
  -- strict thread matches above, loose matches on Subject: below --
2021-12-16 20:34 kernel test robot

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=8735mww2w3.fsf@email.froward.int.ebiederm.org \
    --to=ebiederm@xmission.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=brho@google.com \
    --cc=caoxiaofeng@yulong.com \
    --cc=chris.hyser@oracle.com \
    --cc=christian.brauner@ubuntu.com \
    --cc=david@redhat.com \
    --cc=gorcunov@gmail.com \
    --cc=legion@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pcc@google.com \
    --cc=viresh.kumar@linaro.org \
    --cc=wcohen@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.