Skip to content

Commit d297653

Browse files
roopa-prabhudavem330
authored andcommitted
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 472681d ("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>
1 parent 66fdd05 commit d297653

9 files changed

Lines changed: 98 additions & 73 deletions

File tree

‎drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,18 +432,19 @@ static int qlcnic_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
432432

433433
static int qlcnic_fdb_dump(struct sk_buff *skb, struct netlink_callback *ncb,
434434
struct net_device *netdev,
435-
struct net_device *filter_dev, int idx)
435+
struct net_device *filter_dev, int *idx)
436436
{
437437
struct qlcnic_adapter *adapter = netdev_priv(netdev);
438+
int err = 0;
438439

439440
if (!adapter->fdb_mac_learn)
440441
return ndo_dflt_fdb_dump(skb, ncb, netdev, filter_dev, idx);
441442

442443
if ((adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
443444
qlcnic_sriov_check(adapter))
444-
idx = ndo_dflt_fdb_dump(skb, ncb, netdev, filter_dev, idx);
445+
err = ndo_dflt_fdb_dump(skb, ncb, netdev, filter_dev, idx);
445446

446-
return idx;
447+
return err;
447448
}
448449

449450
static void qlcnic_82xx_cancel_idc_work(struct qlcnic_adapter *adapter)

‎drivers/net/vxlan.c‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -860,38 +860,36 @@ static int vxlan_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
860860
/* Dump forwarding table */
861861
static int vxlan_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
862862
struct net_device *dev,
863-
struct net_device *filter_dev, int idx)
863+
struct net_device *filter_dev, int *idx)
864864
{
865865
struct vxlan_dev *vxlan = netdev_priv(dev);
866866
unsigned int h;
867+
int err = 0;
867868

868869
for (h = 0; h < FDB_HASH_SIZE; ++h) {
869870
struct vxlan_fdb *f;
870-
int err;
871871

872872
hlist_for_each_entry_rcu(f, &vxlan->fdb_head[h], hlist) {
873873
struct vxlan_rdst *rd;
874874

875875
list_for_each_entry_rcu(rd, &f->remotes, list) {
876-
if (idx < cb->args[0])
876+
if (*idx < cb->args[2])
877877
goto skip;
878878

879879
err = vxlan_fdb_info(skb, vxlan, f,
880880
NETLINK_CB(cb->skb).portid,
881881
cb->nlh->nlmsg_seq,
882882
RTM_NEWNEIGH,
883883
NLM_F_MULTI, rd);
884-
if (err < 0) {
885-
cb->args[1] = err;
884+
if (err < 0)
886885
goto out;
887-
}
888886
skip:
889-
++idx;
887+
*idx += 1;
890888
}
891889
}
892890
}
893891
out:
894-
return idx;
892+
return err;
895893
}
896894

897895
/* Watch incoming packets to learn mapping between Ethernet address

‎include/linux/netdevice.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ struct netdev_xdp {
10311031
* Deletes the FDB entry from dev coresponding to addr.
10321032
* int (*ndo_fdb_dump)(struct sk_buff *skb, struct netlink_callback *cb,
10331033
* struct net_device *dev, struct net_device *filter_dev,
1034-
* int idx)
1034+
* int *idx)
10351035
* Used to add FDB entries to dump requests. Implementers should add
10361036
* entries to skb and update idx with the number of entries.
10371037
*
@@ -1263,7 +1263,7 @@ struct net_device_ops {
12631263
struct netlink_callback *cb,
12641264
struct net_device *dev,
12651265
struct net_device *filter_dev,
1266-
int idx);
1266+
int *idx);
12671267

12681268
int (*ndo_bridge_setlink)(struct net_device *dev,
12691269
struct nlmsghdr *nlh,

‎include/linux/rtnetlink.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ extern int ndo_dflt_fdb_dump(struct sk_buff *skb,
105105
struct netlink_callback *cb,
106106
struct net_device *dev,
107107
struct net_device *filter_dev,
108-
int idx);
108+
int *idx);
109109
extern int ndo_dflt_fdb_add(struct ndmsg *ndm,
110110
struct nlattr *tb[],
111111
struct net_device *dev,

‎include/net/switchdev.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
222222
u16 vid);
223223
int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
224224
struct net_device *dev,
225-
struct net_device *filter_dev, int idx);
225+
struct net_device *filter_dev, int *idx);
226226
void switchdev_port_fwd_mark_set(struct net_device *dev,
227227
struct net_device *group_dev,
228228
bool joining);
@@ -342,7 +342,7 @@ static inline int switchdev_port_fdb_dump(struct sk_buff *skb,
342342
struct netlink_callback *cb,
343343
struct net_device *dev,
344344
struct net_device *filter_dev,
345-
int idx)
345+
int *idx)
346346
{
347347
return idx;
348348
}

‎net/bridge/br_fdb.c‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -710,24 +710,27 @@ int br_fdb_dump(struct sk_buff *skb,
710710
struct netlink_callback *cb,
711711
struct net_device *dev,
712712
struct net_device *filter_dev,
713-
int idx)
713+
int *idx)
714714
{
715715
struct net_bridge *br = netdev_priv(dev);
716+
int err = 0;
716717
int i;
717718

718719
if (!(dev->priv_flags & IFF_EBRIDGE))
719720
goto out;
720721

721-
if (!filter_dev)
722-
idx = ndo_dflt_fdb_dump(skb, cb, dev, NULL, idx);
722+
if (!filter_dev) {
723+
err = ndo_dflt_fdb_dump(skb, cb, dev, NULL, idx);
724+
if (err < 0)
725+
goto out;
726+
}
723727

724728
for (i = 0; i < BR_HASH_SIZE; i++) {
725729
struct net_bridge_fdb_entry *f;
726730

727731
hlist_for_each_entry_rcu(f, &br->hash[i], hlist) {
728-
int err;
729732

730-
if (idx < cb->args[0])
733+
if (*idx < cb->args[2])
731734
goto skip;
732735

733736
if (filter_dev &&
@@ -750,17 +753,15 @@ int br_fdb_dump(struct sk_buff *skb,
750753
cb->nlh->nlmsg_seq,
751754
RTM_NEWNEIGH,
752755
NLM_F_MULTI);
753-
if (err < 0) {
754-
cb->args[1] = err;
755-
break;
756-
}
756+
if (err < 0)
757+
goto out;
757758
skip:
758-
++idx;
759+
*idx += 1;
759760
}
760761
}
761762

762763
out:
763-
return idx;
764+
return err;
764765
}
765766

766767
/* Update (create or replace) forwarding database entry */

