* [PATCH v3 0/2] sched: Add cond_resched_rcu_lock() helper
@ 2013-05-01 8:57 Simon Horman
2013-05-01 8:57 ` [PATCH v3 1/2] " Simon Horman
2013-05-01 8:57 ` [PATCH v3 2/2] ipvs: Use cond_resched_rcu_lock() helper when dumping connections Simon Horman
0 siblings, 2 replies; 3+ messages in thread
From: Simon Horman @ 2013-05-01 8:57 UTC (permalink / raw)
To: Eric Dumazet, Julian Anastasov, Ingo Molnar, Peter Zijlstra,
Paul E. McKenney
Cc: lvs-devel, netdev, netfilter-devel, linux-kernel,
Pablo Neira Ayuso, Dipankar Sarma, Simon Horman
Add a helper that for use in loops which read data protected by RCU and
may have a large number of iterations. Such an example is dumping the list
of connections known to IPVS: ip_vs_conn_array() and ip_vs_conn_seq_next().
This series also updates the two ip_vs functions mentioned above
to use the helper.
Changes since v1 and v2 noted in the changelog of each patch.
Simon Horman (2):
sched: Add cond_resched_rcu_lock() helper
ipvs: Use cond_resched_rcu_lock() helper when dumping connections
include/linux/sched.h | 11 +++++++++++
net/netfilter/ipvs/ip_vs_conn.c | 6 ++----
2 files changed, 13 insertions(+), 4 deletions(-)
--
1.8.2.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v3 1/2] sched: Add cond_resched_rcu_lock() helper
2013-05-01 8:57 [PATCH v3 0/2] sched: Add cond_resched_rcu_lock() helper Simon Horman
@ 2013-05-01 8:57 ` Simon Horman
2013-05-01 8:57 ` [PATCH v3 2/2] ipvs: Use cond_resched_rcu_lock() helper when dumping connections Simon Horman
1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2013-05-01 8:57 UTC (permalink / raw)
To: Eric Dumazet, Julian Anastasov, Ingo Molnar, Peter Zijlstra,
Paul E. McKenney
Cc: lvs-devel, netdev, netfilter-devel, linux-kernel,
Pablo Neira Ayuso, Dipankar Sarma, Simon Horman
This is intended for use in loops which read data protected by RCU and may
have a large number of iterations. Such an example is dumping the list of
connections known to IPVS: ip_vs_conn_array() and ip_vs_conn_seq_next().
The call to cond_resched() is guarded by #ifndef CONFIG_PREEMPT_RCU as in
the case of CONFIG_PREEMPT_RCU _rcu_read_unlock() will check to see if the
RCU core needs to be informed, so there is no need to invoke cond_resched()
in that case. Thanks to Paul E. McKenney for explaining this.
cond_resched_rcu_lock() suggested by Eric Dumazet.
ifndef guard suggested by Paul E. McKenney and Julian Anastasov.
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Julian Anastasov <ja@ssi.bg>
Acked-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Simon Horman <horms@verge.net.au>
---
v3
* Remove if (need_resched()), it is no longer needed with
the guard added in v2.
v2
* Guard the call to cond_resched() with #ifndef CONFIG_PREEMPT_RCU
---
include/linux/sched.h | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index e692a02..79cfe6d 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2787,3 +2787,12 @@ static inline unsigned long rlimit_max(unsigned int limit)
}
#endif
+
+static void inline cond_resched_rcu_lock(void)
+{
+ rcu_read_unlock();
+#ifndef CONFIG_PREEMPT_RCU
+ cond_resched();
+#endif
+ rcu_read_lock();
+}
--
1.8.2.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v3 2/2] ipvs: Use cond_resched_rcu_lock() helper when dumping connections
2013-05-01 8:57 [PATCH v3 0/2] sched: Add cond_resched_rcu_lock() helper Simon Horman
2013-05-01 8:57 ` [PATCH v3 1/2] " Simon Horman
@ 2013-05-01 8:57 ` Simon Horman
1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2013-05-01 8:57 UTC (permalink / raw)
To: Eric Dumazet, Julian Anastasov, Ingo Molnar, Peter Zijlstra,
Paul E. McKenney
Cc: lvs-devel, netdev, netfilter-devel, linux-kernel,
Pablo Neira Ayuso, Dipankar Sarma, Simon Horman, Ingo Molnar
This avoids the situation where a dump of a large number of connections
may prevent scheduling for a long time while also avoiding excessive
calls to rcu_read_unlock() and rcu_read_lock().
Note that in the case of !CONFIG_PREEMPT_RCU this will
add a call to cond_resched().
Compile tested only.
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Julian Anastasov <ja@ssi.bg>
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Simon Horman <horms@verge.net.au>
---
net/netfilter/ipvs/ip_vs_conn.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
index a083bda..42a7b33 100644
--- a/net/netfilter/ipvs/ip_vs_conn.c
+++ b/net/netfilter/ipvs/ip_vs_conn.c
@@ -975,8 +975,7 @@ static void *ip_vs_conn_array(struct seq_file *seq, loff_t pos)
return cp;
}
}
- rcu_read_unlock();
- rcu_read_lock();
+ cond_resched_rcu_lock();
}
return NULL;
@@ -1015,8 +1014,7 @@ static void *ip_vs_conn_seq_next(struct seq_file *seq, void *v, loff_t *pos)
iter->l = &ip_vs_conn_tab[idx];
return cp;
}
- rcu_read_unlock();
- rcu_read_lock();
+ cond_resched_rcu_lock();
}
iter->l = NULL;
return NULL;
--
1.8.2.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-05-01 8:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-01 8:57 [PATCH v3 0/2] sched: Add cond_resched_rcu_lock() helper Simon Horman
2013-05-01 8:57 ` [PATCH v3 1/2] " Simon Horman
2013-05-01 8:57 ` [PATCH v3 2/2] ipvs: Use cond_resched_rcu_lock() helper when dumping connections Simon Horman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).