All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC net-next 1/2] net: net-porcfs: Reduce rcu lock critical section
@ 2018-04-10 17:08 Saeed Mahameed
  2018-04-10 17:08 ` [RFC net-next 2/2] net: net-sysfs: Reduce netstat_show read_lock " Saeed Mahameed
  2018-04-10 17:16 ` [RFC net-next 1/2] net: net-porcfs: Reduce rcu lock " David Miller
  0 siblings, 2 replies; 12+ messages in thread
From: Saeed Mahameed @ 2018-04-10 17:08 UTC (permalink / raw)
  To: netdev; +Cc: Saeed Mahameed

The current net proc fs sequence file implementation to show current
namespace netdevs list statistics and mc lists holds the rcu lock
throughout the whole process, from dev seq start up to dev seq stop.

This is really greedy and demanding from device drivers since
ndo_get_stats64 called from dev_seq_show while the rcu lock is held.

The rcu lock is needed to guarantee that device chain is not modified
while the dev sequence file is walking through it and handling the
netdev in the same time.

To minimize this critical section and drastically reduce the time rcu lock
is being held, all we need is to grab the rcu lock only for the brief
moment where we are looking for the next netdev to handle, if found,
dev_hold it to guarantee it kept alive while accessed later in seq show
callback and release the rcu lock immediately.

The current netdev being handled will be released "dev_put" when the seq next
callback is called or dev seq stop is called.

Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
---
 net/core/net-procfs.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
index 9737302907b1..9d5ce6a203d2 100644
--- a/net/core/net-procfs.c
+++ b/net/core/net-procfs.c
@@ -31,19 +31,24 @@ static inline struct net_device *dev_from_same_bucket(struct seq_file *seq, loff
 
 static inline struct net_device *dev_from_bucket(struct seq_file *seq, loff_t *pos)
 {
-	struct net_device *dev;
+	struct net_device *dev = NULL;
 	unsigned int bucket;
 
+	rcu_read_lock();
 	do {
 		dev = dev_from_same_bucket(seq, pos);
-		if (dev)
-			return dev;
+		if (dev) {
+			dev_hold(dev);
+			goto unlock;
+		}
 
 		bucket = get_bucket(*pos) + 1;
 		*pos = set_bucket_offset(bucket, 1);
 	} while (bucket < NETDEV_HASHENTRIES);
 
-	return NULL;
+unlock:
+	rcu_read_unlock();
+	return dev;
 }
 
 /*
@@ -51,9 +56,7 @@ static inline struct net_device *dev_from_bucket(struct seq_file *seq, loff_t *p
  *	in detail.
  */
 static void *dev_seq_start(struct seq_file *seq, loff_t *pos)
-	__acquires(RCU)
 {
-	rcu_read_lock();
 	if (!*pos)
 		return SEQ_START_TOKEN;
 
@@ -66,13 +69,15 @@ static void *dev_seq_start(struct seq_file *seq, loff_t *pos)
 static void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 {
 	++*pos;
+	if (v && v != SEQ_START_TOKEN)
+		dev_put(v);
 	return dev_from_bucket(seq, pos);
 }
 
 static void dev_seq_stop(struct seq_file *seq, void *v)
-	__releases(RCU)
 {
-	rcu_read_unlock();
+	if (v && v != SEQ_START_TOKEN)
+		dev_put(v);
 }
 
 static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2018-04-16 21:07 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-10 17:08 [RFC net-next 1/2] net: net-porcfs: Reduce rcu lock critical section Saeed Mahameed
2018-04-10 17:08 ` [RFC net-next 2/2] net: net-sysfs: Reduce netstat_show read_lock " Saeed Mahameed
2018-04-10 17:17   ` David Miller
2018-04-10 17:16 ` [RFC net-next 1/2] net: net-porcfs: Reduce rcu lock " David Miller
2018-04-10 20:35   ` Eric Dumazet
2018-04-11 18:59     ` Saeed Mahameed
2018-04-11 22:30       ` Eric Dumazet
2018-04-11 23:47         ` Saeed Mahameed
2018-04-12  2:59           ` Eric Dumazet
2018-04-12 19:12             ` Saeed Mahameed
2018-04-16 20:50               ` Saeed Mahameed
2018-04-16 21:07                 ` Eric Dumazet

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.