netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jesper Dangaard Brouer <brouer@redhat.com>
To: "Björn Töpel" <bjorn.topel@gmail.com>
Cc: magnus.karlsson@intel.com, magnus.karlsson@gmail.com,
	alexander.h.duyck@intel.com, alexander.duyck@gmail.com,
	ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org,
	jesse.brandeburg@intel.com, anjali.singhai@intel.com,
	peter.waskiewicz.jr@intel.com,
	"Björn Töpel" <bjorn.topel@intel.com>,
	michael.lundkvist@ericsson.com, willemdebruijn.kernel@gmail.com,
	john.fastabend@gmail.com, jakub.kicinski@netronome.com,
	neerav.parikh@intel.com, mykyta.iziumtsev@linaro.org,
	francois.ozog@linaro.org, ilias.apalodimas@linaro.org,
	brian.brooks@linaro.org, u9012063@gmail.com,
	pavel@fastnetmon.com, qi.z.zhang@intel.com, brouer@redhat.com
Subject: Re: [PATCH bpf-next 01/11] xdp: implement convert_to_xdp_frame for MEM_TYPE_ZERO_COPY
Date: Tue, 28 Aug 2018 16:11:02 +0200	[thread overview]
Message-ID: <20180828161102.45a00204@redhat.com> (raw)
In-Reply-To: <20180828124435.30578-2-bjorn.topel@gmail.com>

On Tue, 28 Aug 2018 14:44:25 +0200
Björn Töpel <bjorn.topel@gmail.com> wrote:

> From: Björn Töpel <bjorn.topel@intel.com>
> 
> This commit adds proper MEM_TYPE_ZERO_COPY support for
> convert_to_xdp_frame. Converting a MEM_TYPE_ZERO_COPY xdp_buff to an
> xdp_frame is done by transforming the MEM_TYPE_ZERO_COPY buffer into a
> MEM_TYPE_PAGE_ORDER0 frame. This is costly, and in the future it might
> make sense to implement a more sophisticated thread-safe alloc/free
> scheme for MEM_TYPE_ZERO_COPY, so that no allocation and copy is
> required in the fast-path.

This is going to be slow. Especially the dev_alloc_page() call, which
for small frames is likely going to be slower than the data copy.
I guess this is a good first step, but I do hope we will circle back and
optimize this later.  (It would also be quite easy to use
MEM_TYPE_PAGE_POOL instead to get page recycling in devmap redirect case).

I would have liked the MEM_TYPE_ZERO_COPY frame to travel one level
deeper into the redirect-core code.  Allowing devmap to send these
frame without copy, and allow cpumap to do the dev_alloc_page() call
(+copy) on the remote CPU.


> Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
> ---
>  include/net/xdp.h |  5 +++--
>  net/core/xdp.c    | 39 +++++++++++++++++++++++++++++++++++++++
>  2 files changed, 42 insertions(+), 2 deletions(-)
> 
> diff --git a/include/net/xdp.h b/include/net/xdp.h
> index 76b95256c266..0d5c6fb4b2e2 100644
> --- a/include/net/xdp.h
> +++ b/include/net/xdp.h
> @@ -91,6 +91,8 @@ static inline void xdp_scrub_frame(struct xdp_frame *frame)
>  	frame->dev_rx = NULL;
>  }
>  
> +struct xdp_frame *xdp_convert_zc_to_xdp_frame(struct xdp_buff *xdp);
> +
>  /* Convert xdp_buff to xdp_frame */
>  static inline
>  struct xdp_frame *convert_to_xdp_frame(struct xdp_buff *xdp)
> @@ -99,9 +101,8 @@ struct xdp_frame *convert_to_xdp_frame(struct xdp_buff *xdp)
>  	int metasize;
>  	int headroom;
>  
> -	/* TODO: implement clone, copy, use "native" MEM_TYPE */
>  	if (xdp->rxq->mem.type == MEM_TYPE_ZERO_COPY)
> -		return NULL;
> +		return xdp_convert_zc_to_xdp_frame(xdp);
>  
>  	/* Assure headroom is available for storing info */
>  	headroom = xdp->data - xdp->data_hard_start;
> diff --git a/net/core/xdp.c b/net/core/xdp.c
> index 89b6785cef2a..be6cb2f0e722 100644
> --- a/net/core/xdp.c
> +++ b/net/core/xdp.c
> @@ -398,3 +398,42 @@ void xdp_attachment_setup(struct xdp_attachment_info *info,
>  	info->flags = bpf->flags;
>  }
>  EXPORT_SYMBOL_GPL(xdp_attachment_setup);
> +
> +struct xdp_frame *xdp_convert_zc_to_xdp_frame(struct xdp_buff *xdp)
> +{
> +	unsigned int metasize, headroom, totsize;
> +	void *addr, *data_to_copy;
> +	struct xdp_frame *xdpf;
> +	struct page *page;
> +
> +	/* Clone into a MEM_TYPE_PAGE_ORDER0 xdp_frame. */
> +	metasize = xdp_data_meta_unsupported(xdp) ? 0 :
> +		   xdp->data - xdp->data_meta;
> +	headroom = xdp->data - xdp->data_hard_start;
> +	totsize = xdp->data_end - xdp->data + metasize;
> +
> +	if (sizeof(*xdpf) + totsize > PAGE_SIZE)
> +		return NULL;
> +
> +	page = dev_alloc_page();
> +	if (!page)
> +		return NULL;
> +
> +	addr = page_to_virt(page);
> +	xdpf = addr;
> +	memset(xdpf, 0, sizeof(*xdpf));
> +
> +	addr += sizeof(*xdpf);
> +	data_to_copy = metasize ? xdp->data_meta : xdp->data;
> +	memcpy(addr, data_to_copy, totsize);
> +
> +	xdpf->data = addr + metasize;
> +	xdpf->len = totsize - metasize;
> +	xdpf->headroom = 0;
> +	xdpf->metasize = metasize;
> +	xdpf->mem.type = MEM_TYPE_PAGE_ORDER0;
> +
> +	xdp_return_buff(xdp);
> +	return xdpf;
> +}
> +EXPORT_SYMBOL_GPL(xdp_convert_zc_to_xdp_frame);



