diff mbox series

[RFC,net-next,2/2] net: net-sysfs: Reduce netstat_show read_lock critical section

Message ID 20180410170812.18905-2-saeedm@mellanox.com
State RFC, archived
Delegated to: David Miller
Headers show
Series [RFC,net-next,1/2] net: net-porcfs: Reduce rcu lock critical section | expand

Commit Message

Saeed Mahameed April 10, 2018, 5:08 p.m. UTC
Instead of holding the device chain read_lock also while calling
dev_get_stats just hold it only to check dev_isalive, if the dev is alive,
hold that dev via dev_hold then release the read_lock.

When done handling the device, dev_put it.

Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
---
 net/core/net-sysfs.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

David Miller April 10, 2018, 5:17 p.m. UTC | #1
From: Saeed Mahameed <saeedm@mellanox.com>
Date: Tue, 10 Apr 2018 10:08:12 -0700

> Instead of holding the device chain read_lock also while calling
> dev_get_stats just hold it only to check dev_isalive, if the dev is alive,
> hold that dev via dev_hold then release the read_lock.
> 
> When done handling the device, dev_put it.
> 
> Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>

My feedback here is that same as for patch #1.

Two atomics for a shorter RCU lock hold time is not that great of
a tradeoff.
diff mbox series

Patch

diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index c476f0794132..ee6f9fed43df 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -563,13 +563,20 @@  static ssize_t netstat_show(const struct device *d,
 		offset % sizeof(u64) != 0);
 
 	read_lock(&dev_base_lock);
-	if (dev_isalive(dev)) {
+	if (dev_isalive(dev))
+		dev_hold(dev);
+	else
+		dev = NULL;
+	read_unlock(&dev_base_lock);
+
+	if (dev) {
 		struct rtnl_link_stats64 temp;
 		const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
 
+		dev_put(dev);
 		ret = sprintf(buf, fmt_u64, *(u64 *)(((u8 *)stats) + offset));
 	}
-	read_unlock(&dev_base_lock);
+
 	return ret;
 }