The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Hangbin Liu <hangbin.liu@linux.dev>
To: Nikolay Aleksandrov <razor@blackwall.org>
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 17:51:02 +0800	[thread overview]
Message-ID: <aoV8hvRlyRrFQobA@fedora> (raw)
In-Reply-To: <1ebd9c8a-5b7e-4ebb-9c7d-5b2b2fe4a675@blackwall.org>

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.

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);
+
+	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;
 	atomic_t		tx_rebalance_counter;
 	int			lp_counter;
 	/* -------- rlb parameters -------- */

This looks like an easy update :) Hope I didn't miss anything.

Thanks
Hangbin

  reply	other threads:[~2026-08-19  9:51 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 [this message]
2026-08-19 10:02                 ` Nikolay Aleksandrov
2026-08-19 10:14                   ` Nikolay Aleksandrov

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=aoV8hvRlyRrFQobA@fedora \
    --to=hangbin.liu@linux.dev \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --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 \
    --cc=razor@blackwall.org \
    /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