Re: [RFC v2 17/24] eth: bnxt: adjust the fill level of agg queues with larger buffers

From: Stanislav Fomichev
Date: Fri Aug 08 2025 - 14:03:36 EST


On 08/08, Pavel Begunkov wrote:
> From: Jakub Kicinski <kuba@xxxxxxxxxx>
>
> The driver tries to provision more agg buffers than header buffers
> since multiple agg segments can reuse the same header. The calculation
> / heuristic tries to provide enough pages for 65k of data for each header
> (or 4 frags per header if the result is too big). This calculation is
> currently global to the adapter. If we increase the buffer sizes 8x
> we don't want 8x the amount of memory sitting on the rings.
> Luckily we don't have to fill the rings completely, adjust
> the fill level dynamically in case particular queue has buffers
> larger than the global size.
>
> Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx>
> [pavel: rebase on top of agg_size_fac, assert agg_size_fac]
> Signed-off-by: Pavel Begunkov <asml.silence@xxxxxxxxx>
> ---
> drivers/net/ethernet/broadcom/bnxt/bnxt.c | 27 +++++++++++++++++++----
> 1 file changed, 23 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> index 40cfc48cd439..a00c2a829b6b 100644
> --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> @@ -3805,16 +3805,33 @@ static void bnxt_free_rx_rings(struct bnxt *bp)
> }
> }
>
> +static int bnxt_rx_agg_ring_fill_level(struct bnxt *bp,
> + struct bnxt_rx_ring_info *rxr)
> +{
> + /* User may have chosen larger than default rx_page_size,
> + * we keep the ring sizes uniform and also want uniform amount
> + * of bytes consumed per ring, so cap how much of the rings we fill.
> + */
> + int fill_level = bp->rx_agg_ring_size;
> +
> + if (rxr->rx_page_size > bp->rx_page_size)
> + fill_level /= rxr->rx_page_size / bp->rx_page_size;
> +
> + return fill_level;
> +}
> +
> static int bnxt_alloc_rx_page_pool(struct bnxt *bp,
> struct bnxt_rx_ring_info *rxr,
> int numa_node)
> {
> - const unsigned int agg_size_fac = PAGE_SIZE / BNXT_RX_PAGE_SIZE;
> + const unsigned int agg_size_fac = rxr->rx_page_size / BNXT_RX_PAGE_SIZE;
> const unsigned int rx_size_fac = PAGE_SIZE / SZ_4K;
> struct page_pool_params pp = { 0 };
> struct page_pool *pool;
>
> - pp.pool_size = bp->rx_agg_ring_size / agg_size_fac;

[..]

> + WARN_ON_ONCE(agg_size_fac == 0);

nit: do we need to make this if (WARN_ON_ONCE(...)) agg_size_fac = 1?
Otherwise you're gonna divide by zero on the next line. Or properly
return some EINVAL instead?

> +
> + pp.pool_size = bnxt_rx_agg_ring_fill_level(bp, rxr) / agg_size_fac;