rtnetlink: fdb dump: optimize by saving last interface markers

fdb dumps spanning multiple skb's currently restart from the first
interface again for every skb. This results in unnecessary
iterations on the already visited interfaces and their fdb
entries. In large scale setups, we have seen this to slow
down fdb dumps considerably. On a system with 30k macs we
see fdb dumps spanning across more than 300 skbs.

To fix the problem, this patch replaces the existing single fdb
marker with three markers: netdev hash entries, netdevs and fdb
index to continue where we left off instead of restarting from the
first netdev. This is consistent with link dumps.

In the process of fixing the performance issue, this patch also
re-implements fix done by
commit 472681d57a ("net: ndo_fdb_dump should report -EMSGSIZE to rtnl_fdb_dump")
(with an internal fix from Wilson Kok) in the following ways:
- change ndo_fdb_dump handlers to return error code instead
of the last fdb index
- use cb->args strictly for dump frag markers and not error codes.
This is consistent with other dump functions.

Below results were taken on a system with 1000 netdevs
and 35085 fdb entries:
before patch:
$time bridge fdb show | wc -l
15065

real    1m11.791s
user    0m0.070s
sys 1m8.395s

(existing code does not return all macs)

after patch:
$time bridge fdb show | wc -l
35085

real    0m2.017s
user    0m0.113s
sys 0m1.942s

Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
Signed-off-by: Wilson Kok <wkok@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Roopa Prabhu 2016-08-30 21:56:45 -07:00 committed by David S. Miller
parent 66fdd05e7a
commit d297653dd6
9 changed files with 100 additions and 75 deletions

View File

