mbox series

[bpf-next,v3,0/2] Optimize bpf_redirect_map()/xdp_do_redirect()

Message ID 20210221200954.164125-1-bjorn.topel@gmail.com
Headers show
Series Optimize bpf_redirect_map()/xdp_do_redirect() | expand

Message

Björn Töpel Feb. 21, 2021, 8:09 p.m. UTC
Hi XDP-folks,

This two patch series contain two optimizations for the
bpf_redirect_map() helper and the xdp_do_redirect() function.

The bpf_redirect_map() optimization is about avoiding the map lookup
dispatching. Instead of having a switch-statement and selecting the
correct lookup function, we let the verifier patch the
bpf_redirect_map() call to a specific lookup function. This way the
run-time lookup is avoided.

The xdp_do_redirect() patch restructures the code, so that the map
pointer indirection can be avoided.

Performance-wise I got 3% improvement for XSKMAP
(sample:xdpsock/rx-drop), and 4% (sample:xdp_redirect_map) on my
machine.

More details in each commit. Changes since the RFC is outlined in each
commit.


Cheers,
Björn


Björn Töpel (2):
  bpf, xdp: per-map bpf_redirect_map functions for XDP
  bpf, xdp: restructure redirect actions

 include/linux/bpf.h        |  21 ++--
 include/linux/filter.h     |  20 +++-
 include/net/xdp_sock.h     |   6 +-
 include/trace/events/xdp.h |  66 +++++++-----
 kernel/bpf/cpumap.c        |   3 +-
 kernel/bpf/devmap.c        |   5 +-
 kernel/bpf/verifier.c      |  17 ++-
 net/core/filter.c          | 216 ++++++++++++++++++-------------------
 net/xdp/xskmap.c           |   1 -
 9 files changed, 195 insertions(+), 160 deletions(-)


base-commit: 7b1e385c9a488de9291eaaa412146d3972e9dec5

Comments

Jesper Dangaard Brouer Feb. 22, 2021, 8:10 a.m. UTC | #1
On Sun, 21 Feb 2021 21:09:54 +0100
Björn Töpel <bjorn.topel@gmail.com> wrote:

> From: Björn Töpel <bjorn.topel@intel.com>

> 

> The XDP_REDIRECT implementations for maps and non-maps are fairly

> similar, but obviously need to take different code paths depending on

> if the target is using a map or not. Today, the redirect targets for

> XDP either uses a map, or is based on ifindex.

> 

> Here, an explicit redirect type is added to bpf_redirect_info, instead

> of the actual map. Redirect type, map item/ifindex, and the map_id (if

> any) is passed to xdp_do_redirect().

> 

> In addition to making the code easier to follow, using an explicit

> type in bpf_redirect_info has a slight positive performance impact by

> avoiding a pointer indirection for the map type lookup, and instead

> use the cacheline for bpf_redirect_info.

> 

> Since the actual map is not passed via bpf_redirect_info anymore, the

> map lookup is only done in the BPF helper. This means that the

> bpf_clear_redirect_map() function can be removed. The actual map item

> is RCU protected.

> 

> The bpf_redirect_info flags member is not used by XDP, and not

> read/written any more. The map member is only written to when

> required/used, and not unconditionally.

> 

> v1->v2 : Removed warning when CONFIG_BPF_SYSCALL was not set. (lkp)

>        : Cleaned up case-clause in xdp_do_generic_redirect_map(). (Toke)

> rfc->v1: Use map_id, and remove bpf_clear_redirect_map(). (Toke)

> 

> Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>

> Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>

> Signed-off-by: Björn Töpel <bjorn.topel@intel.com>

> ---

>  include/linux/bpf.h        |   1 +

>  include/linux/filter.h     |  11 ++-

>  include/trace/events/xdp.h |  66 +++++++++------

>  kernel/bpf/cpumap.c        |   1 -

>  kernel/bpf/devmap.c        |   1 -

>  net/core/filter.c          | 165 ++++++++++++++++---------------------

>  net/xdp/xskmap.c           |   1 -

>  7 files changed, 122 insertions(+), 124 deletions(-)


I like it! :-)

Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>


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