Skip to content

Commit aae8c28

Browse files
committed
Merge branch 'bonding_neighbours'
bonding: use neighbours instead of own lists Veaceslav Falico says: ==================== This patchset introduces all the needed infrastructure, on top of current adjacent lists, to be able to remove bond's slave_list/slave->list. The overhead in memory/CPU is minimal, and after the patchset bonding can rely on its slave-related functions, given the proper locking. I've done some netperf benchmarks on a vm, and the delta was about 0.1gbps for 35gbps as a whole, so no speed fluctuations. It also automatically creates lower/upper and master symlinks in dev's sysfs directory. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 4ed377e + 5831d66 commit aae8c28

11 files changed

Lines changed: 638 additions & 444 deletions

File tree

‎drivers/net/bonding/bond_3ad.c‎

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,7 +2117,7 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
21172117
read_lock(&bond->lock);
21182118

21192119
//check if there are any slaves
2120-
if (list_empty(&bond->slave_list))
2120+
if (!bond_has_slaves(bond))
21212121
goto re_arm;
21222122

21232123
// check if agg_select_timer timer after initialize is timed out
@@ -2417,14 +2417,15 @@ int bond_3ad_get_active_agg_info(struct bonding *bond, struct ad_info *ad_info)
24172417

24182418
int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
24192419
{
2420-
struct slave *slave, *start_at;
24212420
struct bonding *bond = netdev_priv(dev);
2422-
int slave_agg_no;
2423-
int slaves_in_agg;
2424-
int agg_id;
2425-
int i;
2421+
struct slave *slave, *first_ok_slave;
2422+
struct aggregator *agg;
24262423
struct ad_info ad_info;
2424+
struct list_head *iter;
2425+
int slaves_in_agg;
2426+
int slave_agg_no;
24272427
int res = 1;
2428+
int agg_id;
24282429

24292430
read_lock(&bond->lock);
24302431
if (__bond_3ad_get_active_agg_info(bond, &ad_info)) {
@@ -2437,20 +2438,28 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
24372438
agg_id = ad_info.aggregator_id;
24382439

24392440
if (slaves_in_agg == 0) {
2440-
/*the aggregator is empty*/
24412441
pr_debug("%s: Error: active aggregator is empty\n", dev->name);
24422442
goto out;
24432443
}
24442444

24452445
slave_agg_no = bond->xmit_hash_policy(skb, slaves_in_agg);
2446+
first_ok_slave = NULL;
24462447

2447-
bond_for_each_slave(bond, slave) {
2448-
struct aggregator *agg = SLAVE_AD_INFO(slave).port.aggregator;
2448+
bond_for_each_slave(bond, slave, iter) {
2449+
agg = SLAVE_AD_INFO(slave).port.aggregator;
2450+
if (!agg || agg->aggregator_identifier != agg_id)
2451+
continue;
24492452

2450-
if (agg && (agg->aggregator_identifier == agg_id)) {
2453+
if (slave_agg_no >= 0) {
2454+
if (!first_ok_slave && SLAVE_IS_OK(slave))
2455+
first_ok_slave = slave;
24512456
slave_agg_no--;
2452-
if (slave_agg_no < 0)
2453-
break;
2457+
continue;
2458+
}
2459+
2460+
if (SLAVE_IS_OK(slave)) {
2461+
res = bond_dev_queue_xmit(bond, skb, slave->dev);
2462+
goto out;
24542463
}
24552464
}
24562465

@@ -2460,20 +2469,10 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
24602469
goto out;
24612470
}
24622471

2463-
start_at = slave;
2464-
2465-
bond_for_each_slave_from(bond, slave, i, start_at) {
2466-
int slave_agg_id = 0;
2467-
struct aggregator *agg = SLAVE_AD_INFO(slave).port.aggregator;
2468-
2469-
if (agg)
2470-
slave_agg_id = agg->aggregator_identifier;
2471-
2472-
if (SLAVE_IS_OK(slave) && agg && (slave_agg_id == agg_id)) {
2473-
res = bond_dev_queue_xmit(bond, skb, slave->dev);
2474-
break;
2475-
}
2476-
}
2472+
/* we couldn't find any suitable slave after the agg_no, so use the
2473+
* first suitable found, if found. */
2474+
if (first_ok_slave)
2475+
res = bond_dev_queue_xmit(bond, skb, first_ok_slave->dev);
24772476

24782477
out:
24792478
read_unlock(&bond->lock);
@@ -2515,11 +2514,12 @@ int bond_3ad_lacpdu_recv(const struct sk_buff *skb, struct bonding *bond,
25152514
void bond_3ad_update_lacp_rate(struct bonding *bond)
25162515
{
25172516
struct port *port = NULL;
2517+
struct list_head *iter;
25182518
struct slave *slave;
25192519
int lacp_fast;
25202520

25212521
lacp_fast = bond->params.lacp_fast;
2522-
bond_for_each_slave(bond, slave) {
2522+
bond_for_each_slave(bond, slave, iter) {
25232523
port = &(SLAVE_AD_INFO(slave).port);
25242524
__get_state_machine_lock(port);
25252525
if (lacp_fast)

‎drivers/net/bonding/bond_alb.c‎

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,14 @@ static long long compute_gap(struct slave *slave)
223223
static struct slave *tlb_get_least_loaded_slave(struct bonding *bond)
224224
{
225225
struct slave *slave, *least_loaded;
226+
struct list_head *iter;
226227
long long max_gap;
227228

228229
least_loaded = NULL;
229230
max_gap = LLONG_MIN;
230231

231232
/* Find the slave with the largest gap */
232-
bond_for_each_slave(bond, slave) {
233+
bond_for_each_slave(bond, slave, iter) {
233234
if (SLAVE_IS_OK(slave)) {
234235
long long gap = compute_gap(slave);
235236

@@ -382,30 +383,31 @@ static int rlb_arp_recv(const struct sk_buff *skb, struct bonding *bond,
382383
static struct slave *rlb_next_rx_slave(struct bonding *bond)
383384
{
384385
struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
385-
struct slave *rx_slave, *slave, *start_at;
386-
int i = 0;
387-
388-
if (bond_info->next_rx_slave)
389-
start_at = bond_info->next_rx_slave;
390-
else
391-
start_at = bond_first_slave(bond);
392-
393-
rx_slave = NULL;
386+
struct slave *before = NULL, *rx_slave = NULL, *slave;
387+
struct list_head *iter;
388+
bool found = false;
394389

395-
bond_for_each_slave_from(bond, slave, i, start_at) {
396-
if (SLAVE_IS_OK(slave)) {
397-
if (!rx_slave) {
398-
rx_slave = slave;
399-
} else if (slave->speed > rx_slave->speed) {
390+
bond_for_each_slave(bond, slave, iter) {
391+
if (!SLAVE_IS_OK(slave))
392+
continue;
393+
if (!found) {
394+
if (!before || before->speed < slave->speed)
395+
before = slave;
396+
} else {
397+
if (!rx_slave || rx_slave->speed < slave->speed)
400398
rx_slave = slave;
401-
}
402399
}
400+
if (slave == bond_info->rx_slave)
401+
found = true;
403402
}
403+
/* we didn't find anything after the current or we have something
404+
* better before and up to the current slave
405+
*/
406+
if (!rx_slave || (before && rx_slave->speed < before->speed))
407+
rx_slave = before;
404408

405-
if (rx_slave) {
406-
slave = bond_next_slave(bond, rx_slave);
407-
bond_info->next_rx_slave = slave;
408-
}
409+
if (rx_slave)
410+
bond_info->rx_slave = rx_slave;
409411

410412
return rx_slave;
411413
}
@@ -1019,7 +1021,7 @@ static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[])
10191021

10201022
/* loop through vlans and send one packet for each */
10211023
rcu_read_lock();
1022-
netdev_for_each_upper_dev_rcu(bond->dev, upper, iter) {
1024+
netdev_for_each_all_upper_dev_rcu(bond->dev, upper, iter) {
10231025
if (upper->priv_flags & IFF_802_1Q_VLAN)
10241026
alb_send_lp_vid(slave, mac_addr,
10251027
vlan_dev_vlan_id(upper));
@@ -1172,10 +1174,11 @@ static void alb_change_hw_addr_on_detach(struct bonding *bond, struct slave *sla
11721174
*/
11731175
static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slave *slave)
11741176
{
1175-
struct slave *tmp_slave1, *free_mac_slave = NULL;
11761177
struct slave *has_bond_addr = bond->curr_active_slave;
1178+
struct slave *tmp_slave1, *free_mac_slave = NULL;
1179+
struct list_head *iter;
11771180

1178-
if (list_empty(&bond->slave_list)) {
1181+
if (!bond_has_slaves(bond)) {
11791182
/* this is the first slave */
11801183
return 0;
11811184
}
@@ -1196,7 +1199,7 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav
11961199
/* The slave's address is equal to the address of the bond.
11971200
* Search for a spare address in the bond for this slave.
11981201
*/
1199-
bond_for_each_slave(bond, tmp_slave1) {
1202+
bond_for_each_slave(bond, tmp_slave1, iter) {
12001203
if (!bond_slave_has_mac(bond, tmp_slave1->perm_hwaddr)) {
12011204
/* no slave has tmp_slave1's perm addr
12021205
* as its curr addr
@@ -1246,15 +1249,16 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav
12461249
*/
12471250
static int alb_set_mac_address(struct bonding *bond, void *addr)
12481251
{
1249-
char tmp_addr[ETH_ALEN];
1250-
struct slave *slave;
1252+
struct slave *slave, *rollback_slave;
1253+
struct list_head *iter;
12511254
struct sockaddr sa;
1255+
char tmp_addr[ETH_ALEN];
12521256
int res;
12531257

12541258
if (bond->alb_info.rlb_enabled)
12551259
return 0;
12561260

1257-
bond_for_each_slave(bond, slave) {
1261+
bond_for_each_slave(bond, slave, iter) {
12581262
/* save net_device's current hw address */
12591263
memcpy(tmp_addr, slave->dev->dev_addr, ETH_ALEN);
12601264

@@ -1274,10 +1278,12 @@ static int alb_set_mac_address(struct bonding *bond, void *addr)
12741278
sa.sa_family = bond->dev->type;
12751279

12761280
/* unwind from head to the slave that failed */
1277-
bond_for_each_slave_continue_reverse(bond, slave) {
1278-
memcpy(tmp_addr, slave->dev->dev_addr, ETH_ALEN);
1279-
dev_set_mac_address(slave->dev, &sa);
1280-
memcpy(slave->dev->dev_addr, tmp_addr, ETH_ALEN);
1281+
bond_for_each_slave(bond, rollback_slave, iter) {
1282+
if (rollback_slave == slave)
1283+
break;
1284+
memcpy(tmp_addr, rollback_slave->dev->dev_addr, ETH_ALEN);
1285+
dev_set_mac_address(rollback_slave->dev, &sa);
1286+
memcpy(rollback_slave->dev->dev_addr, tmp_addr, ETH_ALEN);
12811287
}
12821288

12831289
return res;
@@ -1458,11 +1464,12 @@ void bond_alb_monitor(struct work_struct *work)
14581464
struct bonding *bond = container_of(work, struct bonding,
14591465
alb_work.work);
14601466
struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1467+
struct list_head *iter;
14611468
struct slave *slave;
14621469

14631470
read_lock(&bond->lock);
14641471

1465-
if (list_empty(&bond->slave_list)) {
1472+
if (!bond_has_slaves(bond)) {
14661473
bond_info->tx_rebalance_counter = 0;
14671474
bond_info->lp_counter = 0;
14681475
goto re_arm;
@@ -1480,7 +1487,7 @@ void bond_alb_monitor(struct work_struct *work)
14801487
*/
14811488
read_lock(&bond->curr_slave_lock);
14821489

1483-
bond_for_each_slave(bond, slave)
1490+
bond_for_each_slave(bond, slave, iter)
14841491
alb_send_learning_packets(slave, slave->dev->dev_addr);
14851492

14861493
read_unlock(&bond->curr_slave_lock);
@@ -1493,7 +1500,7 @@ void bond_alb_monitor(struct work_struct *work)
14931500

14941501
read_lock(&bond->curr_slave_lock);
14951502

1496-
bond_for_each_slave(bond, slave) {
1503+
bond_for_each_slave(bond, slave, iter) {
14971504
tlb_clear_slave(bond, slave, 1);
14981505
if (slave == bond->curr_active_slave) {
14991506
SLAVE_TLB_INFO(slave).load =
@@ -1599,13 +1606,13 @@ int bond_alb_init_slave(struct bonding *bond, struct slave *slave)
15991606
*/
16001607
void bond_alb_deinit_slave(struct bonding *bond, struct slave *slave)
16011608
{
1602-
if (!list_empty(&bond->slave_list))
1609+
if (bond_has_slaves(bond))
16031610
alb_change_hw_addr_on_detach(bond, slave);
16041611

16051612
tlb_clear_slave(bond, slave, 0);
16061613

16071614
if (bond->alb_info.rlb_enabled) {
1608-
bond->alb_info.next_rx_slave = NULL;
1615+
bond->alb_info.rx_slave = NULL;
16091616
rlb_clear_slave(bond, slave);
16101617
}
16111618
}
@@ -1669,7 +1676,7 @@ void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave
16691676
swap_slave = bond->curr_active_slave;
16701677
rcu_assign_pointer(bond->curr_active_slave, new_slave);
16711678

1672-
if (!new_slave || list_empty(&bond->slave_list))
1679+
if (!new_slave || !bond_has_slaves(bond))
16731680
return;
16741681

16751682
/* set the new curr_active_slave to the bonds mac address

‎drivers/net/bonding/bond_alb.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ struct alb_bond_info {
154154
u8 rx_ntt; /* flag - need to transmit
155155
* to all rx clients
156156
*/
157-
struct slave *next_rx_slave;/* next slave to be assigned
158-
* to a new rx client for
159-
*/
157+
struct slave *rx_slave;/* last slave to xmit from */
160158
u8 primary_is_promisc; /* boolean */
161159
u32 rlb_promisc_timeout_counter;/* counts primary
162160
* promiscuity time

0 commit comments

Comments
 (0)