mbox series

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

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

Message

Björn Töpel March 8, 2021, 11:29 a.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 bpf_redirect_map() be a map operation,
where each map has its own bpf_redirect_map() implementation. 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 4% improvement for XSKMAP
(sample:xdpsock/rx-drop), and 8% (sample:xdp_redirect_map) on my
machine.

@Jesper/@Toke I kept your Acked-by: for patch 2. Let me know, if you
don't agree with that decision.

More details in each commit.

Changelog:
v5->v6:  Removed REDIR enum, and instead use map_id and map_type. (Daniel)
         Applied Daniel's fixups on patch 1. (Daniel)
v4->v5:  Renamed map operation to map_redirect. (Daniel)
v3->v4:  Made bpf_redirect_map() a map operation. (Daniel)
v2->v3:  Fix build when CONFIG_NET is not set. (lkp)
v1->v2:  Removed warning when CONFIG_BPF_SYSCALL was not set. (lkp)
         Cleaned up case-clause in xdp_do_generic_redirect_map(). (Toke)
         Re-added comment. (Toke)
rfc->v1: Use map_id, and remove bpf_clear_redirect_map(). (Toke)
         Get rid of the macro and use __always_inline. (Jesper)

rfc: https://lore.kernel.org/bpf/87im7fy9nc.fsf@toke.dk/ (Cover not on lore!)
v1:  https://lore.kernel.org/bpf/20210219145922.63655-1-bjorn.topel@gmail.com/
v2:  https://lore.kernel.org/bpf/20210220153056.111968-1-bjorn.topel@gmail.com/
v3:  https://lore.kernel.org/bpf/20210221200954.164125-3-bjorn.topel@gmail.com/
v4:  https://lore.kernel.org/bpf/20210226112322.144927-1-bjorn.topel@gmail.com/
v5:  https://lore.kernel.org/bpf/20210227122139.183284-1-bjorn.topel@gmail.com/

Björn Töpel (2):
  bpf, xdp: make bpf_redirect_map() a map operation
  bpf, xdp: restructure redirect actions

 include/linux/bpf.h        |  26 ++---
 include/linux/filter.h     |  31 +++++-
 include/net/xdp_sock.h     |  19 ----
 include/trace/events/xdp.h |  62 ++++++-----
 kernel/bpf/cpumap.c        |   9 +-
 kernel/bpf/devmap.c        |  17 ++-
 kernel/bpf/verifier.c      |  13 ++-
 net/core/filter.c          | 209 ++++++++++++++-----------------------
 net/xdp/xskmap.c           |  17 ++-
 9 files changed, 195 insertions(+), 208 deletions(-)


base-commit: 5e6d87315279db3abe69e2ebfd05fa8f5c014295

Comments

Daniel Borkmann March 10, 2021, 12:19 a.m. UTC | #1
On 3/8/21 12:29 PM, Björn Töpel wrote:
> 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 bpf_redirect_map() be a map operation,

> where each map has its own bpf_redirect_map() implementation. 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 4% improvement for XSKMAP

> (sample:xdpsock/rx-drop), and 8% (sample:xdp_redirect_map) on my

> machine.

> 

> @Jesper/@Toke I kept your Acked-by: for patch 2. Let me know, if you

> don't agree with that decision.

> 

> More details in each commit.

> 

> Changelog:

> v5->v6:  Removed REDIR enum, and instead use map_id and map_type. (Daniel)

>           Applied Daniel's fixups on patch 1. (Daniel)

> v4->v5:  Renamed map operation to map_redirect. (Daniel)

> v3->v4:  Made bpf_redirect_map() a map operation. (Daniel)

> v2->v3:  Fix build when CONFIG_NET is not set. (lkp)

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

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

>           Re-added comment. (Toke)

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

>           Get rid of the macro and use __always_inline. (Jesper)


Applied, thanks!
patchwork-bot+netdevbpf@kernel.org March 10, 2021, 12:20 a.m. UTC | #2
Hello:

This series was applied to bpf/bpf-next.git (refs/heads/master):

On Mon,  8 Mar 2021 12:29:05 +0100 you wrote:
> 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 bpf_redirect_map() be a map operation,

> where each map has its own bpf_redirect_map() implementation. This way

> the run-time lookup is avoided.

> 

> [...]


Here is the summary with links:
  - [bpf-next,v6,1/2] bpf, xdp: make bpf_redirect_map() a map operation
    https://git.kernel.org/bpf/bpf-next/c/e6a4750ffe9d
  - [bpf-next,v6,2/2] bpf, xdp: restructure redirect actions
    https://git.kernel.org/bpf/bpf-next/c/ee75aef23afe

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html