Thread (15 messages) read the whole thread 15 messages, 4 authors, 2020-11-27
STALE2072d

[PATCH 3/3] xsk: set tx/rx the min entries

From: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Date: 2020-11-18 08:25:37
Also in: bpf, lkml
Subsystem: networking drivers, networking [general], the rest, xdp sockets (af_xdp) · Maintainers: Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds, Magnus Karlsson, Maciej Fijalkowski

We expect tx entries to be greater than twice the number of packets that
the network card can send at a time, so that when the remaining number
of the tx queue is less than half of the queue, it can be guaranteed
that there are recycled items in the cq that can be used.

At the same time, rx will not cause packet loss because it cannot
receive the packets uploaded by the network card at one time.

Of course, the 1024 here is only an estimated value, and the number of
packets sent by each network card at a time may be different.

Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
---
 include/uapi/linux/if_xdp.h | 2 ++
 net/xdp/xsk.c               | 2 ++
 2 files changed, 4 insertions(+)
diff --git a/include/uapi/linux/if_xdp.h b/include/uapi/linux/if_xdp.h
index a78a809..d55ba79 100644
--- a/include/uapi/linux/if_xdp.h
+++ b/include/uapi/linux/if_xdp.h
@@ -64,6 +64,8 @@ struct xdp_mmap_offsets {
 #define XDP_STATISTICS			7
 #define XDP_OPTIONS			8
 
+#define XDP_RXTX_RING_MIN_ENTRIES       1024
+
 struct xdp_umem_reg {
 	__u64 addr; /* Start of packet data area */
 	__u64 len; /* Length of packet data area */
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index bc3d4ece..e62c795 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -831,6 +831,8 @@ static int xsk_setsockopt(struct socket *sock, int level, int optname,
 			return -EINVAL;
 		if (copy_from_sockptr(&entries, optval, sizeof(entries)))
 			return -EFAULT;
+		if (entries < XDP_RXTX_RING_MIN_ENTRIES)
+			return -EINVAL;
 
 		mutex_lock(&xs->mutex);
 		if (xs->state != XSK_READY) {
-- 
1.8.3.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help