linux/net
Jason Xing 45e359be1c net: xsk: introduce XDP_MAX_TX_SKB_BUDGET setsockopt
This patch provides a setsockopt method to let applications leverage to
adjust how many descs to be handled at most in one send syscall. It
mitigates the situation where the default value (32) that is too small
leads to higher frequency of triggering send syscall.

Considering the prosperity/complexity the applications have, there is no
absolutely ideal suggestion fitting all cases. So keep 32 as its default
value like before.

The patch does the following things:
- Add XDP_MAX_TX_SKB_BUDGET socket option.
- Set max_tx_budget to 32 by default in the initialization phase as a
  per-socket granular control.
- Set the range of max_tx_budget as [32, xs->tx->nentries].

The idea behind this comes out of real workloads in production. We use a
user-level stack with xsk support to accelerate sending packets and
minimize triggering syscalls. When the packets are aggregated, it's not
hard to hit the upper bound (namely, 32). The moment user-space stack
fetches the -EAGAIN error number passed from sendto(), it will loop to try
again until all the expected descs from tx ring are sent out to the driver.
Enlarging the XDP_MAX_TX_SKB_BUDGET value contributes to less frequency of
sendto() and higher throughput/PPS.

Here is what I did in production, along with some numbers as follows:
For one application I saw lately, I suggested using 128 as max_tx_budget
because I saw two limitations without changing any default configuration:
1) XDP_MAX_TX_SKB_BUDGET, 2) socket sndbuf which is 212992 decided by
net.core.wmem_default. As to XDP_MAX_TX_SKB_BUDGET, the scenario behind
this was I counted how many descs are transmitted to the driver at one
time of sendto() based on [1] patch and then I calculated the
possibility of hitting the upper bound. Finally I chose 128 as a
suitable value because 1) it covers most of the cases, 2) a higher
number would not bring evident results. After twisting the parameters,
a stable improvement of around 4% for both PPS and throughput and less
resources consumption were found to be observed by strace -c -p xxx:
1) %time was decreased by 7.8%
2) error counter was decreased from 18367 to 572

[1]: https://lore.kernel.org/all/20250619093641.70700-1-kerneljasonxing@gmail.com/

