mbox series

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

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

Message

Björn Töpel Feb. 26, 2021, 11:23 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 3% improvement for XSKMAP
(sample:xdpsock/rx-drop), and 4% (sample:xdp_redirect_map) on my
machine.

More details in each commit.

@Jesper/Toke I dropped your Acked-by: on the first patch, since there
were major restucturing. Please have another look! Thanks!

Changelog:
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/


Cheers,
Björn

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     |  39 +++++++-
 include/net/xdp_sock.h     |  19 ----
 include/trace/events/xdp.h |  66 ++++++++-----
 kernel/bpf/cpumap.c        |  10 +-
 kernel/bpf/devmap.c        |  19 +++-
 kernel/bpf/verifier.c      |  11 ++-
 net/core/filter.c          | 183 ++++++++++++-------------------------
 net/xdp/xskmap.c           |  20 +++-
 9 files changed, 195 insertions(+), 198 deletions(-)


base-commit: 9c8f21e6f8856a96634e542a58ef3abf27486801

Comments

Toke Høiland-Jørgensen Feb. 26, 2021, 11:35 a.m. UTC | #1
Björn Töpel <bjorn.topel@gmail.com> writes:

> 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 3% improvement for XSKMAP
> (sample:xdpsock/rx-drop), and 4% (sample:xdp_redirect_map) on my
> machine.
>
> More details in each commit.
>
> @Jesper/Toke I dropped your Acked-by: on the first patch, since there
> were major restucturing. Please have another look! Thanks!

Will do! Did you update the performance numbers above after that change?

-Toke
Björn Töpel Feb. 26, 2021, 11:38 a.m. UTC | #2
On 2021-02-26 12:35, Toke Høiland-Jørgensen wrote:
> Björn Töpel <bjorn.topel@gmail.com> writes:
> 
>> 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 3% improvement for XSKMAP
>> (sample:xdpsock/rx-drop), and 4% (sample:xdp_redirect_map) on my
>> machine.
>>
>> More details in each commit.
>>
>> @Jesper/Toke I dropped your Acked-by: on the first patch, since there
>> were major restucturing. Please have another look! Thanks!
> 
> Will do! Did you update the performance numbers above after that change?
>

I did. The XSKMAP performance stayed the same (no surprise, since the
code was the same). However, for the DEVMAP the v4 got rid of a call, so
it *should* be a bit better, but for some reason it didn't show on my
machine.


Björn
Toke Høiland-Jørgensen Feb. 26, 2021, 11:43 a.m. UTC | #3
Björn Töpel <bjorn.topel@intel.com> writes:

> On 2021-02-26 12:35, Toke Høiland-Jørgensen wrote:
>> Björn Töpel <bjorn.topel@gmail.com> writes:
>> 
>>> 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 3% improvement for XSKMAP
>>> (sample:xdpsock/rx-drop), and 4% (sample:xdp_redirect_map) on my
>>> machine.
>>>
>>> More details in each commit.
>>>
>>> @Jesper/Toke I dropped your Acked-by: on the first patch, since there
>>> were major restucturing. Please have another look! Thanks!
>> 
>> Will do! Did you update the performance numbers above after that change?
>>
>
> I did. The XSKMAP performance stayed the same (no surprise, since the
> code was the same). However, for the DEVMAP the v4 got rid of a call, so
> it *should* be a bit better, but for some reason it didn't show on my
> machine.

Alright, fair enough - pesky real world not lining up with expectations!
Maybe Jesper has additional suggestions, but I can live with the 4%
improvement ;)

-Toke