bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Duyck <alexander.duyck@gmail.com>
To: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Cc: "Jesper Dangaard Brouer" <brouer@redhat.com>,
	"Jubran, Samih" <sameehj@amazon.com>,
	"Jeff Kirsher" <jeffrey.t.kirsher@intel.com>,
	Netdev <netdev@vger.kernel.org>,
	bpf@vger.kernel.org, zorik@amazon.com, akiyano@amazon.com,
	gtzalik@amazon.com, "Toke Høiland-Jørgensen" <toke@toke.dk>,
	"Daniel Borkmann" <borkmann@iogearbox.net>,
	"Alexei Starovoitov" <alexei.starovoitov@gmail.com>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"David Ahern" <dsahern@gmail.com>,
	"Willem de Bruijn" <willemdebruijn.kernel@gmail.com>,
	"Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
	"Lorenzo Bianconi" <lorenzo@kernel.org>,
	"Björn Töpel" <bjorn.topel@intel.com>,
	kuba@kernel.org
Subject: Re: [PATCH RFC v1 05/15] ixgbe: add XDP frame size to driver
Date: Wed, 18 Mar 2020 14:23:09 -0700	[thread overview]
Message-ID: <CAKgT0UeV7OHsu=E11QVrQ-HvUe83-ZL2Mo+CKg5Bw4v8REEoew@mail.gmail.com> (raw)
In-Reply-To: <20200318200300.GA18295@ranger.igk.intel.com>

On Wed, Mar 18, 2020 at 1:04 PM Maciej Fijalkowski
<maciej.fijalkowski@intel.com> wrote:
>
> On Tue, Mar 17, 2020 at 06:29:33PM +0100, Jesper Dangaard Brouer wrote:
> > The ixgbe driver uses different memory models depending on PAGE_SIZE at
> > compile time. For PAGE_SIZE 4K it uses page splitting, meaning for
> > normal MTU frame size is 2048 bytes (and headroom 192 bytes).
>
> To be clear the 2048 is the size of buffer given to HW and we slice it up
> in a following way:
> - 192 bytes dedicated for headroom
> - 1500 is max allowed MTU for this setup
> - 320 bytes for tailroom (skb shinfo)
>
> In case you go with higher MTU then 3K buffer would be used and it would
> came from order1 page and we still do the half split. Just FYI all of this
> is for PAGE_SIZE == 4k and L1$ size == 64.

True, but for most people this is the most common case since these are
the standard for x86.

> > For PAGE_SIZE larger than 4K, driver advance its rx_buffer->page_offset
> > with the frame size "truesize".
>
> Alex, couldn't we base the truesize here somehow on ixgbe_rx_bufsz() since
> these are the sizes that we are passing to hw? I must admit I haven't been
> in touch with systems with PAGE_SIZE > 4K.

With a page size greater than 4K we can actually get many more uses
out of a page by using the frame size to determine the truesize of the
packet. The truesize is the memory footprint currently being held by
the packet. So once the packet is filled we just have to add the
headroom and tailroom to whatever the hardware wrote instead of having
to use what we gave to the hardware. That gives us better efficiency,
if we used ixgbe_rx_bufsz() we would penalize small packets and that
in turn would likely hurt performance.

> >
> > When driver enable XDP it uses build_skb() which provides the necessary
> > tailroom for XDP-redirect.
>
> We still allow to load XDP prog when ring is not using build_skb(). I have
> a feeling that we should drop this case now.
>
> Alex/John/Bjorn WDYT?

The comment Jesper had about using using build_skb() when XDP is in
use is incorrect. The two are not correlated. The underlying buffer is
the same, however we drop the headroom and tailroom if we are in
_RX_LEGACY mode. We default to build_skb and the option of switching
to legacy Rx is controlled via the device private flags.

However with that said the change itself is mostly harmless, and
likely helps to resolve issues that would be seen if somebody were to
enable XDP while having the RX_LEGACY flag set.

