From: Dipankar Sarma <dipankar@in.ibm.com>
To: Christoph Hellwig <hch@infradead.org>,
"Paul E. McKenney" <paulmck@us.ibm.com>,
linux-kernel@vger.kernel.org, mingo@elte.hu, rusty@au1.ibm.com,
bmark@us.ibm.com
Subject: Re: [RFC,PATCH] Use RCU to protect tasklist for unicast signals
Date: Thu, 11 Aug 2005 23:42:35 +0530 [thread overview]
Message-ID: <20050811181235.GE4546@in.ibm.com> (raw)
In-Reply-To: <20050811180044.GD4546@in.ibm.com>
On Thu, Aug 11, 2005 at 11:30:44PM +0530, Dipankar Sarma wrote:
> When I worked on this last (a year or so ago), it seemed that I would
> need to put a number of additional structures under RCU control.
> It would be better to gradually move it towards RCU rather than
> trying make all the readers lock-free.
Just for reference, this was my tasks-rcu patch. 2.6.0-test2, no less :)
I was interested in get_pid_list() at that time. IIRC, I tested it with
lots of top running along with other tests.
Thanks
Dipankar
Incremental patch to do lockfree traversal of the task list using
RCU. For now it just does one of the costlies ones in /proc.
Signed-off-by: Dipankar Sarma <dipankar@in.ibm.com>
fs/exec.c | 1 +
fs/proc/base.c | 5 +++--
include/linux/sched.h | 21 ++++++++++++++++-----
3 files changed, 20 insertions(+), 7 deletions(-)
diff -puN fs/exec.c~tasks-rcu fs/exec.c
--- linux-2.6.0-test2-ds/fs/exec.c~tasks-rcu 2003-08-04 21:48:38.000000000 +0530
+++ linux-2.6.0-test2-ds-dipankar/fs/exec.c 2003-08-04 21:49:26.000000000 +0530
@@ -676,6 +676,7 @@ static inline int de_thread(struct task_
list_del(¤t->tasks);
list_add_tail(¤t->tasks, &init_task.tasks);
+ list_add_tail_rcu(¤t->tasks, &init_task.tasks);
current->exit_signal = SIGCHLD;
state = leader->state;
diff -puN fs/proc/base.c~tasks-rcu fs/proc/base.c
--- linux-2.6.0-test2-ds/fs/proc/base.c~tasks-rcu 2003-08-04 21:48:38.000000000 +0530
+++ linux-2.6.0-test2-ds-dipankar/fs/proc/base.c 2003-08-04 21:49:59.000000000 +0530
@@ -32,6 +32,7 @@
#include <linux/mount.h>
#include <linux/security.h>
#include <linux/ptrace.h>
+#include <linux/rcupdate.h>
/*
* For hysterical raisins we keep the same inumbers as in the old procfs.
@@ -1403,7 +1404,7 @@ static int get_pid_list(int index, unsig
int nr_pids = 0;
index--;
- read_lock(&tasklist_lock);
+ rcu_read_lock();
for_each_process(p) {
int pid = p->pid;
if (!pid_alive(p))
@@ -1415,7 +1416,7 @@ static int get_pid_list(int index, unsig
if (nr_pids >= PROC_MAXPIDS)
break;
}
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
return nr_pids;
}
diff -puN include/linux/sched.h~tasks-rcu include/linux/sched.h
--- linux-2.6.0-test2-ds/include/linux/sched.h~tasks-rcu 2003-08-04 21:48:38.000000000 +0530
+++ linux-2.6.0-test2-ds-dipankar/include/linux/sched.h 2003-08-04 21:54:58.000000000 +0530
@@ -28,6 +28,7 @@
#include <linux/completion.h>
#include <linux/pid.h>
#include <linux/percpu.h>
+#include <linux/rcupdate.h>
struct exec_domain;
@@ -456,13 +457,23 @@ struct task_struct {
struct io_context *io_context;
unsigned long ptrace_message;
+ struct rcu_head rcu;
siginfo_t *last_siginfo; /* For ptrace use. */
};
extern void __put_task_struct(struct task_struct *tsk);
#define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
-#define put_task_struct(tsk) \
-do { if (atomic_dec_and_test(&(tsk)->usage)) __put_task_struct(tsk); } while(0)
+static void put_task_struct_rcu(struct rcu_head *rcu)
+{
+ struct task_struct *tsk = container_of(rcu, struct task_struct, rcu);
+ __put_task_struct(tsk);
+}
+static inline void put_task_struct(struct task_struct *tsk)
+{
+ if (atomic_dec_and_test(&tsk->usage))
+ call_rcu(&tsk->rcu, put_task_struct_rcu);
+}
+
/*
* Per process flags
@@ -675,13 +686,13 @@ extern void wait_task_inactive(task_t *
#define REMOVE_LINKS(p) do { \
if (thread_group_leader(p)) \
- list_del_init(&(p)->tasks); \
+ list_del_rcu(&(p)->tasks); \
remove_parent(p); \
} while (0)
#define SET_LINKS(p) do { \
if (thread_group_leader(p)) \
- list_add_tail(&(p)->tasks,&init_task.tasks); \
+ list_add_tail_rcu(&(p)->tasks,&init_task.tasks); \
add_parent(p, (p)->parent); \
} while (0)
@@ -689,7 +700,7 @@ extern void wait_task_inactive(task_t *
#define prev_task(p) list_entry((p)->tasks.prev, struct task_struct, tasks)
#define for_each_process(p) \
- for (p = &init_task ; (p = next_task(p)) != &init_task ; )
+ for (p = &init_task ; (p = next_task(p)),({ read_barrier_depends(); 0;}),p != &init_task ; )
/*
* Careful: do_each_thread/while_each_thread is a double loop so
_
next prev parent reply other threads:[~2005-08-11 18:16 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-10 17:11 [RFC,PATCH] Use RCU to protect tasklist for unicast signals Paul E. McKenney
2005-08-11 9:56 ` Ingo Molnar
2005-08-11 14:14 ` Paul E. McKenney
2005-08-12 2:00 ` Lee Revell
2005-08-12 6:36 ` Ingo Molnar
2005-08-12 20:57 ` Paul E. McKenney
2005-08-11 17:14 ` Christoph Hellwig
2005-08-11 17:56 ` Paul E. McKenney
2005-08-11 18:00 ` Dipankar Sarma
2005-08-11 18:12 ` Dipankar Sarma [this message]
-- strict thread matches above, loose matches on Subject: below --
2005-08-11 12:16 Oleg Nesterov
2005-08-11 15:20 ` Paul E. McKenney
2005-08-12 1:56 ` Paul E. McKenney
2005-08-12 8:51 ` Oleg Nesterov
2005-08-12 15:42 ` Paul E. McKenney
2005-08-15 17:44 ` Paul E. McKenney
2005-08-16 8:14 ` Ingo Molnar
2005-08-16 11:56 ` Oleg Nesterov
2005-08-16 17:07 ` Paul E. McKenney
2005-08-17 1:48 ` Paul E. McKenney
2005-08-17 6:35 ` Ingo Molnar
2005-08-17 14:35 ` Oleg Nesterov
2005-08-17 21:19 ` Paul E. McKenney
2005-08-18 11:48 ` Oleg Nesterov
2005-08-19 1:29 ` Paul E. McKenney
2005-08-19 13:27 ` Oleg Nesterov
2005-08-19 18:34 ` Paul E. McKenney
2005-08-18 12:24 ` Oleg Nesterov
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=20050811181235.GE4546@in.ibm.com \
--to=dipankar@in.ibm.com \
--cc=bmark@us.ibm.com \
--cc=hch@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulmck@us.ibm.com \
--cc=rusty@au1.ibm.com \
/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