mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jacob Keller <jacob.e.keller@intel.com>
To: Mingrui Cui <mingruic@outlook.com>
Cc: <andrew+netdev@lunn.ch>, <davem@davemloft.net>,
	<dtatulea@nvidia.com>, <edumazet@google.com>, <kuba@kernel.org>,
	<leon@kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-rdma@vger.kernel.org>, <mbloch@nvidia.com>,
	<netdev@vger.kernel.org>, <pabeni@redhat.com>,
	<saeedm@nvidia.com>, <tariqt@nvidia.com>
Subject: Re: [PATCH net v2] net/mlx5e: Make DEFAULT_FRAG_SIZE relative to page size
Date: Wed, 15 Oct 2025 10:36:10 -0700	[thread overview]
Message-ID: <7314721e-3822-43d1-b9bc-acc1e56d610d@intel.com> (raw)
In-Reply-To: <MN6PR16MB545089E086BF99087773B76EB7E8A@MN6PR16MB5450.namprd16.prod.outlook.com>


[-- Attachment #1.1: Type: text/plain, Size: 3772 bytes --]



On 10/15/2025 5:32 AM, Mingrui Cui wrote:
> That's all the effects of changing DEFAULT_FRAG_SIZE. DEFAULT_FRAG_SIZE is only
> used as the initial value for frag_size_max. It is primarily used to calculate
> frag_size and frag_stride in arr of mlx5e_rq_frags_info, representing the actual
> data size and the size used for page allocation, respectively. In
> mlx5e_init_frags_partition(), an mlx5e_wqe_frag_info is allocated for each
> fragment according to its frag_stride, which determines the layout of fragments
> on a page.

Right.

> 
>>>  static int mlx5e_build_rq_frags_info(struct mlx5_core_dev *mdev,
>>>  				     struct mlx5e_params *params,
>>> @@ -756,18 +756,13 @@ static int mlx5e_build_rq_frags_info(struct mlx5_=
>> core_dev *mdev,
>>>  		/* No WQE can start in the middle of a page. */
>>>  		info->wqe_index_mask =3D 0;
>>>  	} else {
>>> -		/* PAGE_SIZEs starting from 8192 don't use 2K-sized fragments,
>>> -		 * because there would be more than MLX5E_MAX_RX_FRAGS of them.
>>> -		 */
>>> -		WARN_ON(PAGE_SIZE !=3D 2 * DEFAULT_FRAG_SIZE);
>>> -
>>
>> So previously we would warn, but now we just fix the DEFAULT_FRAG_SIZE
>> so this warning is redundant.. Ok.
>>
>>>  		/* Odd number of fragments allows to pack the last fragment of
>>>  		 * the previous WQE and the first fragment of the next WQE into
>>>  		 * the same page.
>>> -		 * As long as DEFAULT_FRAG_SIZE is 2048, and MLX5E_MAX_RX_FRAGS
>>> -		 * is 4, the last fragment can be bigger than the rest only if
>>> -		 * it's the fourth one, so WQEs consisting of 3 fragments will
>>> -		 * always share a page.
>>> +		 * As long as DEFAULT_FRAG_SIZE is (PAGE_SIZE / 2), and
>>> +		 * MLX5E_MAX_RX_FRAGS is 4, the last fragment can be bigger than
>>> +		 * the rest only if it's the fourth one, so WQEs consisting of 3
>>> +		 * fragments will always share a page.
>>>  		 * When a page is shared, WQE bulk size is 2, otherwise just 1.
>>>  		 */
>>>  		info->wqe_index_mask =3D info->num_frags % 2;
>>
>> Would it be possible to fix the other logic so that it works for a
>> DEFAULT_FRAG_SIZE of 2k on 8K pages? I guess if there's no negative to
>> increasing the frag size then this fix makes sense since it is simple.
> 
> To maintain 2K DEFAULT_FRAG_SIZE on 8K pages, one of two alternatives would be
> necessary: either find a method to calculate the occurrence period of
> page-aligned WQEs for the current MTU to replace wqe_index_mask, or use a more
> complex logic to manage fragment allocation and release on shared pages to avoid
> conflicts. This would make the page allocation logic for 8K pages significantly
> different from the 4K page case. Therefore, I believe directly modifying
> DEFAULT_FRAG_SIZE is a cleaner solution.
> 

Makes sense. The cost of the more complex logic doesn't seem worth it.

> Please note that frag_size_max is not fixed at 2048. If the current MTU exceeds
> the maximum size that 2K fragments can store, frag_size_max will be set to
> PAGE_SIZE. Therefore, changing DEFAULT_FRAG_SIZE to PAGE_SIZE/2 should
> theoretically be safe. The only downside is a potential for slightly more wasted
> space when filling a page.

Ok.
> 
>> I guess the noted fixed commit limits to 4 fragments, but it make some
>> assumptions that were wrong for 8K pages?
> 
> That's right. Specifically, on 4KB pages, once a small fragment and a 2K
> fragment are placed, there is no room for another 2K fragment. This results in
> the predictable page-sharing pattern for 3-fragment WQEs that breaks on larger
> page sizes.


Right.

Thanks for the explanation and answers, helps understand the logic and
solution.

For the patch:

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

  reply	other threads:[~2025-10-15 17:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-30 11:33 Mingrui Cui
2025-09-30 23:35 ` Jacob Keller
2025-10-15 12:32   ` Mingrui Cui
2025-10-15 17:36     ` Jacob Keller [this message]
2025-10-01 13:02 ` Dragos Tatulea
2025-10-15 13:02   ` Mingrui Cui

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=7314721e-3822-43d1-b9bc-acc1e56d610d@intel.com \
    --to=jacob.e.keller@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=dtatulea@nvidia.com \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=mbloch@nvidia.com \
    --cc=mingruic@outlook.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=saeedm@nvidia.com \
    --cc=tariqt@nvidia.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

all inboxes | Powered by JetHome®