‎net/bridge/br_private.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
508508
int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev,
509509
const unsigned char *addr, u16 vid, u16 nlh_flags);
510510
int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
511-
struct net_device *dev, struct net_device *fdev, int idx);
511+
struct net_device *dev, struct net_device *fdev, int *idx);
512512
int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p);
513513
void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p);
514514
int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,

‎net/core/rtnetlink.c‎

Lines changed: 65 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3068,7 +3068,7 @@ static int nlmsg_populate_fdb(struct sk_buff *skb,
30683068
seq = cb->nlh->nlmsg_seq;
30693069

30703070
list_for_each_entry(ha, &list->list, list) {
3071-
if (*idx < cb->args[0])
3071+
if (*idx < cb->args[2])
30723072
goto skip;
30733073

30743074
err = nlmsg_populate_fdb_fill(skb, dev, ha->addr, 0,
@@ -3095,19 +3095,18 @@ int ndo_dflt_fdb_dump(struct sk_buff *skb,
30953095
struct netlink_callback *cb,
30963096
struct net_device *dev,
30973097
struct net_device *filter_dev,
3098-
int idx)
3098+
int *idx)
30993099
{
31003100
int err;
31013101

31023102
netif_addr_lock_bh(dev);
3103-
err = nlmsg_populate_fdb(skb, cb, dev, &idx, &dev->uc);
3103+
err = nlmsg_populate_fdb(skb, cb, dev, idx, &dev->uc);
31043104
if (err)
31053105
goto out;
3106-
nlmsg_populate_fdb(skb, cb, dev, &idx, &dev->mc);
3106+
nlmsg_populate_fdb(skb, cb, dev, idx, &dev->mc);
31073107
out:
31083108
netif_addr_unlock_bh(dev);
3109-
cb->args[1] = err;
3110-
return idx;
3109+
return err;
31113110
}
31123111
EXPORT_SYMBOL(ndo_dflt_fdb_dump);
31133112

@@ -3120,9 +3119,13 @@ static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb)
31203119
const struct net_device_ops *cops = NULL;
31213120
struct ifinfomsg *ifm = nlmsg_data(cb->nlh);
31223121
struct net *net = sock_net(skb->sk);
3122+
struct hlist_head *head;
31233123
int brport_idx = 0;
31243124
int br_idx = 0;
3125-
int idx = 0;
3125+
int h, s_h;
3126+
int idx = 0, s_idx;
3127+
int err = 0;
3128+
int fidx = 0;
31263129

31273130
if (nlmsg_parse(cb->nlh, sizeof(struct ifinfomsg), tb, IFLA_MAX,
31283131
ifla_policy) == 0) {
@@ -3140,49 +3143,71 @@ static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb)
31403143
ops = br_dev->netdev_ops;
31413144
}
31423145

