ipv6: speedup inet6_dump_ifinfo()
When handling large number of netdevice, inet6_dump_ifinfo() is very slow because it has O(N^2) complexity. Instead of scanning one single list, we can use the 256 sub lists of the dev_index hash table, and RCU lookups. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
13cfa97bef
commit
84d2697d96
@@ -3823,28 +3823,39 @@ nla_put_failure:
|
|||||||
static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
|
static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
|
||||||
{
|
{
|
||||||
struct net *net = sock_net(skb->sk);
|
struct net *net = sock_net(skb->sk);
|
||||||
int idx, err;
|
int h, s_h;
|
||||||
int s_idx = cb->args[0];
|
int idx = 0, err, s_idx;
|
||||||
struct net_device *dev;
|
struct net_device *dev;
|
||||||
struct inet6_dev *idev;
|
struct inet6_dev *idev;
|
||||||
|
struct hlist_head *head;
|
||||||
|
struct hlist_node *node;
|
||||||
|
|
||||||
read_lock(&dev_base_lock);
|
s_h = cb->args[0];
|
||||||
idx = 0;
|
s_idx = cb->args[1];
|
||||||
for_each_netdev(net, dev) {
|
|
||||||
if (idx < s_idx)
|
rcu_read_lock();
|
||||||
goto cont;
|
for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
|
||||||
if ((idev = in6_dev_get(dev)) == NULL)
|
idx = 0;
|
||||||
goto cont;
|
head = &net->dev_index_head[h];
|
||||||
err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
|
hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
|
||||||
cb->nlh->nlmsg_seq, RTM_NEWLINK, NLM_F_MULTI);
|
if (idx < s_idx)
|
||||||
in6_dev_put(idev);
|
goto cont;
|
||||||
if (err <= 0)
|
idev = __in6_dev_get(dev);
|
||||||
break;
|
if (!idev)
|
||||||
|
goto cont;
|
||||||
|
if (inet6_fill_ifinfo(skb, idev,
|
||||||
|
NETLINK_CB(cb->skb).pid,
|
||||||
|
cb->nlh->nlmsg_seq,
|
||||||
|
RTM_NEWLINK, NLM_F_MULTI) <= 0)
|
||||||
|
goto out;
|
||||||
cont:
|
cont:
|
||||||
idx++;
|
idx++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
read_unlock(&dev_base_lock);
|
out:
|
||||||
cb->args[0] = idx;
|
rcu_read_unlock();
|
||||||
|
cb->args[1] = idx;
|
||||||
|
cb->args[0] = h;
|
||||||
|
|
||||||
return skb->len;
|
return skb->len;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user