From: Stanislav Fomichev <sdf.kernel@gmail.com>
To: Mina Almasry <almasrymina@google.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, andrew+netdev@lunn.ch,
edumazet@kernel.org, horms@kernel.org, corbet@lwn.net,
skhan@linuxfoundation.org, rdunlap@infradead.org,
michael.chan@broadcom.com, pavan.chebbi@broadcom.com,
sdf@fomichev.me, bobbyeshleman@meta.com, asml.silence@gmail.com,
daniel@iogearbox.net, razor@blackwall.org, leitao@debian.org,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net-next 6/7] net: devmem: size TX net_iovs from the dmabuf sg table
Date: Mon, 2 Nov 2026 15:37:54 -0800 [thread overview]
Message-ID: <aukcZBLBir_91hPr@devvm16445.scu0.facebook.com> (raw)
In-Reply-To: <CAHS8izMRtaL=kZaM29XQBodT8e+srppnK_DjNSTJnxFfNgG9aw@mail.gmail.com>
On 11/02, Mina Almasry wrote:
> On Mon, Nov 2, 2026 at 11:14 AM Stanislav Fomichev <sdf.kernel@gmail.com> wrote:
> >
> > PAGE_SIZE TX net_iovs cap devmem skbs at MAX_SKB_FRAGS pages (~68KB),
> > which makes BIG TCP ineffective.
> >
> > TX net_iovs only need to be DMA contiguous. Use the largest power of 2,
> > up to 2MB, which aligns every DMA segment of the dmabuf:
> > - 2MB hugepage-backed udmabufs get 2MB net_iovs
> > - no UAPI change, TX addresses are dmabuf offsets
> > - skbs are still bounded by TCP's size_goal, only frags get larger
> >
> > Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
> > ---
> > net/core/devmem.c | 28 ++++++++++++++++++++++++++--
> > net/core/netdev-genl.c | 2 +-
> > 2 files changed, 27 insertions(+), 3 deletions(-)
> >
> > diff --git a/net/core/devmem.c b/net/core/devmem.c
> > index 19c039ed2cb2..98c9594dbf99 100644
> > --- a/net/core/devmem.c
> > +++ b/net/core/devmem.c
> > @@ -181,6 +181,20 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
> > return err;
> > }
> >
> > +static bool net_devmem_sgt_aligned(struct sg_table *sgt, size_t size)
> > +{
> > + struct scatterlist *sg;
> > + unsigned int i;
> > +
> > + for_each_sgtable_dma_sg(sgt, sg, i) {
> > + if (!IS_ALIGNED(sg_dma_address(sg), size) ||
> > + !IS_ALIGNED(sg_dma_len(sg), size))
> > + return false;
> > + }
> > + return true;
> > +}
> > +
> > +/* niov_shift == 0 picks the net_iov size from the dmabuf, TX only */
> > struct net_devmem_dmabuf_binding *
> > net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,
> > struct device *dma_dev,
> > @@ -191,11 +205,11 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,
> > struct netlink_ext_ack *extack)
> > {
> > struct net_devmem_dmabuf_binding *binding;
> > - size_t niov_size = 1UL << niov_shift;
> > static u32 id_alloc_next;
> > struct scatterlist *sg;
> > struct dma_buf *dmabuf;
> > unsigned int sg_idx;
> > + size_t niov_size;
> > size_t niov_idx;
> > size_t i;
> > long err;
> > @@ -221,7 +235,6 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,
> > binding->tx_max_frag_size = dev->netmem_tx_max_frag_size;
> > write_pnet(&binding->net, sock_net(nl_sk));
> > binding->uid = sk_uid(nl_sk);
> > - binding->niov_shift = niov_shift;
> > xa_init_flags(&binding->bound_rxqs, XA_FLAGS_ALLOC);
> >
> > err = percpu_ref_init(&binding->ref,
> > @@ -266,6 +279,17 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,
> > goto err_unmap;
> > }
> >
> > + if (!niov_shift) {
> > + niov_size = SZ_2M;
> > + while (niov_size > PAGE_SIZE &&
> > + (!IS_ALIGNED(dmabuf->size, niov_size) ||
> > + !net_devmem_sgt_aligned(binding->sgt, niov_size)))
> > + niov_size /= 2;
> > + niov_shift = ilog2(niov_size);
> > + }
> > + binding->niov_shift = niov_shift;
> > + niov_size = 1UL << niov_shift;
> > +
>
> How come we're not checknig the largest supported size of the netdev here?
>
> Also, maybe should clarify in the cl with the largest supported size,
> is it actually only powers of 2 up to that power of 2? Or all sizes up
> to that (not-necassirly) power of 2 size?
I think these are a bit orthogonal, no? We can have niovs larger than
the HW can tx. If that's the case, we'll just sub-divide when we build
the skb. If we limit to the same chunk the device can handle here,
we might use 2 frags to send single chunk worth of data more often (offset
doesn't have to be aligned to the chunk size).
Assuming device can only send 16K, current patch:
[ 2MB ] 2BM niov
[ 16K ] sending 16K from that 2MB will use one chunk
Limiting chunks to device's chunk size:
[ 16K ][ 16K ] 16K niov
[ 16K ] sending 16K from offset 8K will have to use 2 frags
(obviously, the same thing can happen with 2MB chunks, but less often)
LMK if it does not sound convincing.
next prev parent reply other threads:[~2026-11-02 23:38 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 19:14 [PATCH net-next 0/7] net: devmem: size TX net_iovs from the dmabuf layout Stanislav Fomichev
2026-11-02 19:14 ` [PATCH net-next 1/7] bnxt_en: let the stack segment GSO skbs with too many frags Stanislav Fomichev
2026-11-02 19:14 ` [PATCH net-next 2/7] net: devmem: charge the frag length to TX skb truesize Stanislav Fomichev
2026-11-02 20:22 ` Mina Almasry
2026-11-02 23:23 ` Stanislav Fomichev
2026-11-02 19:14 ` [PATCH net-next 3/7] net: devmem: use niov_shift in net_devmem_get_niov_at() Stanislav Fomichev
2026-11-02 20:24 ` Mina Almasry
2026-11-02 19:14 ` [PATCH net-next 4/7] net: devmem: add a per-device netmem TX frag size limit Stanislav Fomichev
2026-11-02 20:31 ` Mina Almasry
2026-11-02 23:27 ` Stanislav Fomichev
2026-11-02 19:14 ` [PATCH net-next 5/7] bnxt_en: limit netmem TX frags to 32KB Stanislav Fomichev
2026-11-02 20:31 ` Mina Almasry
2026-11-02 19:14 ` [PATCH net-next 6/7] net: devmem: size TX net_iovs from the dmabuf sg table Stanislav Fomichev
2026-11-02 20:40 ` Mina Almasry
2026-11-02 23:37 ` Stanislav Fomichev [this message]
2026-11-03 2:33 ` Mina Almasry
2026-11-02 19:14 ` [PATCH net-next 7/7] selftests: drv-net: devmem: TX from a hugepage-backed dmabuf Stanislav Fomichev
2026-11-03 2:58 ` Mina Almasry
2026-11-02 20:07 ` [PATCH net-next 0/7] net: devmem: size TX net_iovs from the dmabuf layout Mina Almasry
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=aukcZBLBir_91hPr@devvm16445.scu0.facebook.com \
--to=sdf.kernel@gmail.com \
--cc=almasrymina@google.com \
--cc=andrew+netdev@lunn.ch \
--cc=asml.silence@gmail.com \
--cc=bobbyeshleman@meta.com \
--cc=corbet@lwn.net \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=leitao@debian.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=michael.chan@broadcom.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pavan.chebbi@broadcom.com \
--cc=razor@blackwall.org \
--cc=rdunlap@infradead.org \
--cc=sdf@fomichev.me \
--cc=skhan@linuxfoundation.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
all inboxes | Powered by JetHome®