3143-
cb->args[1] = 0;
3144-
for_each_netdev(net, dev) {
3145-
if (brport_idx && (dev->ifindex != brport_idx))
3146-
continue;
3146+
s_h = cb->args[0];
3147+
s_idx = cb->args[1];
31473148

3148-
if (!br_idx) { /* user did not specify a specific bridge */
3149-
if (dev->priv_flags & IFF_BRIDGE_PORT) {
3150-
br_dev = netdev_master_upper_dev_get(dev);
3151-
cops = br_dev->netdev_ops;
3152-
}
3149+
for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
3150+
idx = 0;
3151+
head = &net->dev_index_head[h];
3152+
hlist_for_each_entry(dev, head, index_hlist) {
31533153

3154-
} else {
3155-
if (dev != br_dev &&
3156-
!(dev->priv_flags & IFF_BRIDGE_PORT))
3154+
if (brport_idx && (dev->ifindex != brport_idx))
31573155
continue;
31583156

3159-
if (br_dev != netdev_master_upper_dev_get(dev) &&
3160-
!(dev->priv_flags & IFF_EBRIDGE))
3161-
continue;
3157+
if (!br_idx) { /* user did not specify a specific bridge */
3158+
if (dev->priv_flags & IFF_BRIDGE_PORT) {
3159+
br_dev = netdev_master_upper_dev_get(dev);
3160+
cops = br_dev->netdev_ops;
3161+
}
3162+
} else {
3163+
if (dev != br_dev &&
3164+
!(dev->priv_flags & IFF_BRIDGE_PORT))
3165+
continue;
31623166

3163-
cops = ops;
3164-
}
3167+
if (br_dev != netdev_master_upper_dev_get(dev) &&
3168+
!(dev->priv_flags & IFF_EBRIDGE))
3169+
continue;
3170+
cops = ops;
3171+
}
31653172

3166-
if (dev->priv_flags & IFF_BRIDGE_PORT) {
3167-
if (cops && cops->ndo_fdb_dump)
3168-
idx = cops->ndo_fdb_dump(skb, cb, br_dev, dev,
3169-
idx);
3170-
}
3171-
if (cb->args[1] == -EMSGSIZE)
3172-
break;
3173+
if (idx < s_idx)
3174+
goto cont;
31733175

3174-
if (dev->netdev_ops->ndo_fdb_dump)
3175-
idx = dev->netdev_ops->ndo_fdb_dump(skb, cb, dev, NULL,
3176-
idx);
3177-
else
3178-
idx = ndo_dflt_fdb_dump(skb, cb, dev, NULL, idx);
3179-
if (cb->args[1] == -EMSGSIZE)
3180-
break;
3176+
if (dev->priv_flags & IFF_BRIDGE_PORT) {
3177+
if (cops && cops->ndo_fdb_dump) {
3178+
err = cops->ndo_fdb_dump(skb, cb,
3179+
br_dev, dev,
3180+
&fidx);
3181+
if (err == -EMSGSIZE)
3182+
goto out;
3183+
}
3184+
}
31813185

3182-
cops = NULL;
3186+
if (dev->netdev_ops->ndo_fdb_dump)
3187+
err = dev->netdev_ops->ndo_fdb_dump(skb, cb,
3188+
dev, NULL,
3189+
&fidx);
3190+
else
3191+
err = ndo_dflt_fdb_dump(skb, cb, dev, NULL,
3192+
&fidx);
3193+
if (err == -EMSGSIZE)
3194+
goto out;
3195+
3196+
cops = NULL;
3197+
3198+
/* reset fdb offset to 0 for rest of the interfaces */
3199+
cb->args[2] = 0;
3200+
fidx = 0;
3201+
cont:
3202+
idx++;
3203+
}
31833204
}
31843205

3185-
cb->args[0] = idx;
3206+
out:
3207+
cb->args[0] = h;
3208+
cb->args[1] = idx;
3209+
cb->args[2] = fidx;
3210+
31863211
return skb->len;
31873212
}
31883213

‎net/switchdev/switchdev.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ static int switchdev_port_fdb_dump_cb(struct switchdev_obj *obj)
10421042
struct nlmsghdr *nlh;
10431043
struct ndmsg *ndm;
10441044

1045-
if (dump->idx < dump->cb->args[0])
1045+
if (dump->idx < dump->cb->args[2])
10461046
goto skip;
10471047

10481048
nlh = nlmsg_put(dump->skb, portid, seq, RTM_NEWNEIGH,
@@ -1089,22 +1089,22 @@ static int switchdev_port_fdb_dump_cb(struct switchdev_obj *obj)
10891089
*/
10901090
int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
10911091
struct net_device *dev,
1092-
struct net_device *filter_dev, int idx)
1092+
struct net_device *filter_dev, int *idx)
10931093
{
10941094
struct switchdev_fdb_dump dump = {
10951095
.fdb.obj.orig_dev = dev,
10961096
.fdb.obj.id = SWITCHDEV_OBJ_ID_PORT_FDB,
10971097
.dev = dev,
10981098
.skb = skb,
10991099
.cb = cb,
1100-
.idx = idx,
1100+
.idx = *idx,
11011101
};
11021102
int err;
11031103

11041104
err = switchdev_port_obj_dump(dev, &dump.fdb.obj,
11051105
switchdev_port_fdb_dump_cb);
1106-
cb->args[1] = err;
1107-
return dump.idx;
1106+
*idx = dump.idx;
1107+
return err;
11081108
}
11091109
EXPORT_SYMBOL_GPL(switchdev_port_fdb_dump);
11101110

0 commit comments

Comments
 (0)