From: Nikolay Aleksandrov <razor@blackwall.org>
To: Hangbin Liu <hangbin.liu@linux.dev>
Cc: Jay Vosburgh <jv@jvosburgh.net>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Hangbin Liu <liuhangbin@kylinos.cn>
Subject: Re: [PATCH net v3 2/2] bonding: fix u32 overflow in compute_gap()
Date: Wed, 19 Aug 2026 13:14:08 +0300 [thread overview]
Message-ID: <cce1b5dc-5f2d-4065-b171-e35e083d169d@blackwall.org> (raw)
In-Reply-To: <c89c5035-8c53-4104-9ca6-cbeff864c01a@blackwall.org>
On 19/08/2026 13:02, Nikolay Aleksandrov wrote:
> On 19/08/2026 12:51, Hangbin Liu wrote:
>> On Wed, Aug 19, 2026 at 11:35:29AM +0300, Nikolay Aleksandrov wrote:
>>> hmm why don't you change the way the reset is done? *untested* but in theory
>>> you could just record the values at a reset "moment" in reset unbalanced and
>>> just use the delta, so it becomes a reader and there is only 1 writer left (tx).
>>> Keep the counters only increasing (important), only record a snapshot at a reset
>>> moment, count current total bytes (sum all per-cpu data), decrement the previous
>>> total from it and use that as the "interval bytes" to div.
>>
>> Oh, you mean add another variable to track the total unbalanced load? e.g.
>>
>
> right, but without any locking because...
>
one more minor nit below
>> diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
>> index 659a77323444..a65be54049d3 100644
>> --- a/drivers/net/bonding/bond_alb.c
>> +++ b/drivers/net/bonding/bond_alb.c
>> @@ -1546,10 +1546,10 @@ netdev_tx_t bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
>> return bond_do_alb_xmit(skb, bond, tx_slave);
>> }
>> -static u64 reset_unbalanced_load(struct alb_bond_info *bond_info)
>> +static u64 reset_unbalanced_load(struct bonding *bond, struct alb_bond_info *bond_info)
>> {
>> struct unbalanced_load_stats *p;
>> - u64 tx_bytes, total_bytes = 0;
>> + u64 delta, tx_bytes, total_bytes = 0;
>> unsigned int start;
>> int i;
>> @@ -1560,14 +1560,15 @@ static u64 reset_unbalanced_load(struct alb_bond_info *bond_info)
>> tx_bytes = u64_stats_read(&p->tx_bytes);
>> } while (u64_stats_fetch_retry(&p->syncp, start));
>> - u64_stats_update_begin(&p->syncp);
>> - u64_stats_set(&p->tx_bytes, 0);
>> - u64_stats_update_end(&p->syncp);
>> -
>> total_bytes += tx_bytes;
>> }
>> - return div_u64(total_bytes, BOND_TLB_REBALANCE_INTERVAL);
>> + spin_lock_bh(&bond->mode_lock);
>> + delta = total_bytes - bond_info->total_unbalanced;
>> + bond_info->total_unbalanced = total_bytes;
>> + spin_unlock_bh(&bond->mode_lock);
>> +
>
> ... there should be only 1 alb monitor running, no need to lock to keep it up-to-date
> also this is its only user, so remove the spinlock
>
>> + return div_u64(delta, BOND_TLB_REBALANCE_INTERVAL);
>> }
>> void bond_alb_monitor(struct work_struct *work)
>> @@ -1612,7 +1613,7 @@ void bond_alb_monitor(struct work_struct *work)
>> bond_for_each_slave_rcu(bond, slave, iter) {
>> tlb_clear_slave(bond, slave, 1);
>> if (slave == rcu_access_pointer(bond->curr_active_slave))
>> - SLAVE_TLB_INFO(slave).load = reset_unbalanced_load(bond_info);
>> + SLAVE_TLB_INFO(slave).load = reset_unbalanced_load(bond, bond_info);
>> }
>> atomic_set(&bond_info->tx_rebalance_counter, 0);
>> }
>> diff --git a/include/net/bond_alb.h b/include/net/bond_alb.h
>> index 51c083c76115..9d3877644286 100644
>> --- a/include/net/bond_alb.h
>> +++ b/include/net/bond_alb.h
>> @@ -131,6 +131,7 @@ struct unbalanced_load_stats {
>> struct alb_bond_info {
>> struct tlb_client_info *tx_hashtbl; /* Dynamically allocated */
>> struct unbalanced_load_stats __percpu *unbalanced_load;
>> + u64 total_unbalanced;
I'd name this prev_total_unbalanced or something similar since it is
the previous recorded value
>> atomic_t tx_rebalance_counter;
>> int lp_counter;
>> /* -------- rlb parameters -------- */
>>
>> This looks like an easy update :) Hope I didn't miss anything.
>>
>> Thanks
>> Hangbin
>
prev parent reply other threads:[~2026-08-19 10:14 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 8:47 [PATCH net v3 0/2] bonding: fix TLB load-tracking overflow on high-speed NICs Hangbin Liu
2026-08-18 8:47 ` [PATCH net v3 1/2] bonding: convert unbalanced_load to per-cpu state Hangbin Liu
2026-08-18 9:42 ` Nikolay Aleksandrov
2026-08-19 1:11 ` Hangbin Liu
2026-08-18 8:47 ` [PATCH net v3 2/2] bonding: fix u32 overflow in compute_gap() Hangbin Liu
2026-08-18 9:44 ` Nikolay Aleksandrov
2026-08-18 11:06 ` Nikolay Aleksandrov
2026-08-18 11:51 ` Nikolay Aleksandrov
2026-08-19 2:07 ` Hangbin Liu
2026-08-19 2:09 ` Hangbin Liu
2026-08-19 8:35 ` Nikolay Aleksandrov
2026-08-19 9:51 ` Hangbin Liu
2026-08-19 10:02 ` Nikolay Aleksandrov
2026-08-19 10:14 ` Nikolay Aleksandrov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cce1b5dc-5f2d-4065-b171-e35e083d169d@blackwall.org \
--to=razor@blackwall.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hangbin.liu@linux.dev \
--cc=horms@kernel.org \
--cc=jv@jvosburgh.net \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liuhangbin@kylinos.cn \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox