Skip to content

Commit c8a039a

Browse files
magnus-karlssonborkmann
authored andcommitted
samples/bpf: Optimize l2fwd performance in xdpsock
Optimize the throughput performance of the l2fwd sub-app in the xdpsock sample application by removing a duplicate syscall and increasing the size of the fill ring. The latter needs some further explanation. We recommend that you set the fill ring size >= HW RX ring size + AF_XDP RX ring size. Make sure you fill up the fill ring with buffers at regular intervals, and you will with this setting avoid allocation failures in the driver. These are usually quite expensive since drivers have not been written to assume that allocation failures are common. For regular sockets, kernel allocated memory is used that only runs out in OOM situations that should be rare. These two performance optimizations together lead to a 6% percent improvement for the l2fwd app on my machine. Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/1598619065-1944-1-git-send-email-magnus.karlsson@intel.com
1 parent acabf32 commit c8a039a

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

‎samples/bpf/xdpsock_user.c‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,16 @@ static struct xsk_umem_info *xsk_configure_umem(void *buffer, u64 size)
613613
{
614614
struct xsk_umem_info *umem;
615615
struct xsk_umem_config cfg = {
616-
.fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS,
616+
/* We recommend that you set the fill ring size >= HW RX ring size +
617+
* AF_XDP RX ring size. Make sure you fill up the fill ring
618+
* with buffers at regular intervals, and you will with this setting
619+
* avoid allocation failures in the driver. These are usually quite
620+
* expensive since drivers have not been written to assume that
621+
* allocation failures are common. For regular sockets, kernel
622+
* allocated memory is used that only runs out in OOM situations
623+
* that should be rare.
624+
*/
625+
.fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS * 2,
617626
.comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS,
618627
.frame_size = opt_xsk_frame_size,
619628
.frame_headroom = XSK_UMEM__DEFAULT_FRAME_HEADROOM,
@@ -640,13 +649,13 @@ static void xsk_populate_fill_ring(struct xsk_umem_info *umem)
640649
u32 idx;
641650

642651
ret = xsk_ring_prod__reserve(&umem->fq,
643-
XSK_RING_PROD__DEFAULT_NUM_DESCS, &idx);
644-
if (ret != XSK_RING_PROD__DEFAULT_NUM_DESCS)
652+
XSK_RING_PROD__DEFAULT_NUM_DESCS * 2, &idx);
653+
if (ret != XSK_RING_PROD__DEFAULT_NUM_DESCS * 2)
645654
exit_with_error(-ret);
646-
for (i = 0; i < XSK_RING_PROD__DEFAULT_NUM_DESCS; i++)
655+
for (i = 0; i < XSK_RING_PROD__DEFAULT_NUM_DESCS * 2; i++)
647656
*xsk_ring_prod__fill_addr(&umem->fq, idx++) =
648657
i * opt_xsk_frame_size;
649-
xsk_ring_prod__submit(&umem->fq, XSK_RING_PROD__DEFAULT_NUM_DESCS);
658+
xsk_ring_prod__submit(&umem->fq, XSK_RING_PROD__DEFAULT_NUM_DESCS * 2);
650659
}
651660

652661
static struct xsk_socket_info *xsk_configure_socket(struct xsk_umem_info *umem,
@@ -888,9 +897,6 @@ static inline void complete_tx_l2fwd(struct xsk_socket_info *xsk,
888897
if (!xsk->outstanding_tx)
889898
return;
890899

891-
if (!opt_need_wakeup || xsk_ring_prod__needs_wakeup(&xsk->tx))
892-
kick_tx(xsk);
893-
894900
ndescs = (xsk->outstanding_tx > opt_batch_size) ? opt_batch_size :
895901
xsk->outstanding_tx;
896902

0 commit comments

Comments
 (0)