public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rlimits: do not grab tasklist_lock for do_prlimit on current
@ 2021-12-13 22:04 Barret Rhoden
  2021-12-13 22:34 ` Eric W. Biederman
  0 siblings, 1 reply; 6+ messages in thread
From: Barret Rhoden @ 2021-12-13 22:04 UTC (permalink / raw)
  To: Eric W. Biederman, Christian Brauner, Andrew Morton,
	Alexey Gladkov, William Cohen, Viresh Kumar, Alexey Dobriyan,
	Chris Hyser, Peter Collingbourne, Xiaofeng Cao, David Hildenbrand,
	Cyrill Gorcunov, linux-kernel

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().

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;
 }
 
-- 
2.34.1.173.g76aa8bc2d0-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-01-05 21:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox