RFC xsk: batch xmit in copy mode
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v4 RFC Latest14 patches 14 repliesIn review
- v39 patches 12 repliesSuperseded
- v29 patches 20 repliesSuperseded
Earlier versions · 1
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v1 | 2 patches | 13 replies | Superseded |
Patches in v4 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/14 | xsk: introduce XDP_GENERIC_XMIT_BATCH setsockoptDocumentation/ include/ include/ +2 more | +73 | 1 reply | |
| 2/14 | xsk: extend xsk_build_skb() to support passing an already allocated skbinclude/ net/ | +19 | 1 reply | |
| 3/14 | xsk: add xsk_alloc_batch_skb() to build skbs in batchinclude/ net/ net/ | +131 | 1 reply | |
| 4/14 | xsk: cache data buffers to avoid frequently calling kmalloc_reserveinclude/ net/ net/ | +44 | 2 replies | |
| 5/14 | xsk: add direct xmit in batch functioninclude/ net/ | +42 | 1 reply | |
| 6/14 | xsk: support dynamic xmit.more control for batch xmitnet/ | +6 | 3 replies | |
| 7/14 | xsk: try to skip validating skb list in xmit pathnet/ | +12 | 1 reply | |
| 8/14 | xsk: rename nb_pkts to nb_descs in xsk_tx_peek_release_desc_batchnet/ | +14 | 0 replies | |
| 9/14 | xsk: extend xskq_cons_read_desc_batch to count nb_pktsnet/ | +15 | 0 replies | |
| 10/14 | xsk: extend xsk_cq_reserve_locked() to reserve n slotsnet/ net/ | +15 | 0 replies | |
| 11/14 | xsk: support batch xmit main logicnet/ net/ | +124 | 1 reply | |
| 12/14 | xsk: separate read-mostly and write-heavy fields in xsk_buff_poolinclude/ | +7 | 1 reply | |
| 13/14 | xsk: retire old xmit path in copy modenet/ | +37 | 1 reply | |
| 14/14 | xsk: optimize xsk_build_skb for batch copy-mode fast pathinclude/ net/ net/ | +24 | 1 reply |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.
Cover letter [PATCH RFC net-next v4 00/14] xsk: batch xmit in copy mode
From: Jason Xing <[email protected]>
Greetings, everyone. This is the batch feature series. Even though net-next is closed, I would appreciate any feedbacks and suggestions on this! Many thanks!
Bottom line up front: it improves the performance by 88.2% stably.
# Background
This series is focused on the performance improvement in copy mode. As observed in the physical servers, there are much room left to ramp up the transmission for copy mode, compared to zerocopy mode.
Even though we can apply zerocopy to achieve a much better performance, some limitations are still there especially for virtio and veth cases due to the implementation in the host. In the real world, hundreds and thousands of hosts like at Tencent still don't support zerocopy mode for VMs, so copy mode is the only way we can resort to. Being general is its strong advantage.
Zerocopy has a good function name xskq_cons_read_desc_batch() which reads descriptors in batch and then sends them out at a time, rather than just read and send the descriptor one by one in a loop. Similar batch ideas can be seen from classic mechanisms like GSO/GRO which also try to handle as many packets as they can at one time. So the motivation and idea of the series actually originated from them.
# AF_PACKET Comparison
Looking back to the initial design and implementation of AF_XDP, it's not hard to find the big difference it made is to speed up the transmission when zerocopy mode is enabled. So the conclusion is that zerocopy mode of AF_XDP outperforms AF_PACKET that still uses copy mode. As to the whole logic of copy mode for both of them, they looks quite similar, especially when application using AF_PACKET sets PACKET_QDISC_BYPASS option. Digging into the details of AF_PACKET, we can find the implementation is comparatively heavy which can also be proved by the real test as shown below. The numbers of AF_PACKET test are a little bit lower.
# Batch Mode
At the current moment, I consider copy mode of AF_XDP as a half bypass mechanism to some extent in comparison with the well known bypass mechanism like DPDK. To avoid much consumption in kernel as much as possible, then the batch xmit is proposed to aggregate descriptors in a certain small group and then read/allocate/build/send them in individual loops.
Applications are allowed to use setsockopt to enlarge the default value. Please note that since memory allocation can be time consuming and heavy due to lack of memory that results in complicated memory reclaim, it might not be that good to hold one descriptor for too long, which brings high latency for one skb.
# Experiments
Tested on ixgbe at 10Gb/sec with the following settings:
1. mitigations off
2. ethtool -G enp2s0f1 tx 512
3. sysctl -w net.core.skb_defer_max=0
4. sysctl -w net.core.wmem_max=21299200 and sndbuf is the same value
5. XDP_MAX_TX_SKB_BUDGET 512
taskset -c 1 ./xdpsock -i enp2s0f1 -t -S -s 64
copy mode(before): 1,801,007 pps (baseline) AF_PACKET: 1,375,808 pps (-23.6%) zc mode: 13,333,593 pps (+640.3%) batch mode(batch 1): 1,976,821 pps (+9.8%) batch mode(batch 64): 3,389,704 pps (+88.2%) batch mode(batch 256): 3,387,563 pps (+88.0%)
---
RFC v4
1. fix a few bugs in v3
2. add a few optimizations
The series is built on top of commit 2ce8a41113ed (net: hsr: emit notification for PRP slave2 changed hw addr on port deletion). Since the changes compared to v3 are too many, please review the series from scratch. Thanks!
v3
1. I retested and got different test numbers. Previous test is not that right because my env has two NUMA nodes and only the first one has a faster speed.
2. To achieve a stable performance result, the development and evaluation are also finished in physical servers just like the numbers that I share.
3. I didn't use pool->tx_descs because sockets can share the same umem pool.
3. Use skb list to chain the allocated and built skbs to send.
5. Add AF_PACKET test numbers.
V2
1. add xmit.more sub-feature (Jesper)
2. add kmem_cache_alloc_bulk (Jesper and Maciej)
Jason Xing (14):
xsk: introduce XDP_GENERIC_XMIT_BATCH setsockopt
xsk: extend xsk_build_skb() to support passing an already allocated
skb
xsk: add xsk_alloc_batch_skb() to build skbs in batch
xsk: cache data buffers to avoid frequently calling kmalloc_reserve
xsk: add direct xmit in batch function
xsk: support dynamic xmit.more control for batch xmit
xsk: try to skip validating skb list in xmit path
xsk: rename nb_pkts to nb_descs in xsk_tx_peek_release_desc_batch
xsk: extend xskq_cons_read_desc_batch to count nb_pkts
xsk: extend xsk_cq_reserve_locked() to reserve n slots
xsk: support batch xmit main logic
xsk: separate read-mostly and write-heavy fields in xsk_buff_pool
xsk: retire old xmit path in copy mode
xsk: optimize xsk_build_skb for batch copy-mode fast path
Documentation/networking/af_xdp.rst | 17 ++ include/net/xdp_sock.h | 17 ++ include/net/xsk_buff_pool.h | 10 +- include/uapi/linux/if_xdp.h | 1 + net/core/dev.c | 49 +++++ net/core/skbuff.c | 152 +++++++++++++++ net/xdp/xsk.c | 279 ++++++++++++++++++++-------- net/xdp/xsk_queue.h | 40 +++- tools/include/uapi/linux/if_xdp.h | 1 + 9 files changed, 473 insertions(+), 93 deletions(-)
Signature · 1 line
2.41.3