Skip to content

Commit 2f268f1

Browse files
Veaceslav Falicodavem330
authored andcommitted
net: add adj_list to save only neighbours
Currently, we distinguish neighbours (first-level linked devices) from non-neighbours by the neighbour bool in the netdev_adjacent. This could be quite time-consuming in case we would like to traverse *only* through neighbours - cause we'd have to traverse through all devices and check for this flag, and in a (quite common) scenario where we have lots of vlans on top of bridge, which is on top of a bond - the bonding would have to go through all those vlans to get its upper neighbour linked devices. This situation is really unpleasant, cause there are already a lot of cases when a device with slaves needs to go through them in hot path. To fix this, introduce a new upper/lower device lists structure - adj_list, which contains only the neighbours. It works always in pair with the all_adj_list structure (renamed from upper/lower_dev_list), i.e. both of them contain the same links, only that all_adj_list contains also non-neighbour device links. It's really a small change visible, currently, only for __netdev_adjacent_dev_insert/remove(), and doesn't change the main linked logic at all. Also, add some comments a fix a name collision in netdev_for_each_upper_dev_rcu() and rework the naming by the following rules: netdev_(all_)(upper|lower)_* If "all_" is present, then we work with the whole list of upper/lower devices, otherwise - only with direct neighbours. Uninline functions - to get better stack traces. CC: "David S. Miller" <[email protected]> CC: Eric Dumazet <[email protected]> CC: Jiri Pirko <[email protected]> CC: Alexander Duyck <[email protected]> CC: Cong Wang <[email protected]> Signed-off-by: Veaceslav Falico <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7863c05 commit 2f268f1

File tree

4 files changed

+129
-114
lines changed

4 files changed

+129
-114
lines changed

drivers/net/bonding/bond_alb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[])
10191019

10201020
/* loop through vlans and send one packet for each */
10211021
rcu_read_lock();
1022-
netdev_for_each_upper_dev_rcu(bond->dev, upper, iter) {
1022+
netdev_for_each_all_upper_dev_rcu(bond->dev, upper, iter) {
10231023
if (upper->priv_flags & IFF_802_1Q_VLAN)
10241024
alb_send_lp_vid(slave, mac_addr,
10251025
vlan_dev_vlan_id(upper));

drivers/net/bonding/bond_main.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,7 +2267,7 @@ static bool bond_has_this_ip(struct bonding *bond, __be32 ip)
22672267
return true;
22682268

22692269
rcu_read_lock();
2270-
netdev_for_each_upper_dev_rcu(bond->dev, upper, iter) {
2270+
netdev_for_each_all_upper_dev_rcu(bond->dev, upper, iter) {
22712271
if (ip == bond_confirm_addr(upper, 0, ip)) {
22722272
ret = true;
22732273
break;
@@ -2342,10 +2342,12 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
23422342
*
23432343
* TODO: QinQ?
23442344
*/
2345-
netdev_for_each_upper_dev_rcu(bond->dev, vlan_upper, vlan_iter) {
2345+
netdev_for_each_all_upper_dev_rcu(bond->dev, vlan_upper,
2346+
vlan_iter) {
23462347
if (!is_vlan_dev(vlan_upper))
23472348
continue;
2348-
netdev_for_each_upper_dev_rcu(vlan_upper, upper, iter) {
2349+
netdev_for_each_all_upper_dev_rcu(vlan_upper, upper,
2350+
iter) {
23492351
if (upper == rt->dst.dev) {
23502352
vlan_id = vlan_dev_vlan_id(vlan_upper);
23512353
rcu_read_unlock();
@@ -2358,7 +2360,7 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
23582360
* our upper vlans, then just search for any dev that
23592361
* matches, and in case it's a vlan - save the id
23602362
*/
2361-
netdev_for_each_upper_dev_rcu(bond->dev, upper, iter) {
2363+
netdev_for_each_all_upper_dev_rcu(bond->dev, upper, iter) {
23622364
if (upper == rt->dst.dev) {
23632365
/* if it's a vlan - get its VID */
23642366
if (is_vlan_dev(upper))

include/linux/netdevice.h

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,8 +1143,18 @@ struct net_device {
11431143
struct list_head dev_list;
11441144
struct list_head napi_list;
11451145
struct list_head unreg_list;
1146-
struct list_head upper_dev_list; /* List of upper devices */
1147-
struct list_head lower_dev_list;
1146+
1147+
/* directly linked devices, like slaves for bonding */
1148+
struct {
1149+
struct list_head upper;
1150+
struct list_head lower;
1151+
} adj_list;
1152+
1153+
/* all linked devices, *including* neighbours */
1154+
struct {
1155+
struct list_head upper;
1156+
struct list_head lower;
1157+
} all_adj_list;
11481158

11491159

11501160
/* currently active device features */
@@ -2813,15 +2823,15 @@ extern int bpf_jit_enable;
28132823
extern bool netdev_has_upper_dev(struct net_device *dev,
28142824
struct net_device *upper_dev);
28152825
extern bool netdev_has_any_upper_dev(struct net_device *dev);
2816-
extern struct net_device *netdev_upper_get_next_dev_rcu(struct net_device *dev,
2817-
struct list_head **iter);
2826+
extern struct net_device *netdev_all_upper_get_next_dev_rcu(struct net_device *dev,
2827+
struct list_head **iter);
28182828

28192829
/* iterate through upper list, must be called under RCU read lock */
2820-
#define netdev_for_each_upper_dev_rcu(dev, upper, iter) \
2821-
for (iter = &(dev)->upper_dev_list, \
2822-
upper = netdev_upper_get_next_dev_rcu(dev, &(iter)); \
2823-
upper; \
2824-
upper = netdev_upper_get_next_dev_rcu(dev, &(iter)))
2830+
#define netdev_for_each_all_upper_dev_rcu(dev, updev, iter) \
2831+
for (iter = &(dev)->all_adj_list.upper, \
2832+
updev = netdev_all_upper_get_next_dev_rcu(dev, &(iter)); \
2833+
updev; \
2834+
updev = netdev_all_upper_get_next_dev_rcu(dev, &(iter)))
28252835

28262836
extern struct net_device *netdev_master_upper_dev_get(struct net_device *dev);
28272837
extern struct net_device *netdev_master_upper_dev_get_rcu(struct net_device *dev);

0 commit comments

Comments
 (0)