Commit fb33ec01 authored by Jesper Dangaard Brouer's avatar Jesper Dangaard Brouer Committed by Jakub Kicinski

xdp: improve page_pool xdp_return performance

During LPC2022 I meetup with my page_pool co-maintainer Ilias. When
discussing page_pool code we realised/remembered certain optimizations
had not been fully utilised.

Since commit c07aea3e ("mm: add a signature in struct page") struct
page have a direct pointer to the page_pool object this page was
allocated from.

Thus, with this info it is possible to skip the rhashtable_lookup to
find the page_pool object in __xdp_return().

The rcu_read_lock can be removed as it was tied to xdp_mem_allocator.
The page_pool object is still safe to access as it tracks inflight pages
and (potentially) schedules final release from a work queue.

Created a micro benchmark of XDP redirecting from mlx5 into veth with
XDP_DROP bpf-prog on the peer veth device. This increased performance
6.5% from approx 8.45Mpps to 9Mpps corresponding to using 7 nanosec
(27 cycles at 3.8GHz) less per packet.
Suggested-by: default avatarIlias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: default avatarJesper Dangaard Brouer <brouer@redhat.com>
Acked-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
Reviewed-by: default avatarIlias Apalodimas <ilias.apalodimas@linaro.org>
Link: https://lore.kernel.org/r/166377993287.1737053.10258297257583703949.stgit@firesoulSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent c931b060
...@@ -375,19 +375,17 @@ EXPORT_SYMBOL_GPL(xdp_rxq_info_reg_mem_model); ...@@ -375,19 +375,17 @@ EXPORT_SYMBOL_GPL(xdp_rxq_info_reg_mem_model);
void __xdp_return(void *data, struct xdp_mem_info *mem, bool napi_direct, void __xdp_return(void *data, struct xdp_mem_info *mem, bool napi_direct,
struct xdp_buff *xdp) struct xdp_buff *xdp)
{ {
struct xdp_mem_allocator *xa;
struct page *page; struct page *page;
switch (mem->type) { switch (mem->type) {
case MEM_TYPE_PAGE_POOL: case MEM_TYPE_PAGE_POOL:
rcu_read_lock();
/* mem->id is valid, checked in xdp_rxq_info_reg_mem_model() */
xa = rhashtable_lookup(mem_id_ht, &mem->id, mem_id_rht_params);
page = virt_to_head_page(data); page = virt_to_head_page(data);
if (napi_direct && xdp_return_frame_no_direct()) if (napi_direct && xdp_return_frame_no_direct())
napi_direct = false; napi_direct = false;
page_pool_put_full_page(xa->page_pool, page, napi_direct); /* No need to check ((page->pp_magic & ~0x3UL) == PP_SIGNATURE)
rcu_read_unlock(); * as mem->type knows this a page_pool page
*/
page_pool_put_full_page(page->pp, page, napi_direct);
break; break;
case MEM_TYPE_PAGE_SHARED: case MEM_TYPE_PAGE_SHARED:
page_frag_free(data); page_frag_free(data);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment