51 lines
1.4 KiB
Diff
51 lines
1.4 KiB
Diff
|
From d54c730eba63dfe0dcb8c7ab41514c564c159212 Mon Sep 17 00:00:00 2001
|
||
|
From: Jiri Slaby <jirislaby@gmail.com>
|
||
|
Date: Fri, 28 Aug 2009 14:08:17 +0200
|
||
|
Subject: [PATCH] core: optimize setrlimit for current task
|
||
|
References: FATE#305733
|
||
|
Patch-mainline: no (later)
|
||
|
|
||
|
Don't take tasklist lock for 'current'. It's not needed, since
|
||
|
current->sighand/signal can't disappear.
|
||
|
|
||
|
This improves serlimit called especially via sys_setrlimit.
|
||
|
|
||
|
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
|
||
|
Cc: Oleg Nesterov <oleg@redhat.com>
|
||
|
---
|
||
|
kernel/sys.c | 16 ++++++++++------
|
||
|
1 file changed, 10 insertions(+), 6 deletions(-)
|
||
|
|
||
|
--- a/kernel/sys.c
|
||
|
+++ b/kernel/sys.c
|
||
|
@@ -1316,11 +1316,14 @@ int do_setrlimit(struct task_struct *tsk
|
||
|
if (resource == RLIMIT_NOFILE && new_rlim->rlim_max > sysctl_nr_open)
|
||
|
return -EPERM;
|
||
|
|
||
|
- /* protect tsk->signal and tsk->sighand from disappearing */
|
||
|
- read_lock(&tasklist_lock);
|
||
|
- if (!tsk->sighand) {
|
||
|
- retval = -ESRCH;
|
||
|
- goto out;
|
||
|
+ /* optimization: 'current' doesn't need locking, e.g. setrlimit */
|
||
|
+ if (tsk != current) {
|
||
|
+ /* protect tsk->signal and tsk->sighand from disappearing */
|
||
|
+ read_lock(&tasklist_lock);
|
||
|
+ if (!tsk->sighand) {
|
||
|
+ retval = -ESRCH;
|
||
|
+ goto out;
|
||
|
+ }
|
||
|
}
|
||
|
|
||
|
retval = security_task_setrlimit(tsk, resource, new_rlim);
|
||
|
@@ -1360,7 +1363,8 @@ int do_setrlimit(struct task_struct *tsk
|
||
|
|
||
|
update_rlimit_cpu(tsk, new_rlim->rlim_cur);
|
||
|
out:
|
||
|
- read_unlock(&tasklist_lock);
|
||
|
+ if (tsk != current)
|
||
|
+ read_unlock(&tasklist_lock);
|
||
|
return retval;
|
||
|
}
|
||
|
|