-- 
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer

  reply	other threads:[~2018-08-28 18:03 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-28 12:44 [PATCH bpf-next 00/11] AF_XDP zero-copy support for i40e Björn Töpel
2018-08-28 12:44 ` [PATCH bpf-next 01/11] xdp: implement convert_to_xdp_frame for MEM_TYPE_ZERO_COPY Björn Töpel
2018-08-28 14:11   ` Jesper Dangaard Brouer [this message]
2018-08-28 17:42     ` Björn Töpel
2018-08-29 18:06   ` [bpf-next, " Maciek Fijalkowski
2018-08-28 12:44 ` [PATCH bpf-next 02/11] xdp: export xdp_rxq_info_unreg_mem_model Björn Töpel
2018-08-28 12:44 ` [PATCH bpf-next 03/11] xsk: expose xdp_umem_get_{data,dma} to drivers Björn Töpel
2018-08-28 12:44 ` [PATCH bpf-next 04/11] net: add napi_if_scheduled_mark_missed Björn Töpel
2018-08-28 12:44 ` [PATCH bpf-next 05/11] i40e: added queue pair disable/enable functions Björn Töpel
2018-08-28 12:44 ` [PATCH bpf-next 06/11] i40e: refactor Rx path for re-use Björn Töpel
2018-08-28 12:44 ` [PATCH bpf-next 07/11] i40e: move common Rx functions to i40e_txrx_common.h Björn Töpel
2018-08-28 12:44 ` [PATCH bpf-next 08/11] i40e: add AF_XDP zero-copy Rx support Björn Töpel
2018-08-29 19:14   ` Jakub Kicinski
2018-08-30 12:06     ` Björn Töpel
2018-08-31  7:55       ` Jakub Kicinski
2018-08-29 19:22   ` Alexei Starovoitov
2018-08-28 12:44 ` [PATCH bpf-next 09/11] i40e: move common Tx functions to i40e_txrx_common.h Björn Töpel
2018-08-28 12:44 ` [PATCH bpf-next 10/11] i40e: add AF_XDP zero-copy Tx support Björn Töpel
2018-08-28 12:44 ` [PATCH bpf-next 11/11] samples/bpf: add -c/--copy -z/--zero-copy flags to xdpsock Björn Töpel
2018-08-29 12:44   ` Jesper Dangaard Brouer
2018-08-30 10:21     ` Björn Töpel
2018-08-28 12:50 ` [PATCH bpf-next 00/11] AF_XDP zero-copy support for i40e Björn Töpel
2018-08-29 16:12 ` Daniel Borkmann
2018-08-30  0:10   ` William Tu
2018-08-30  9:05   ` Björn Töpel
2018-08-29 19:19 ` [RFC] net: xsk: add a simple buffer reuse queue Jakub Kicinski
2018-08-31  8:34   ` Björn Töpel
2018-08-29 19:39 ` [PATCH bpf-next 00/11] AF_XDP zero-copy support for i40e Alexei Starovoitov

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=20180828161102.45a00204@redhat.com \
    --to=brouer@redhat.com \
    --cc=alexander.duyck@gmail.com \
    --cc=alexander.h.duyck@intel.com \
    --cc=anjali.singhai@intel.com \
    --cc=ast@kernel.org \
    --cc=bjorn.topel@gmail.com \
    --cc=bjorn.topel@intel.com \
    --cc=brian.brooks@linaro.org \
    --cc=daniel@iogearbox.net \
    --cc=francois.ozog@linaro.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jakub.kicinski@netronome.com \
    --cc=jesse.brandeburg@intel.com \
    --cc=john.fastabend@gmail.com \
    --cc=magnus.karlsson@gmail.com \
    --cc=magnus.karlsson@intel.com \
    --cc=michael.lundkvist@ericsson.com \
    --cc=mykyta.iziumtsev@linaro.org \
    --cc=neerav.parikh@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=pavel@fastnetmon.com \
    --cc=peter.waskiewicz.jr@intel.com \
    --cc=qi.z.zhang@intel.com \
    --cc=u9012063@gmail.com \
    --cc=willemdebruijn.kernel@gmail.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).