@ -432,18 +432,19 @@ static int qlcnic_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
static int qlcnic_fdb_dump(struct sk_buff *skb, struct netlink_callback *ncb, static int qlcnic_fdb_dump(struct sk_buff *skb, struct netlink_callback *ncb,
struct net_device *netdev, struct net_device *netdev,
struct net_device *filter_dev, int idx) struct net_device *filter_dev, int *idx)
{ {
struct qlcnic_adapter *adapter = netdev_priv(netdev); struct qlcnic_adapter *adapter = netdev_priv(netdev);
int err = 0;
if (!adapter->fdb_mac_learn) if (!adapter->fdb_mac_learn)
return ndo_dflt_fdb_dump(skb, ncb, netdev, filter_dev, idx); return ndo_dflt_fdb_dump(skb, ncb, netdev, filter_dev, idx);
if ((adapter->flags & QLCNIC_ESWITCH_ENABLED) || if ((adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
qlcnic_sriov_check(adapter)) qlcnic_sriov_check(adapter))
idx = ndo_dflt_fdb_dump(skb, ncb, netdev, filter_dev, idx); err = ndo_dflt_fdb_dump(skb, ncb, netdev, filter_dev, idx);
return idx; return err;
} }
static void qlcnic_82xx_cancel_idc_work(struct qlcnic_adapter *adapter) static void qlcnic_82xx_cancel_idc_work(struct qlcnic_adapter *adapter)

View File

@ -860,20 +860,20 @@ static int vxlan_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
/* Dump forwarding table */ /* Dump forwarding table */
static int vxlan_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, static int vxlan_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
struct net_device *dev, struct net_device *dev,
struct net_device *filter_dev, int idx) struct net_device *filter_dev, int *idx)
{ {
struct vxlan_dev *vxlan = netdev_priv(dev); struct vxlan_dev *vxlan = netdev_priv(dev);
unsigned int h; unsigned int h;
int err = 0;
for (h = 0; h < FDB_HASH_SIZE; ++h) { for (h = 0; h < FDB_HASH_SIZE; ++h) {
struct vxlan_fdb *f; struct vxlan_fdb *f;
int err;
hlist_for_each_entry_rcu(f, &vxlan->fdb_head[h], hlist) { hlist_for_each_entry_rcu(f, &vxlan->fdb_head[h], hlist) {
struct vxlan_rdst *rd; struct vxlan_rdst *rd;
list_for_each_entry_rcu(rd, &f->remotes, list) { list_for_each_entry_rcu(rd, &f->remotes, list) {
if (idx < cb->args[0]) if (*idx < cb->args[2])
goto skip; goto skip;
err = vxlan_fdb_info(skb, vxlan, f, err = vxlan_fdb_info(skb, vxlan, f,
@ -881,17 +881,15 @@ static int vxlan_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
cb->nlh->nlmsg_seq, cb->nlh->nlmsg_seq,
RTM_NEWNEIGH, RTM_NEWNEIGH,
NLM_F_MULTI, rd); NLM_F_MULTI, rd);
if (err < 0) { if (err < 0)
cb->args[1] = err;
goto out; goto out;
}
skip: skip:
++idx; *idx += 1;
} }
} }
} }
out: out:
return idx; return err;
} }
/* Watch incoming packets to learn mapping between Ethernet address /* Watch incoming packets to learn mapping between Ethernet address

View File

@ -1031,7 +1031,7 @@ struct netdev_xdp {
* Deletes the FDB entry from dev coresponding to addr. * Deletes the FDB entry from dev coresponding to addr.
* int (*ndo_fdb_dump)(struct sk_buff *skb, struct netlink_callback *cb, * int (*ndo_fdb_dump)(struct sk_buff *skb, struct netlink_callback *cb,
* struct net_device *dev, struct net_device *filter_dev, * struct net_device *dev, struct net_device *filter_dev,
* int idx) * int *idx)
* Used to add FDB entries to dump requests. Implementers should add * Used to add FDB entries to dump requests. Implementers should add
* entries to skb and update idx with the number of entries. * entries to skb and update idx with the number of entries.
* *
@ -1263,7 +1263,7 @@ struct net_device_ops {
struct netlink_callback *cb, struct netlink_callback *cb,
struct net_device *dev, struct net_device *dev,
struct net_device *filter_dev, struct net_device *filter_dev,
int idx); int *idx);
int (*ndo_bridge_setlink)(struct net_device *dev, int (*ndo_bridge_setlink)(struct net_device *dev,
struct nlmsghdr *nlh, struct nlmsghdr *nlh,

View File

@ -105,7 +105,7 @@ extern int ndo_dflt_fdb_dump(struct sk_buff *skb,
struct netlink_callback *cb, struct netlink_callback *cb,
struct net_device *dev, struct net_device *dev,
struct net_device *filter_dev, struct net_device *filter_dev,
int idx); int *idx);
extern int ndo_dflt_fdb_add(struct ndmsg *ndm, extern int ndo_dflt_fdb_add(struct ndmsg *ndm,
struct nlattr *tb[], struct nlattr *tb[],
struct net_device *dev, struct net_device *dev,

View File

@ -222,7 +222,7 @@ int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
u16 vid); u16 vid);
int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
struct net_device *dev, struct net_device *dev,
struct net_device *filter_dev, int idx); struct net_device *filter_dev, int *idx);
void switchdev_port_fwd_mark_set(struct net_device *dev, void switchdev_port_fwd_mark_set(struct net_device *dev,
struct net_device *group_dev, struct net_device *group_dev,
bool joining); bool joining);
@ -342,7 +342,7 @@ static inline int switchdev_port_fdb_dump(struct sk_buff *skb,
struct netlink_callback *cb, struct netlink_callback *cb,
struct net_device *dev, struct net_device *dev,
struct net_device *filter_dev, struct net_device *filter_dev,
int idx) int *idx)
{ {
return idx; return idx;
} }

View File

@ -710,24 +710,27 @@ int br_fdb_dump(struct sk_buff *skb,
struct netlink_callback *cb, struct netlink_callback *cb,
struct net_device *dev, struct net_device *dev,
struct net_device *filter_dev, struct net_device *filter_dev,
int idx) int *idx)
{ {
struct net_bridge *br = netdev_priv(dev); struct net_bridge *br = netdev_priv(dev);
int err = 0;
int i; int i;
if (!(dev->priv_flags & IFF_EBRIDGE)) if (!(dev->priv_flags & IFF_EBRIDGE))
goto out; goto out;
if (!filter_dev) if (!filter_dev) {
idx = ndo_dflt_fdb_dump(skb, cb, dev, NULL, idx); err = ndo_dflt_fdb_dump(skb, cb, dev, NULL, idx);
if (err < 0)
goto out;
}
for (i = 0; i < BR_HASH_SIZE; i++) { for (i = 0; i < BR_HASH_SIZE; i++) {
struct net_bridge_fdb_entry *f; struct net_bridge_fdb_entry *f;
hlist_for_each_entry_rcu(f, &br->hash[i], hlist) { hlist_for_each_entry_rcu(f, &br->hash[i], hlist) {
int err;
if (idx < cb->args[0]) if (*idx < cb->args[2])
goto skip; goto skip;
if (filter_dev && if (filter_dev &&
@ -750,17 +753,15 @@ int br_fdb_dump(struct sk_buff *skb,
cb->nlh->nlmsg_seq, cb->nlh->nlmsg_seq,
RTM_NEWNEIGH, RTM_NEWNEIGH,
NLM_F_MULTI); NLM_F_MULTI);
if (err < 0) { if (err < 0)
cb->args[1] = err; goto out;
break;
}
skip: skip:
++idx; *idx += 1;
} }
} }
out: out:
return idx; return err;
} }
/* Update (create or replace) forwarding database entry */ /* Update (create or replace) forwarding database entry */