Signed-off-by: Jason Xing <kernelxing@tencent.com>
Acked-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Link: https://patch.msgid.link/20250704160138.48677-1-kerneljasonxing@gmail.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2025-07-10 14:48:29 +02:00
..
6lowpan
9p netfs: Fix the request's work item to not require a ref 2025-05-21 14:35:20 +02:00
802 treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
8021q net: 802: Remove unused p8022 code 2025-04-22 07:04:02 -07:00
appletalk net: remove sock_i_uid() 2025-06-23 17:04:03 -07:00
atm atm: Release atm_dev_mutex after removing procfs in atm_dev_deregister(). 2025-06-25 16:43:39 -07:00
ax25 treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
batman-adv treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
bluetooth Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2025-07-04 08:03:18 +02:00
bpf selftests/bpf: Add test to access const void pointer argument in tracing program 2025-04-23 11:26:22 -07:00
bridge bridge: mcast: Fix use-after-free during router port configuration 2025-06-23 18:19:10 -07:00
caif caif: reduce stack size, again 2025-06-23 16:58:43 -07:00
can Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2025-06-12 10:09:10 -07:00
ceph A small CephFS encryption-related fix and a dead code cleanup. 2025-04-25 15:51:28 -07:00
core skbuff: Add MSG_MORE flag to optimize tcp large packet transmission 2025-07-09 19:25:57 -07:00
dcb
devlink devlink: Add new "clock_id" generic device param 2025-07-09 19:08:52 -07:00
dns_resolver
dsa net: dsa: tag_brcm: add support for legacy FCS tags 2025-06-17 17:52:01 -07:00
ethernet
ethtool net: ethtool: reduce indent for _rxfh_context ops 2025-07-08 11:56:40 -07:00
handshake net/handshake: Add new parameter 'HANDSHAKE_A_ACCEPT_KEYRING' 2025-07-08 15:31:44 +02:00
hsr treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
ieee802154 treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
ife
ipv4 net: ipconfig: convert timeouts to secs_to_jiffies() 2025-07-09 19:25:01 -07:00
ipv6 ipv6: Remove setsockopt_needs_rtnl(). 2025-07-08 18:32:39 -07:00
iucv
kcm net: splice: Drop unused @gfp 2025-07-08 08:37:15 -07:00
key net: remove sock_i_uid() 2025-06-23 17:04:03 -07:00
l2tp net: annotate races around sk->sk_uid 2025-06-23 17:04:03 -07:00
l3mdev net: fib_rules: Fix iif / oif matching on L3 master device 2025-04-15 17:54:56 -07:00
lapb treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
llc net: make sk->sk_rcvtimeo lockless 2025-06-23 17:05:12 -07:00
mac80211 Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2025-06-26 10:40:50 -07:00
mac802154
mctp net: mctp: test: Add tests for gateway routes 2025-07-08 12:39:24 +02:00
mpls mpls: Use rcu_dereference_rtnl() in mpls_route_input_rcu(). 2025-06-17 18:21:59 -07:00
mptcp tcp: move tcp_memory_allocated into net_aligned_data 2025-07-02 14:22:02 -07:00
ncsi net: ncsi: Fix buffer overflow in fetching version id 2025-06-12 18:21:59 -07:00
netfilter net: dst: annotate data-races around dst->obsolete 2025-07-02 14:32:29 -07:00
netlabel calipso: unlock rcu before returning -EAFNOSUPPORT 2025-06-05 08:03:38 -07:00
netlink netlink: spelling: fix appened -> appended in a comment 2025-07-08 08:42:39 -07:00
netrom treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
nfc Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2025-06-19 13:00:24 -07:00
nsh
openvswitch net: openvswitch: allow providing upcall pid for the 'execute' command 2025-07-07 14:30:39 -07:00
packet net: remove sock_i_uid() 2025-06-23 17:04:03 -07:00
phonet net: remove sock_i_uid() 2025-06-23 17:04:03 -07:00
psample
qrtr
rds rds: Correct spelling 2025-06-21 07:35:39 -07:00
rfkill
rose rose: fix dangling neighbour pointers in rose_rt_device_down() 2025-07-01 19:28:48 -07:00
rxrpc treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
sched net: account for encap headers in qdisc pkt len 2025-07-08 08:55:33 -07:00
sctp net: dst: annotate data-races around dst->obsolete 2025-07-02 14:32:29 -07:00
shaper
smc net/smc: convert timeouts to secs_to_jiffies() 2025-07-09 19:25:01 -07:00
strparser net: make sk->sk_rcvtimeo lockless 2025-06-23 17:05:12 -07:00
sunrpc sunrpc: fix loop in gss seqno cache 2025-06-23 11:01:15 -04:00
switchdev net: switchdev: Convert blocking notification chain to a raw one 2025-03-11 11:30:28 +01:00
tipc net: remove sock_i_uid() 2025-06-23 17:04:03 -07:00
tls bpf, ktls: Fix data corruption when using bpf_msg_pop_data() in ktls 2025-06-11 16:59:42 +02:00
unix af_unix: Introduce SO_INQ. 2025-07-08 18:05:25 -07:00
vmw_vsock vsock: Add support for SIOCINQ ioctl 2025-07-09 19:29:52 -07:00
wireless wifi: cfg80211: support configuration of S1G station capabilities 2025-06-24 15:19:28 +02:00
x25 net: make sk->sk_rcvtimeo lockless 2025-06-23 17:05:12 -07:00
xdp net: xsk: introduce XDP_MAX_TX_SKB_BUDGET setsockopt 2025-07-10 14:48:29 +02:00
xfrm net: dst: annotate data-races around dst->obsolete 2025-07-02 14:32:29 -07:00
compat.c
devres.c
Kconfig net: Kconfig NET_DEVMEM selects GENERIC_ALLOCATOR 2025-05-27 17:31:42 -07:00
Kconfig.debug
Makefile net: Retire DCCP socket. 2025-04-11 18:58:10 -07:00
socket.c net: annotate races around sk->sk_uid 2025-06-23 17:04:03 -07:00
sysctl_net.c