> >
> > When XDP frame size doesn't depend on RX packet size (4K case), then
> > xdp.frame_sz can be updated once outside the main NAPI loop.
> >
> > Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
> > Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
> > ---
> >  drivers/net/ethernet/intel/ixgbe/ixgbe.h      |   17 +++++++++++++++++
> >  drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |   18 ++++++++++--------
> >  2 files changed, 27 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe.h b/drivers/net/ethernet/intel/ixgbe/ixgbe.h
> > index 2833e4f041ce..943b643b6ed8 100644
> > --- a/drivers/net/ethernet/intel/ixgbe/ixgbe.h
> > +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe.h
> > @@ -417,6 +417,23 @@ static inline unsigned int ixgbe_rx_pg_order(struct ixgbe_ring *ring)
> >  }
> >  #define ixgbe_rx_pg_size(_ring) (PAGE_SIZE << ixgbe_rx_pg_order(_ring))
> >
> > +static inline unsigned int ixgbe_rx_frame_truesize(struct ixgbe_ring *rx_ring,
> > +                                                unsigned int size)
> > +{
> > +     unsigned int truesize;
> > +
> > +#if (PAGE_SIZE < 8192)
> > +     truesize = ixgbe_rx_pg_size(rx_ring) / 2; /* Must be power-of-2 */
> > +#else
> > +     /* Notice XDP must use build_skb() mode */
> > +     truesize = ring_uses_build_skb(rx_ring) ?
> > +             SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) +
> > +             SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) :
> > +             SKB_DATA_ALIGN(size);
> > +#endif
> > +     return truesize;
> > +}
> > +
> >  #define IXGBE_ITR_ADAPTIVE_MIN_INC   2
> >  #define IXGBE_ITR_ADAPTIVE_MIN_USECS 10
> >  #define IXGBE_ITR_ADAPTIVE_MAX_USECS 126
> > diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> > index ea6834bae04c..f505ed8c9dc1 100644
> > --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> > +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> > @@ -2248,16 +2248,10 @@ static void ixgbe_rx_buffer_flip(struct ixgbe_ring *rx_ring,
> >                                struct ixgbe_rx_buffer *rx_buffer,
> >                                unsigned int size)
> >  {
> > +     unsigned int truesize = ixgbe_rx_frame_truesize(rx_ring, size);
> >  #if (PAGE_SIZE < 8192)
> > -     unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
> > -
> >       rx_buffer->page_offset ^= truesize;
> >  #else
> > -     unsigned int truesize = ring_uses_build_skb(rx_ring) ?
> > -                             SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) +
> > -                             SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) :
> > -                             SKB_DATA_ALIGN(size);
> > -
> >       rx_buffer->page_offset += truesize;
> >  #endif
> >  }
> > @@ -2291,6 +2285,11 @@ static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
> >
> >       xdp.rxq = &rx_ring->xdp_rxq;
> >
> > +     /* Frame size depend on rx_ring setup when PAGE_SIZE=4K */
> > +#if (PAGE_SIZE < 8192)
> > +     xdp.frame_sz = ixgbe_rx_frame_truesize(rx_ring, 0);
> > +#endif
> > +
> >       while (likely(total_rx_packets < budget)) {
> >               union ixgbe_adv_rx_desc *rx_desc;
> >               struct ixgbe_rx_buffer *rx_buffer;
> > @@ -2324,7 +2323,10 @@ static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
> >                       xdp.data_hard_start = xdp.data -
> >                                             ixgbe_rx_offset(rx_ring);
> >                       xdp.data_end = xdp.data + size;
> > -
> > +#if (PAGE_SIZE > 4096)
> > +                     /* At larger PAGE_SIZE, frame_sz depend on size */
> > +                     xdp.frame_sz = ixgbe_rx_frame_truesize(rx_ring, size);
> > +#endif
> >                       skb = ixgbe_run_xdp(adapter, rx_ring, &xdp);
> >               }
> >
> >
> >

  reply	other threads:[~2020-03-18 21:23 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-17 17:29 [PATCH RFC v1 00/15] XDP extend with knowledge of frame size Jesper Dangaard Brouer
2020-03-17 17:29 ` [PATCH RFC v1 01/15] xdp: add frame size to xdp_buff Jesper Dangaard Brouer
2020-03-17 20:42   ` Jakub Kicinski
2020-03-18  6:58     ` Jesper Dangaard Brouer
2020-03-17 17:29 ` [PATCH RFC v1 02/15] mvneta: add XDP frame size to driver Jesper Dangaard Brouer
2020-03-17 17:29 ` [PATCH RFC v1 03/15] bnxt: " Jesper Dangaard Brouer
2020-03-20 19:22   ` Andy Gospodarek
2020-03-23 14:18   ` Andy Gospodarek
2020-03-23 14:44     ` Jesper Dangaard Brouer
2020-03-17 17:29 ` [PATCH RFC v1 04/15] ixgbe: fix XDP redirect on archs with PAGE_SIZE above 4K Jesper Dangaard Brouer
2020-03-17 17:29 ` [PATCH RFC v1 05/15] ixgbe: add XDP frame size to driver Jesper Dangaard Brouer
2020-03-18 20:03   ` Maciej Fijalkowski
2020-03-18 21:23     ` Alexander Duyck [this message]
2020-03-20 21:44       ` Jesper Dangaard Brouer
2020-03-20 22:37         ` Alexander Duyck
2020-03-17 17:29 ` [PATCH RFC v1 06/15] sfc: fix XDP-redirect in this driver Jesper Dangaard Brouer
2020-03-17 17:29 ` [PATCH RFC v1 07/15] sfc: add XDP frame size Jesper Dangaard Brouer
2020-03-17 17:29 ` [PATCH RFC v1 08/15] xdp: allow bpf_xdp_adjust_tail() to grow packet size Jesper Dangaard Brouer
2020-03-17 17:29 ` [PATCH RFC v1 09/15] xdp: clear grow memory in bpf_xdp_adjust_tail() Jesper Dangaard Brouer
2020-03-17 20:38   ` Jakub Kicinski
2020-03-18  9:15   ` Toke Høiland-Jørgensen
2020-03-18 10:25     ` Jesper Dangaard Brouer
2020-03-19  5:35       ` Alexei Starovoitov
2020-03-17 17:29 ` [PATCH RFC v1 10/15] net: XDP-generic determining XDP frame size Jesper Dangaard Brouer
2020-03-17 17:30 ` [PATCH RFC v1 11/15] xdp: xdp_frame add member frame_sz and handle in convert_to_xdp_frame Jesper Dangaard Brouer
2020-03-17 17:30 ` [PATCH RFC v1 12/15] xdp: cpumap redirect use frame_sz and increase skb_tailroom Jesper Dangaard Brouer
2020-03-17 17:30 ` [PATCH RFC v1 13/15] tun: add XDP frame size Jesper Dangaard Brouer
2020-03-17 17:30 ` [PATCH RFC v1 14/15] veth: xdp using frame_sz in veth driver Jesper Dangaard Brouer
2020-03-17 17:30 ` [PATCH RFC v1 15/15] dpaa2-eth: add XDP frame size Jesper Dangaard Brouer

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='CAKgT0UeV7OHsu=E11QVrQ-HvUe83-ZL2Mo+CKg5Bw4v8REEoew@mail.gmail.com' \
    --to=alexander.duyck@gmail.com \
    --cc=akiyano@amazon.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=bjorn.topel@intel.com \
    --cc=borkmann@iogearbox.net \
    --cc=bpf@vger.kernel.org \
    --cc=brouer@redhat.com \
    --cc=dsahern@gmail.com \
    --cc=gtzalik@amazon.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jeffrey.t.kirsher@intel.com \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=maciej.fijalkowski@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=sameehj@amazon.com \
    --cc=toke@toke.dk \
    --cc=willemdebruijn.kernel@gmail.com \
    --cc=zorik@amazon.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;
as well as URLs for NNTP newsgroup(s).