View File

@ -508,7 +508,7 @@ int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev, int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev,
const unsigned char *addr, u16 vid, u16 nlh_flags); const unsigned char *addr, u16 vid, u16 nlh_flags);
int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
struct net_device *dev, struct net_device *fdev, int idx); struct net_device *dev, struct net_device *fdev, int *idx);
int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p); int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p);
void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p); void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p);
int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p, int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,

View File

@ -3068,7 +3068,7 @@ static int nlmsg_populate_fdb(struct sk_buff *skb,
seq = cb->nlh->nlmsg_seq; seq = cb->nlh->nlmsg_seq;
list_for_each_entry(ha, &list->list, list) { list_for_each_entry(ha, &list->list, list) {
if (*idx < cb->args[0]) if (*idx < cb->args[2])
goto skip; goto skip;
err = nlmsg_populate_fdb_fill(skb, dev, ha->addr, 0, err = nlmsg_populate_fdb_fill(skb, dev, ha->addr, 0,
@ -3095,19 +3095,18 @@ int ndo_dflt_fdb_dump(struct sk_buff *skb,
struct netlink_callback *cb, struct netlink_callback *cb,
struct net_device *dev, struct net_device *dev,
struct net_device *filter_dev, struct net_device *filter_dev,
int idx) int *idx)
{ {
int err; int err;
netif_addr_lock_bh(dev); netif_addr_lock_bh(dev);
err = nlmsg_populate_fdb(skb, cb, dev, &idx, &dev->uc); err = nlmsg_populate_fdb(skb, cb, dev, idx, &dev->uc);
if (err) if (err)
goto out; goto out;
nlmsg_populate_fdb(skb, cb, dev, &idx, &dev->mc); nlmsg_populate_fdb(skb, cb, dev, idx, &dev->mc);
out: out:
netif_addr_unlock_bh(dev); netif_addr_unlock_bh(dev);
cb->args[1] = err; return err;
return idx;
} }
EXPORT_SYMBOL(ndo_dflt_fdb_dump); EXPORT_SYMBOL(ndo_dflt_fdb_dump);
@ -3120,9 +3119,13 @@ static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb)
const struct net_device_ops *cops = NULL; const struct net_device_ops *cops = NULL;
struct ifinfomsg *ifm = nlmsg_data(cb->nlh); struct ifinfomsg *ifm = nlmsg_data(cb->nlh);
struct net *net = sock_net(skb->sk); struct net *net = sock_net(skb->sk);
struct hlist_head *head;
int brport_idx = 0; int brport_idx = 0;
int br_idx = 0; int br_idx = 0;
int idx = 0; int h, s_h;
int idx = 0, s_idx;
int err = 0;
int fidx = 0;
if (nlmsg_parse(cb->nlh, sizeof(struct ifinfomsg), tb, IFLA_MAX, if (nlmsg_parse(cb->nlh, sizeof(struct ifinfomsg), tb, IFLA_MAX,
ifla_policy) == 0) { ifla_policy) == 0) {
@ -3140,8 +3143,14 @@ static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb)
ops = br_dev->netdev_ops; ops = br_dev->netdev_ops;
} }
cb->args[1] = 0; s_h = cb->args[0];
for_each_netdev(net, dev) { s_idx = cb->args[1];
for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
idx = 0;
head = &net->dev_index_head[h];
hlist_for_each_entry(dev, head, index_hlist) {
if (brport_idx && (dev->ifindex != brport_idx)) if (brport_idx && (dev->ifindex != brport_idx))
continue; continue;
@ -3150,7 +3159,6 @@ static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb)
br_dev = netdev_master_upper_dev_get(dev); br_dev = netdev_master_upper_dev_get(dev);
cops = br_dev->netdev_ops; cops = br_dev->netdev_ops;
} }
} else { } else {
if (dev != br_dev && if (dev != br_dev &&
!(dev->priv_flags & IFF_BRIDGE_PORT)) !(dev->priv_flags & IFF_BRIDGE_PORT))
@ -3159,30 +3167,47 @@ static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb)
if (br_dev != netdev_master_upper_dev_get(dev) && if (br_dev != netdev_master_upper_dev_get(dev) &&
!(dev->priv_flags & IFF_EBRIDGE)) !(dev->priv_flags & IFF_EBRIDGE))
continue; continue;
cops = ops; cops = ops;
} }
if (idx < s_idx)
goto cont;
if (dev->priv_flags & IFF_BRIDGE_PORT) { if (dev->priv_flags & IFF_BRIDGE_PORT) {
if (cops && cops->ndo_fdb_dump) if (cops && cops->ndo_fdb_dump) {
idx = cops->ndo_fdb_dump(skb, cb, br_dev, dev, err = cops->ndo_fdb_dump(skb, cb,
idx); br_dev, dev,
&fidx);
if (err == -EMSGSIZE)
goto out;
}
} }
if (cb->args[1] == -EMSGSIZE)
break;
if (dev->netdev_ops->ndo_fdb_dump) if (dev->netdev_ops->ndo_fdb_dump)
idx = dev->netdev_ops->ndo_fdb_dump(skb, cb, dev, NULL, err = dev->netdev_ops->ndo_fdb_dump(skb, cb,
idx); dev, NULL,
&fidx);
else else
idx = ndo_dflt_fdb_dump(skb, cb, dev, NULL, idx); err = ndo_dflt_fdb_dump(skb, cb, dev, NULL,
if (cb->args[1] == -EMSGSIZE) &fidx);
break; if (err == -EMSGSIZE)
goto out;
cops = NULL; cops = NULL;
/* reset fdb offset to 0 for rest of the interfaces */
cb->args[2] = 0;
fidx = 0;
cont:
idx++;
}
} }
cb->args[0] = idx; out:
cb->args[0] = h;
cb->args[1] = idx;
cb->args[2] = fidx;
return skb->len; return skb->len;
} }

