Re: [PATCH] swiotlb: avoid double copy with swiotlb on tx socket
From: Pedro Falcato <pfalcato@suse.de>
Date: 2026-06-16 10:28:18
Also in:
driver-core, linux-iommu, lkml
On Tue, Jun 16, 2026 at 11:48:36AM +0200, Luigi Rizzo wrote:
On Tue, Jun 16, 2026 at 11:20 AM Pedro Falcato [off-list ref] wrote:quoted
(+cc page pool maintainers) On Mon, Jun 15, 2026 at 11:42:20PM +0000, Luigi Rizzo wrote:quoted
The use of swiotlb causes an extra data copy on I/O. For tx sockets, especially with greedy senders, this has a high chance of happening in the softirq handler for tx network interrupts, creating a significant performance bottleneck. Allow tx sockets to allocate socket buffers directly from the bounce buffers. This avoids the second copy and removes the above bottleneck. The fraction of swiotlb buffers allowed for this feature is set with /sys/module/swiotlb/parameters/zerocopy_tx_percent (0 means disabled, 90 is the maximum, to avoid persistent I/O failures). Implementation: - define a new page type to unambiguously identify bounce buffers used as backing storage for socket buffers - modify skb_page_frag_refill to perform the modified allocation - modify the destructors __free_frozen_pages(), free_unref_folio() to handle those pages and return them to the pool. The savings are especially visible with fewer queues. In synthetic benchmarks, senders with 1-2 queues would cap around 50Gbps with conventional swiotlb, and reach over 170Gbps with the feature enabled.I could be wrong, but I genuinely think that the way to go about this is using page_pool for regular TX as well. page_pool pages are all dma-mapped (so whatever swiotlb optimization you want can be done there), and the net stack already has awareness of these special pages and special skbs, so it won't Just Return Them back to the page allocator.I am not sure I follow your comment above, can you expand/clarify? The problem I am dealing with is that the copy from the socket buffer to the bounce buffer is done in the device xmit function. Under high it is almost always done by the tx softirq. This means that even if we move the copy outside the HARD_TX_LOCK(), it would still be almost completely serialized. Hence the proposed method to make skb_page_frag_refill() allocate directly a bounce buffer (under specific conditions) so there is a single copy done directly to the dma-able buffer, and ii is done in the user threads/CPUs and is not seriallized in the softirq thread. I am not sure how page_pool on tx could help here.
Page pool would provide both the means of passing around an iommu-mapped page,
and a concrete "this is where we allocate these pages" spot. Then introducing
a "zero-copy" swiotlb allocation would be a simple matter of introducing this
on page pool's side. In pseudo-code, something like:
static struct page *__page_pool_alloc_page_order(struct page_pool *pool,
gfp_t gfp)
{
struct page *page;
gfp |= __GFP_COMP;
if (pool->dma_map && /* is_swiotlb */) {
page = swiotlb_alloc_pages(pool->p.nid, gfp, pool->p.order, ...);
if (!page)
return NULL;
/* page is implicitly swiotlb mapped (well, _actually_ it's
* not that simple, because of the dma_mapped tracking that
* was introduced, but PoC anyway..). */
} else {
page = alloc_pages_node(pool->p.nid, gfp, pool->p.order);
if (unlikely(!page))
return NULL;
if (pool->dma_map && unlikely(!page_pool_dma_map(pool, page_to_netmem(page), gfp))) {
put_page(page);
return NULL;
}
}
}
(plus other spots, obviously). No copying should be required, and the
netmem desc will keep the dma_addr around. The network stack will notice
pp_recycle on all of these skbs and simply refuse to throw the pages away to
the page allocator.
In any case, it might be that this is not feasible for XYZ reasons, but I've
thought about this (making net use and reuse page pool pre-iommu-mapped pages
exclusively) for a while and I definitely see a lot of similarities with your
problem (that more or less reduces down to "I want to get an iommu-mapped page
from the get-go").
--
Pedro