Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C33CC433EF for ; Mon, 13 Dec 2021 22:34:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243707AbhLMWew (ORCPT ); Mon, 13 Dec 2021 17:34:52 -0500 Received: from out01.mta.xmission.com ([166.70.13.231]:38562 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240469AbhLMWed (ORCPT ); Mon, 13 Dec 2021 17:34:33 -0500 Received: from in02.mta.xmission.com ([166.70.13.52]:45134) by out01.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1mwttw-007zvI-4D; Mon, 13 Dec 2021 15:34:32 -0700 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95]:59454 helo=email.froward.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1mwttv-00CWgI-0z; Mon, 13 Dec 2021 15:34:31 -0700 From: ebiederm@xmission.com (Eric W. Biederman) To: Barret Rhoden Cc: Christian Brauner , Andrew Morton , Alexey Gladkov , William Cohen , Viresh Kumar , Alexey Dobriyan , Chris Hyser , Peter Collingbourne , Xiaofeng Cao , David Hildenbrand , Cyrill Gorcunov , linux-kernel@vger.kernel.org References: <20211213220401.1039578-1-brho@google.com> Date: Mon, 13 Dec 2021 16:34:04 -0600 In-Reply-To: <20211213220401.1039578-1-brho@google.com> (Barret Rhoden's message of "Mon, 13 Dec 2021 17:04:01 -0500") Message-ID: <8735mww2w3.fsf@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1mwttv-00CWgI-0z;;;mid=<8735mww2w3.fsf@email.froward.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX19ilNAxJXurZ5jl8Voq6UpIBODNwxZ0rS0= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH] rlimits: do not grab tasklist_lock for do_prlimit on current X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Barret Rhoden 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 > --- > 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; > }