From: Ingo Molnar <mingo@elte.hu>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Oleg Nesterov <oleg@tv-sign.ru>, Robin Holt <holt@sgi.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Chris Snook <csnook@redhat.com>,
linux-kernel@vger.kernel.org,
Jack Steiner <steiner@americas.sgi.com>
Subject: [patch] uninline remove/add_parent() APIs
Date: Wed, 11 Apr 2007 08:20:41 +0200 [thread overview]
Message-ID: <20070411062041.GA8017@elte.hu> (raw)
In-Reply-To: <20070410155314.GA16267@elte.hu>
here's a (tested) patch i did that should simplify changes done to
p->children and p->sibling handling.
Ingo
---------------------->
Subject: [patch] uninline remove/add_parent() APIs
From: Ingo Molnar <mingo@elte.hu>
uninline/simplify remove/add_parent() APIs.
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
include/linux/sched.h | 5 +++--
kernel/exit.c | 31 +++++++++++++++++++++----------
kernel/fork.c | 2 +-
kernel/ptrace.c | 11 ++++-------
4 files changed, 29 insertions(+), 20 deletions(-)
Index: linux/include/linux/sched.h
===================================================================
--- linux.orig/include/linux/sched.h
+++ linux/include/linux/sched.h
@@ -1418,8 +1418,9 @@ extern void wait_task_inactive(struct ta
#define wait_task_inactive(p) do { } while (0)
#endif
-#define remove_parent(p) list_del_init(&(p)->sibling)
-#define add_parent(p) list_add_tail(&(p)->sibling,&(p)->parent->children)
+extern void
+task_relink_parent(struct task_struct *p, struct task_struct *new_real_parent,
+ struct task_struct *new_parent);
#define next_task(p) list_entry(rcu_dereference((p)->tasks.next), struct task_struct, tasks)
Index: linux/kernel/exit.c
===================================================================
--- linux.orig/kernel/exit.c
+++ linux/kernel/exit.c
@@ -52,6 +52,20 @@ extern void sem_exit (void);
static void exit_mm(struct task_struct * tsk);
+void
+task_relink_parent(struct task_struct *p,
+ struct task_struct *new_real_parent,
+ struct task_struct *new_parent)
+{
+ /*
+ * Move this task to a new parent's children list.
+ * (if p->parent == new->parent this this requeues from head to tail)
+ */
+ list_move_tail(&p->sibling, &new_parent->children);
+ p->real_parent = new_real_parent;
+ p->parent = new_parent;
+}
+
static void __unhash_process(struct task_struct *p)
{
nr_threads--;
@@ -64,7 +78,7 @@ static void __unhash_process(struct task
__get_cpu_var(process_counts)--;
}
list_del_rcu(&p->thread_group);
- remove_parent(p);
+ list_del_init(&p->sibling);
}
/*
@@ -268,14 +282,14 @@ static int has_stopped_jobs(struct pid *
*/
static void reparent_to_init(void)
{
+ struct task_struct *reaper;
+
write_lock_irq(&tasklist_lock);
ptrace_unlink(current);
/* Reparent to init */
- remove_parent(current);
- current->parent = child_reaper(current);
- current->real_parent = child_reaper(current);
- add_parent(current);
+ reaper = child_reaper(current);
+ task_relink_parent(current, reaper, reaper);
/* Set the exit signal to SIGCHLD so we signal init on exit */
current->exit_signal = SIGCHLD;
@@ -611,9 +625,7 @@ reparent_thread(struct task_struct *p, s
* anyway, so let go of it.
*/
p->ptrace = 0;
- remove_parent(p);
- p->parent = p->real_parent;
- add_parent(p);
+ task_relink_parent(p, p->real_parent, p->real_parent);
if (p->state == TASK_TRACED) {
/*
@@ -1344,8 +1356,7 @@ bail_ref:
}
/* move to end of parent's list to avoid starvation */
- remove_parent(p);
- add_parent(p);
+ task_relink_parent(p, p->real_parent, p->parent);
write_unlock_irq(&tasklist_lock);
Index: linux/kernel/fork.c
===================================================================
--- linux.orig/kernel/fork.c
+++ linux/kernel/fork.c
@@ -1242,7 +1242,7 @@ static struct task_struct *copy_process(
}
if (likely(p->pid)) {
- add_parent(p);
+ list_add_tail(&p->sibling, &p->parent->children);
if (unlikely(p->ptrace & PT_PTRACED))
__ptrace_link(p, current->parent);
Index: linux/kernel/ptrace.c
===================================================================
--- linux.orig/kernel/ptrace.c
+++ linux/kernel/ptrace.c
@@ -34,11 +34,9 @@ void __ptrace_link(struct task_struct *c
if (child->parent == new_parent)
return;
list_add(&child->ptrace_list, &child->parent->ptrace_children);
- remove_parent(child);
- child->parent = new_parent;
- add_parent(child);
+ task_relink_parent(child, new_parent, child->real_parent);
}
-
+
/*
* Turn a tracing stop into a normal stop now, since with no tracer there
* would be no way to wake it up with SIGCONT or SIGKILL. If there was a
@@ -72,9 +70,8 @@ void __ptrace_unlink(struct task_struct
child->ptrace = 0;
if (!list_empty(&child->ptrace_list)) {
list_del_init(&child->ptrace_list);
- remove_parent(child);
- child->parent = child->real_parent;
- add_parent(child);
+ task_relink_parent(child, child->real_parent,
+ child->real_parent);
}
if (child->state == TASK_TRACED)
next prev parent reply other threads:[~2007-04-11 6:20 UTC|newest]
Thread overview: 89+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-05 19:51 init's children list is long and slows reaping children Robin Holt
2007-04-05 20:57 ` Linus Torvalds
2007-04-06 0:51 ` Chris Snook
2007-04-06 1:03 ` Chris Snook
2007-04-06 1:29 ` Linus Torvalds
2007-04-06 2:15 ` Eric W. Biederman
2007-04-06 10:43 ` Robin Holt
2007-04-06 15:38 ` Eric W. Biederman
2007-04-06 16:31 ` Oleg Nesterov
2007-04-06 17:32 ` Ingo Molnar
2007-04-06 17:39 ` Roland Dreier
2007-04-06 18:04 ` Eric W. Biederman
2007-04-06 18:30 ` Eric W. Biederman
2007-04-06 19:18 ` [patch] sched: get rid of p->children use in show_task() Ingo Molnar
2007-04-06 19:22 ` Ingo Molnar
2007-04-10 13:48 ` init's children list is long and slows reaping children Ingo Molnar
2007-04-10 13:38 ` Oleg Nesterov
2007-04-10 15:00 ` Eric W. Biederman
2007-04-10 15:16 ` [PATCH] Only send pdeath_signal when getppid changes Eric W. Biederman
2007-04-10 16:37 ` Oleg Nesterov
2007-04-10 17:41 ` Eric W. Biederman
2007-04-10 17:48 ` Roland McGrath
2007-04-11 3:17 ` Albert Cahalan
2007-04-10 14:51 ` init's children list is long and slows reaping children Eric W. Biederman
2007-04-10 15:06 ` Ingo Molnar
2007-04-10 15:22 ` Eric W. Biederman
2007-04-10 15:53 ` Ingo Molnar
2007-04-10 16:17 ` Eric W. Biederman
2007-04-11 6:20 ` Ingo Molnar [this message]
2007-04-11 7:00 ` [patch] uninline remove/add_parent() APIs Eric W. Biederman
2007-04-11 22:06 ` Andrew Morton
2007-04-12 10:45 ` Eric W. Biederman
2007-04-12 22:50 ` Roland McGrath
2007-04-10 16:44 ` init's children list is long and slows reaping children Oleg Nesterov
2007-04-11 19:55 ` Bill Davidsen
2007-04-11 20:17 ` Eric W. Biederman
2007-04-11 21:24 ` Bill Davidsen
2007-04-11 20:19 ` Oleg Nesterov
2007-04-06 18:02 ` Eric W. Biederman
2007-04-06 18:21 ` Davide Libenzi
2007-04-06 18:56 ` Eric W. Biederman
2007-04-06 19:16 ` Davide Libenzi
2007-04-06 19:19 ` Ingo Molnar
2007-04-06 21:29 ` Davide Libenzi
2007-04-06 21:51 ` Linus Torvalds
2007-04-06 22:31 ` Davide Libenzi
2007-04-06 22:46 ` Linus Torvalds
2007-04-06 22:59 ` Davide Libenzi
2007-04-09 8:28 ` Ingo Molnar
2007-04-09 18:09 ` Bill Davidsen
2007-04-09 19:28 ` Kyle Moffett
2007-04-09 19:51 ` Linus Torvalds
2007-04-09 20:03 ` Davide Libenzi
2007-04-10 15:12 ` Bill Davidsen
2007-04-10 19:17 ` Davide Libenzi
2007-04-09 20:00 ` Eric W. Biederman
2007-04-06 16:41 ` Robin Holt
2007-04-09 17:37 ` Chris Snook
2007-04-06 18:05 ` Christoph Hellwig
2007-04-06 19:39 ` Eric W. Biederman
2007-04-06 22:38 ` Jeff Garzik
2007-04-06 22:51 ` Linus Torvalds
2007-04-06 23:37 ` Jeff Garzik
2007-04-11 7:28 ` Nick Piggin
2007-04-10 0:23 ` Andrew Morton
2007-04-10 0:48 ` Eric W. Biederman
2007-04-10 1:15 ` Andrew Morton
2007-04-10 6:53 ` Jeff Garzik
2007-04-10 9:42 ` Robin Holt
2007-04-10 1:59 ` Dave Jones
2007-04-10 2:30 ` Andrew Morton
2007-04-10 2:46 ` Linus Torvalds
2007-04-10 7:07 ` Jeff Garzik
2007-04-10 22:20 ` Ingo Oeser
2007-04-10 5:07 ` Alexey Dobriyan
2007-04-10 5:21 ` Dave Jones
2007-04-10 6:09 ` Torsten Kaiser
2007-04-10 7:08 ` Jeff Garzik
2007-04-10 7:05 ` Jeff Garzik
2007-04-10 7:37 ` Andrew Morton
2007-04-10 8:33 ` Jeff Garzik
2007-04-10 8:41 ` Andrew Morton
2007-04-10 8:48 ` Jeff Garzik
2007-04-10 22:35 ` Ingo Oeser
2007-04-10 16:35 ` Matt Mackall
2007-04-10 7:44 ` Russell King
2007-04-10 8:16 ` Jeff Garzik
2007-04-10 8:59 ` Ingo Molnar
2007-04-10 9:33 ` Jeff Garzik
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=20070411062041.GA8017@elte.hu \
--to=mingo@elte.hu \
--cc=csnook@redhat.com \
--cc=ebiederm@xmission.com \
--cc=holt@sgi.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@tv-sign.ru \
--cc=steiner@americas.sgi.com \
--cc=torvalds@linux-foundation.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox