RE: [PATCH net,v2] net: mana: Switch to page pool for jumbo frames
From: Haiyang Zhang
Date: Tue Mar 25 2025 - 14:11:47 EST
> -----Original Message-----
> From: Long Li <longli@xxxxxxxxxxxxx>
> Sent: Tuesday, March 25, 2025 1:06 PM
> To: Haiyang Zhang <haiyangz@xxxxxxxxxxxxx>; linux-hyperv@xxxxxxxxxxxxxxx;
> netdev@xxxxxxxxxxxxxxx
> Cc: Dexuan Cui <decui@xxxxxxxxxxxxx>; stephen@xxxxxxxxxxxxxxxxxx; KY
> Srinivasan <kys@xxxxxxxxxxxxx>; Paul Rosswurm <paulros@xxxxxxxxxxxxx>;
> olaf@xxxxxxxxx; vkuznets <vkuznets@xxxxxxxxxx>; davem@xxxxxxxxxxxxx;
> wei.liu@xxxxxxxxxx; edumazet@xxxxxxxxxx; kuba@xxxxxxxxxx;
> pabeni@xxxxxxxxxx; leon@xxxxxxxxxx; ssengar@xxxxxxxxxxxxxxxxxxx; linux-
> rdma@xxxxxxxxxxxxxxx; daniel@xxxxxxxxxxxxx; john.fastabend@xxxxxxxxx;
> bpf@xxxxxxxxxxxxxxx; ast@xxxxxxxxxx; hawk@xxxxxxxxxx; tglx@xxxxxxxxxxxxx;
> shradhagupta@xxxxxxxxxxxxxxxxxxx; jesse.brandeburg@xxxxxxxxx;
> andrew+netdev@xxxxxxx; linux-kernel@xxxxxxxxxxxxxxx;
> stable@xxxxxxxxxxxxxxx
> Subject: RE: [PATCH net,v2] net: mana: Switch to page pool for jumbo
> frames
>
>
>
> > -----Original Message-----
> > From: LKML haiyangz <lkmlhyz@xxxxxxxxxxxxx> On Behalf Of Haiyang Zhang
> > Sent: Tuesday, March 25, 2025 9:33 AM
> > To: linux-hyperv@xxxxxxxxxxxxxxx; netdev@xxxxxxxxxxxxxxx
> > Cc: Haiyang Zhang <haiyangz@xxxxxxxxxxxxx>; Dexuan Cui
> > <decui@xxxxxxxxxxxxx>; stephen@xxxxxxxxxxxxxxxxxx; KY Srinivasan
> > <kys@xxxxxxxxxxxxx>; Paul Rosswurm <paulros@xxxxxxxxxxxxx>;
> > olaf@xxxxxxxxx; vkuznets <vkuznets@xxxxxxxxxx>; davem@xxxxxxxxxxxxx;
> > wei.liu@xxxxxxxxxx; edumazet@xxxxxxxxxx; kuba@xxxxxxxxxx;
> > pabeni@xxxxxxxxxx; leon@xxxxxxxxxx; Long Li <longli@xxxxxxxxxxxxx>;
> > ssengar@xxxxxxxxxxxxxxxxxxx; linux-rdma@xxxxxxxxxxxxxxx;
> > daniel@xxxxxxxxxxxxx; john.fastabend@xxxxxxxxx; bpf@xxxxxxxxxxxxxxx;
> > ast@xxxxxxxxxx; hawk@xxxxxxxxxx; tglx@xxxxxxxxxxxxx;
> > shradhagupta@xxxxxxxxxxxxxxxxxxx; jesse.brandeburg@xxxxxxxxx;
> > andrew+netdev@xxxxxxx; linux-kernel@xxxxxxxxxxxxxxx;
> stable@xxxxxxxxxxxxxxx
> > Subject: [PATCH net,v2] net: mana: Switch to page pool for jumbo frames
> >
> > Frag allocators, such as netdev_alloc_frag(), were not designed to work
> for
> > fragsz > PAGE_SIZE.
> >
> > So, switch to page pool for jumbo frames instead of using page frag
> allocators.
> > This driver is using page pool for smaller MTUs already.
> >
> > Cc: stable@xxxxxxxxxxxxxxx
> > Fixes: 80f6215b450e ("net: mana: Add support for jumbo frame")
> > Signed-off-by: Haiyang Zhang <haiyangz@xxxxxxxxxxxxx>
> > ---
> > v2: updated the commit msg as suggested by Jakub Kicinski.
> >
> > ---
> > drivers/net/ethernet/microsoft/mana/mana_en.c | 46 ++++---------------
> > 1 file changed, 9 insertions(+), 37 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c
> > b/drivers/net/ethernet/microsoft/mana/mana_en.c
> > index 9a8171f099b6..4d41f4cca3d8 100644
> > --- a/drivers/net/ethernet/microsoft/mana/mana_en.c
> > +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
> > @@ -661,30 +661,16 @@ int mana_pre_alloc_rxbufs(struct mana_port_context
> > *mpc, int new_mtu, int num_qu
> > mpc->rxbpre_total = 0;
> >
> > for (i = 0; i < num_rxb; i++) {
> > - if (mpc->rxbpre_alloc_size > PAGE_SIZE) {
> > - va = netdev_alloc_frag(mpc->rxbpre_alloc_size);
> > - if (!va)
> > - goto error;
> > -
> > - page = virt_to_head_page(va);
> > - /* Check if the frag falls back to single page */
> > - if (compound_order(page) <
> > - get_order(mpc->rxbpre_alloc_size)) {
> > - put_page(page);
> > - goto error;
> > - }
> > - } else {
> > - page = dev_alloc_page();
> > - if (!page)
> > - goto error;
> > + page = dev_alloc_pages(get_order(mpc->rxbpre_alloc_size));
> > + if (!page)
> > + goto error;
> >
> > - va = page_to_virt(page);
> > - }
> > + va = page_to_virt(page);
> >
> > da = dma_map_single(dev, va + mpc->rxbpre_headroom,
> > mpc->rxbpre_datasize, DMA_FROM_DEVICE);
> > if (dma_mapping_error(dev, da)) {
> > - put_page(virt_to_head_page(va));
> > + put_page(page);
>
> Should we use __free_pages()?
Quote from doc: https://www.kernel.org/doc/html/next/core-api/mm-api.html
___free_pages():
"This function can free multi-page allocations that are not compound pages."
"If you want to use the page's reference count to decide when to free the
allocation, you should allocate a compound page, and use put_page() instead
of __free_pages()."
And, since dev_alloc_pages returns compound page for high order page, we
use put_page() which works for both compound & single page.
Thanks,
- Haiyang