freenode
Kernel & Low-Level

AF_XDP proposal lets sockets take the NIC's own buffer layout

Björn Töpel's series would drop the one-chunk-per-buffer zero-copy model and back a queue's page pools with UMEM, starting with fbnic and mlx5.

A proposed kernel series would let AF_XDP sockets receive packets in the buffer layout a driver already uses for its page pool, instead of forcing the device to fill one userspace chunk per buffer at a fixed headroom.

Today, zero-copy AF_XDP makes each driver carry a second receive path and bend its geometry to fit that model. Packets the device would split across several buffers, or pack several to a page, cannot arrive without a copy. Meta's fbnic and Broadcom's bnxt have no AF_XDP zero copy at all.

Björn Töpel wrote that the series lets a socket install a memory provider on the bound queue, the same way devmem and io_uring zero-copy receive install theirs. The UMEM then backs that queue's receive page pools. The device places buffers in UMEM chunks as it places them in pages: several buffers may share a chunk, a packet may span chunks, and the device picks the offsets. An XDP program redirects each packet through an XSK map, and each buffer becomes one receive descriptor. A fill entry lends a whole chunk; a new descriptor option, XDP_RX_CHUNK_FREE, gives it back.

The userspace interface grows a registration flag, XDP_UMEM_DRV_LAYOUT, which selects aligned page-sized chunks and no headroom. A bind in that layout requires XDP_USE_NEED_WAKEUP, because only a wakeup restarts a queue that ran out of buffers, and fails without it. The bind also needs a native XDP program, only one socket per queue may receive, and copy mode is refused. The series replaces an earlier proposal that tried zero copy through page-pool memory providers.

The kernel still treats these chunks as unreadable to the networking stack. Userspace can rewrite the memory at any time, so shared packet metadata and other kernel structures stay in kernel memory, and transmit or pass verdicts on these buffers become drops. XDP programs may read and write the packet in place through a dedicated view of the memory.

Driver work in the series is the first consumers. fbnic would honor XDP redirects, which it currently drops, and accept an XDP-only provider on its header page pool. mlx5 would allow queue restarts with an XDP program attached and take such a provider on receive queues that run a program. On a ConnectX-7 with 66-byte frames on one core, Töpel measured 16.42 million packets per second, 179 cycles per packet, though the linear striding layout still yields one packet per 4 KiB chunk at a 1500-byte MTU. bnxt's page-mode receive path is started on the same netmem handling.