View File

@ -1042,7 +1042,7 @@ static int switchdev_port_fdb_dump_cb(struct switchdev_obj *obj)
struct nlmsghdr *nlh; struct nlmsghdr *nlh;
struct ndmsg *ndm; struct ndmsg *ndm;
if (dump->idx < dump->cb->args[0]) if (dump->idx < dump->cb->args[2])
goto skip; goto skip;
nlh = nlmsg_put(dump->skb, portid, seq, RTM_NEWNEIGH, nlh = nlmsg_put(dump->skb, portid, seq, RTM_NEWNEIGH,
@ -1089,7 +1089,7 @@ static int switchdev_port_fdb_dump_cb(struct switchdev_obj *obj)
*/ */
int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
struct net_device *dev, struct net_device *dev,
struct net_device *filter_dev, int idx) struct net_device *filter_dev, int *idx)
{ {
struct switchdev_fdb_dump dump = { struct switchdev_fdb_dump dump = {
.fdb.obj.orig_dev = dev, .fdb.obj.orig_dev = dev,
@ -1097,14 +1097,14 @@ int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
.dev = dev, .dev = dev,
.skb = skb, .skb = skb,
.cb = cb, .cb = cb,
.idx = idx, .idx = *idx,
}; };
int err; int err;
err = switchdev_port_obj_dump(dev, &dump.fdb.obj, err = switchdev_port_obj_dump(dev, &dump.fdb.obj,
switchdev_port_fdb_dump_cb); switchdev_port_fdb_dump_cb);
cb->args[1] = err; *idx = dump.idx;
return dump.idx; return err;
} }
EXPORT_SYMBOL_GPL(switchdev_port_fdb_dump); EXPORT_SYMBOL_GPL(switchdev_port_fdb_dump);