rtnetlink: fdb dump: optimize by saving last interface markers
Subsystems (5)
PATCH 1/1 rtnetlink: fdb dump: optimize by saving last interface markers
From: Roopa Prabhu <[email protected]>
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 472681d57a5d ("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
--- drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c | 7 +- drivers/net/vxlan.c | 14 ++- include/linux/netdevice.h | 4 +- include/linux/rtnetlink.h | 2 +- include/net/switchdev.h | 4 +- net/bridge/br_fdb.c | 23 ++--- net/bridge/br_private.h | 2 +- net/core/rtnetlink.c | 105 ++++++++++++++--------- net/switchdev/switchdev.c | 10 +-- 9 files changed, 98 insertions(+), 73 deletions(-)
drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c +4 -3
@@ -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,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); +int err =0 ;if (!adapter->fdb_mac_learn)return ndo_dflt_fdb_dump (skb, ncb, netdev, filter_dev, idx);if ((adapter->flags &QLCNIC_ESWITCH_ENABLED ) ||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)
drivers/net/vxlan.c +6 -8
@@ -861,20 +861,20 @@ out:/* Dump forwarding table */ static int vxlan_fdb_dump (struct sk_buff *skb,struct netlink_callback *cb,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);unsigned int h; +int err =0 ;for (h =0 ; h <FDB_HASH_SIZE ; ++h) {struct vxlan_fdb *f; -int err;hlist_for_each_entry_rcu (f, &vxlan->fdb_head[h], hlist) {struct vxlan_rdst *rd;list_for_each_entry_rcu (rd, &f->remotes, list) { -if (idx < cb->args[0 ]) +if (*idx < cb->args[2 ]) goto skip; err = vxlan_fdb_info(skb, vxlan, f,
@@ -882,17 +882,15 @@ static int vxlan_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, cb->nlh->nlmsg_seq,RTM_NEWNEIGH , NLM_F_MULTI, rd); -if (err <0 ) { - cb->args[1 ] = err; +if (err <0 ) goto out; - } skip: - ++idx; + *idx +=1 ; } } } out: -return idx; +return err; }/* Watch incoming packets to learn mapping between Ethernet address
include/linux/netdevice.h +2 -2
@@ -1031,7 +1031,7 @@ struct netdev_xdp {* Deletes the FDB entry from dev coresponding to addr. * int (*ndo_fdb_dump)(struct sk_buff *skb, struct netlink_callback *cb, * struct net_device *dev, struct net_device *filter_dev, -* int idx) +* int *idx) * Used to add FDB entries to dump requests. Implementers should add * entries to skb and update idx with the number of entries. *
@@ -1263,7 +1263,7 @@ struct net_device_ops {struct netlink_callback *cb, struct net_device *dev, struct net_device *filter_dev, - int idx); + int *idx); int (*ndo_bridge_setlink)(struct net_device *dev, struct nlmsghdr *nlh,
include/linux/rtnetlink.h +1 -1
@@ -105,7 +105,7 @@ extern int ndo_dflt_fdb_dump(struct sk_buff *skb,struct netlink_callback *cb, struct net_device *dev, struct net_device *filter_dev, - int idx); + int *idx); extern int ndo_dflt_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], struct net_device *dev,
include/net/switchdev.h +2 -2
@@ -222,7 +222,7 @@ int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[], u16 vid);int switchdev_port_fdb_dump (struct sk_buff *skb,struct netlink_callback *cb,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,struct net_device *group_dev,bool joining);
@@ -342,7 +342,7 @@ static inline int switchdev_port_fdb_dump(struct sk_buff *skb,struct netlink_callback *cb, struct net_device *dev, struct net_device *filter_dev, - int idx) + int *idx) { return idx; }
net/bridge/br_fdb.c +12 -11
@@ -710,24 +710,27 @@ int br_fdb_dump(struct sk_buff *skb,struct netlink_callback *cb, struct net_device *dev, struct net_device *filter_dev, - int idx) + int *idx) { struct net_bridge *br = netdev_priv(dev); +int err =0 ;int i;if (!(dev->priv_flags &IFF_EBRIDGE )) goto out; -if (!filter_dev) - idx =ndo_dflt_fdb_dump (skb, cb, dev,NULL , idx); +if (!filter_dev) { + err =ndo_dflt_fdb_dump (skb, cb, dev,NULL , idx); +if (err <0 ) + goto out; + }for (i =0 ; i <BR_HASH_SIZE ; i++) {struct net_bridge_fdb_entry *f;hlist_for_each_entry_rcu (f, &br->hash[i], hlist) { -int err; -if (idx < cb->args[0 ]) +if (*idx < cb->args[2 ]) goto skip; if (filter_dev &&
@@ -750,17 +753,15 @@ int br_fdb_dump(struct sk_buff *skb, cb->nlh->nlmsg_seq,RTM_NEWNEIGH , NLM_F_MULTI); -if (err <0 ) { - cb->args[1 ] = err; -break ; - } +if (err <0 ) + goto out; skip: - ++idx; + *idx +=1 ; } } out: -return idx; +return err; }/* Update (create or replace) forwarding database entry */
net/bridge/br_private.h +1 -1
@@ -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,const unsigned char *addr,u16 vid,u16 nlh_flags);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);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,
net/core/rtnetlink.c +65 -40
149 lines not on this page · raw message
net/switchdev/switchdev.c +5 -5
@@ -1042,7 +1042,7 @@ static int switchdev_port_fdb_dump_cb(struct switchdev_obj *obj)struct nlmsghdr *nlh;struct ndmsg *ndm; -if (dump->idx < dump->cb->args[0 ]) +if (dump->idx < dump->cb->args[2 ]) goto skip; nlh = nlmsg_put(dump->skb, portid, seq, RTM_NEWNEIGH,
@@ -1089,7 +1089,7 @@ nla_put_failure:*/ int switchdev_port_fdb_dump (struct sk_buff *skb,struct netlink_callback *cb,struct net_device *dev, -struct net_device *filter_dev,int idx) +struct net_device *filter_dev,int *idx) {struct switchdev_fdb_dump dump = { .fdb.obj.orig_dev = dev,
@@ -1097,14 +1097,14 @@ int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, .dev = dev, .skb = skb, .cb = cb, - .idx = idx, + .idx = *idx, };int err; err =switchdev_port_obj_dump (dev, &dump.fdb.obj, switchdev_port_fdb_dump_cb); - cb->args[1 ] = err; -return dump.idx; + *idx = dump.idx; +return err; }EXPORT_SYMBOL_GPL (switchdev_port_fdb_dump);
Signature · 1 line
1.9.1
David Miller
maintainerFrom: Roopa Prabhu <[email protected]>
Date: Tue, 30 Aug 2016 21:56:45 -0700
Quoted 22 lines
From: Roopa Prabhu <[email protected]>
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
commit472681d57a5d("net:ndo_fdb_dumpshould report-EMSGSIZEtortnl_fdb_dump") (with an internal fix from Wilson Kok) in the following ways:
- changendo_fdb_dumphandlers to return error code instead
of the last fdb index
- usecb->argsstrictly for dump frag markers and not error codes. This is consistent with other dump functions.
...
Quoted 2 lines
Signed-off-by Roopa Prabhu <[email protected]>Signed-off-by Wilson Kok <[email protected]>
Looks great, applied, thanks!
include/net/switchdev.h static inline int switchdev_port_fdb_dump(struct sk_buff *skb, · line 348
Quoted 11 lines · Roopa Prabhu
From: Roopa Prabhu <[email protected]>
include/net/switchdev.h +1
-1@@ -342,7 +342,7 @@ static inline int switchdev_port_fdb_dump(struct sk_buff *skb,struct netlink_callback *cb, struct net_device *dev, struct net_device *filter_dev, - int idx) + int *idx) { return idx; }
Compiler is not happy with this change.
$ grep CONFIG_NET_SWITCHDEV .config # CONFIG_NET_SWITCHDEV is not set
...
./include/net/switchdev.h: In function 'switchdev_port_fdb_dump':./include/net/switchdev.h:347:8: warning: return makes integer from pointer without a cast [enabled by default]
Thanks.
Hi Eric,
Nice catch!
This warning does not occur under certain gcc versions. For example, gcc 4.8.4 (ubuntu 14.04); it does occur, for example, under gcc 5.3.1 for example (Fedora 24).
I just sent a patch to fix this.
Regards,
Rami Rosen
Quoted 9 lines · Rami Rosen
Hi Eric,
Nice catch!
This warning does not occur under certain gcc versions. For example, gcc 4.8.4 (ubuntu 14.04); it does occur, for example, under gcc 5.3.1 for example (Fedora 24).I just sent a patch to fix this.
Thanks Rami for taking care of this.
Please add in your future submissions any relevant attributions ;)