[PATCH] coredump: optimize ->mm users traversal
zap_threads() iterates over all threads to find those ones which share current->mm. All threads in the thread group share the same ->mm, so we can skip entire thread group if it has another ->mm. This patch shifts the killing of thread group into the newly added zap_process() function. This looks as unnecessary complication, but it is used in further patches. Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Acked-by: Roland McGrath <roland@redhat.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
parent
2ceb8693ef
commit
aceecc0412
1 changed files with 26 additions and 10 deletions
36
fs/exec.c
36
fs/exec.c
|
@ -1368,6 +1368,22 @@ static void format_corename(char *corename, const char *pattern, long signr)
|
||||||
*out_ptr = 0;
|
*out_ptr = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void zap_process(struct task_struct *start, int *ptraced)
|
||||||
|
{
|
||||||
|
struct task_struct *t;
|
||||||
|
|
||||||
|
t = start;
|
||||||
|
do {
|
||||||
|
if (t != current && t->mm) {
|
||||||
|
t->mm->core_waiters++;
|
||||||
|
force_sig_specific(SIGKILL, t);
|
||||||
|
if (unlikely(t->ptrace) &&
|
||||||
|
unlikely(t->parent->mm == t->mm))
|
||||||
|
*ptraced = 1;
|
||||||
|
}
|
||||||
|
} while ((t = next_thread(t)) != start);
|
||||||
|
}
|
||||||
|
|
||||||
static void zap_threads (struct mm_struct *mm)
|
static void zap_threads (struct mm_struct *mm)
|
||||||
{
|
{
|
||||||
struct task_struct *g, *p;
|
struct task_struct *g, *p;
|
||||||
|
@ -1385,16 +1401,16 @@ static void zap_threads (struct mm_struct *mm)
|
||||||
}
|
}
|
||||||
|
|
||||||
read_lock(&tasklist_lock);
|
read_lock(&tasklist_lock);
|
||||||
do_each_thread(g,p)
|
for_each_process(g) {
|
||||||
if (mm == p->mm && p != tsk) {
|
p = g;
|
||||||
force_sig_specific(SIGKILL, p);
|
do {
|
||||||
mm->core_waiters++;
|
if (p->mm) {
|
||||||
if (unlikely(p->ptrace) &&
|
if (p->mm == mm)
|
||||||
unlikely(p->parent->mm == mm))
|
zap_process(p, &traced);
|
||||||
traced = 1;
|
break;
|
||||||
}
|
}
|
||||||
while_each_thread(g,p);
|
} while ((p = next_thread(p)) != g);
|
||||||
|
}
|
||||||
read_unlock(&tasklist_lock);
|
read_unlock(&tasklist_lock);
|
||||||
|
|
||||||
if (unlikely(traced)) {
|
if (unlikely(traced)) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue