libeth, idpf: use GFP_KERNEL for the initial Rx ring fill
v3 cover libeth, idpf: use GFP_KERNEL for the initial Rx ring fill
libeth_rx_alloc() always allocates with GFP_ATOMIC, including when a driver fills its Rx rings at open or on queue reconfiguration. That fill runs in process context, right after page_pool_create() and before the queues' NAPI is enabled, so it may sleep, and GFP_ATOMIC is needlessly restrictive there: it can neither reclaim nor compact, while the initial fill can allocate tens of thousands of buffers across all queues.
Patch 1 adds __libeth_rx_alloc() taking a gfp_t parameter and turns libeth_rx_alloc() into its GFP_ATOMIC wrapper.
Patch 2 switches idpf's initial Rx ring fill (both splitq and singleq) to GFP_KERNEL.
v3:
- rename libeth_rx_alloc_gfp() to __libeth_rx_alloc() and put the gfp argument on its own line in page_pool_alloc_netmem() (Alexander Lobakin)
v2: https://lore.kernel.org/r/[email protected]/
- split into two patches (libeth helper and idpf consumer)
v1: https://lore.kernel.org/r/[email protected]/
Luigi Rizzo (2):
libeth: add __libeth_rx_alloc() to specify allocation flags
idpf: use GFP_KERNEL for the initial Rx ring fill
.../ethernet/intel/idpf/idpf_singleq_txrx.c | 7 +++--- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 9 ++++--- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 2 +- include/net/libeth/rx.h | 24 +++++++++++++++---- 4 files changed, 31 insertions(+), 11 deletions(-)
Signature · 1 line
2.56.0.385.gac671c819a-goog
PATCH v3 1/2 libeth: add __libeth_rx_alloc() to specify allocation flags
libeth_rx_alloc() calls page_pool_dev_alloc_netmem(), which always allocates with GFP_ATOMIC | __GFP_NOWARN. Drivers also use it to fill their Rx rings at open or on queue reconfiguration, which runs in process context before the queues' NAPI is enabled. There, the caller may sleep and GFP_ATOMIC is needlessly restrictive: it can neither reclaim nor compact, while the initial fill can allocate tens of thousands of buffers across all queues.
Add __libeth_rx_alloc(), which takes a gfp_t parameter and passes gfp | __GFP_NOWARN to page_pool_alloc_netmem(), and make libeth_rx_alloc() its GFP_ATOMIC wrapper.
--- include/net/libeth/rx.h | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)
include/net/libeth/rx.h +20 -4
@@ -96,20 +96,24 @@ int libeth_rx_fq_create(struct libeth_fq *fq, void *napi_dev);void libeth_rx_fq_destroy (struct libeth_fq *fq);/** -* libeth_rx_alloc - allocate a new Rx buffer +* __libeth_rx_alloc - allocate a new Rx buffer * @fq: fill queue to allocate for * @i: index of the buffer within the queue +* @gfp: allocation flags: GFP_KERNEL where the caller may sleep (e.g. the +* initial fill of the ring), GFP_ATOMIC from NAPI * * Return: DMA address to be passed to HW for Rx on successful allocation, * ```DMA_MAPPING_ERROR``` otherwise. */ -static inline dma_addr_t libeth_rx_alloc (const struct libeth_fq_fp *fq,u32 i) +static inline dma_addr_t __libeth_rx_alloc (const struct libeth_fq_fp *fq, +u32 i,gfp_t gfp) {struct libeth_fqe *buf = &fq->fqes[i]; buf->truesize = fq->truesize; - buf->netmem =page_pool_dev_alloc_netmem (fq->pp, &buf->offset, - &buf->truesize); + buf->netmem =page_pool_alloc_netmem (fq->pp, &buf->offset, + &buf->truesize, + gfp | __GFP_NOWARN);if (unlikely (!buf->netmem))return DMA_MAPPING_ERROR ;
@@ -117,6 +121,18 @@ static inline dma_addr_t libeth_rx_alloc(const struct libeth_fq_fp *fq, u32 i) fq->pp->p.offset; } +/** +* libeth_rx_alloc - allocate a new Rx buffer from NAPI context +* @fq: fill queue to allocate for +* @i: index of the buffer within the queue +* +* Return: as __libeth_rx_alloc(). +*/ +static inline dma_addr_t libeth_rx_alloc (const struct libeth_fq_fp *fq,u32 i) +{ +return __libeth_rx_alloc (fq, i,GFP_ATOMIC ); +} +void libeth_rx_recycle_slow (netmem_ref netmem);/**
Signature · 1 line
2.56.0.385.gac671c819a-goog
PATCH v3 2/2 idpf: use GFP_KERNEL for the initial Rx ring fill
In reply to Luigi RizzoWhen idpf fills its Rx rings at open or on queue reconfiguration, the allocation runs in process context, right after page_pool_create() and before the queues' NAPI is enabled. Allocating tens of thousands of buffers across all queues with GFP_ATOMIC is needlessly restrictive when the caller may sleep.
In splitq mode, idpf_rx_post_buf_desc() is only used for this initial fill, so switch its header and payload allocations to __libeth_rx_alloc(..., GFP_KERNEL).
In singleq mode, add a gfp_t parameter to idpf_rx_singleq_buf_hw_alloc_all() and pass GFP_KERNEL from idpf_rx_buf_alloc_singleq() and GFP_ATOMIC from idpf_rx_singleq_clean().
--- drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c | 7 ++++--- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 9 ++++++--- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +4 -3
@@ -885,11 +885,12 @@ static void idpf_rx_buf_hw_update(struct idpf_rx_queue *rxq, u32 val)* idpf_rx_singleq_buf_hw_alloc_all - Replace used receive buffers * @rx_q: queue for which the hw buffers are allocated * @cleaned_count: number of buffers to replace +* @gfp: GFP_KERNEL for the initial fill, GFP_ATOMIC from NAPI * * Returns false if all allocations were successful, true if any fail */ bool idpf_rx_singleq_buf_hw_alloc_all (struct idpf_rx_queue *rx_q, -u16 cleaned_count) +u16 cleaned_count,gfp_t gfp) {struct virtchnl2_singleq_rx_buf_desc *desc;const struct libeth_fq_fp fq = {
@@ -908,7 +909,7 @@ bool idpf_rx_singleq_buf_hw_alloc_all(struct idpf_rx_queue *rx_q, do { dma_addr_t addr; - addr = libeth_rx_alloc(&fq, nta); + addr = __libeth_rx_alloc(&fq, nta, gfp); if (addr == DMA_MAPPING_ERROR) break;
@@ -1095,7 +1096,7 @@ static int idpf_rx_singleq_clean(struct idpf_rx_queue *rx_q, int budget)page_pool_nid_changed (rx_q->pp,numa_mem_id ());if (cleaned_count) -idpf_rx_singleq_buf_hw_alloc_all (rx_q, cleaned_count); +idpf_rx_singleq_buf_hw_alloc_all (rx_q, cleaned_count,GFP_ATOMIC );u64_stats_update_begin (&rx_q->stats_sync);u64_stats_add (&rx_q->q_stats.packets, rs.packets);
drivers/net/ethernet/intel/idpf/idpf_txrx.c +6 -3
@@ -599,6 +599,9 @@ static void idpf_post_buf_refill(struct idpf_sw_queue *refillq, u16 buf_id)* @bufq: buffer queue to post to * @buf_id: buffer id to post * +* Only used for the initial fill, from process context, so it allocates +* with GFP_KERNEL. +* * Return: %false if buffer could not be allocated, %true otherwise. */ static bool idpf_rx_post_buf_desc (struct idpf_buf_queue *bufq,u16 buf_id)
@@ -617,7 +620,7 @@ static bool idpf_rx_post_buf_desc(struct idpf_buf_queue *bufq, u16 buf_id) fq.fqes = bufq->hdr_buf; fq.truesize = bufq->hdr_truesize; - addr =libeth_rx_alloc (&fq, buf_id); + addr =__libeth_rx_alloc (&fq, buf_id,GFP_KERNEL );if (addr ==DMA_MAPPING_ERROR )return false;
@@ -628,7 +631,7 @@ static bool idpf_rx_post_buf_desc(struct idpf_buf_queue *bufq, u16 buf_id) fq.fqes = bufq->buf; fq.truesize = bufq->truesize; - addr =libeth_rx_alloc (&fq, buf_id); + addr =__libeth_rx_alloc (&fq, buf_id,GFP_KERNEL );if (addr ==DMA_MAPPING_ERROR )return false;
@@ -674,7 +677,7 @@ static bool idpf_rx_post_init_bufs(struct idpf_buf_queue *bufq,*/ static int idpf_rx_buf_alloc_singleq (struct idpf_rx_queue *rxq) { -if (idpf_rx_singleq_buf_hw_alloc_all (rxq, rxq->desc_count -1 )) +if (idpf_rx_singleq_buf_hw_alloc_all (rxq, rxq->desc_count -1 ,GFP_KERNEL )) goto err;return 0 ;
drivers/net/ethernet/intel/idpf/idpf_txrx.h +1 -1
@@ -1129,7 +1129,7 @@ netdev_tx_t idpf_tx_singleq_frame(struct sk_buff *skb, struct idpf_tx_queue *tx_q);netdev_tx_t idpf_tx_start (struct sk_buff *skb,struct net_device *netdev);bool idpf_rx_singleq_buf_hw_alloc_all (struct idpf_rx_queue *rxq, -u16 cleaned_count); +u16 cleaned_count,gfp_t gfp);bool idpf_rx_process_skb_fields (struct sk_buff *skb,const struct libeth_xdp_buff *xdp,struct libeth_rq_napi_stats *rs);
Signature · 1 line
2.56.0.385.gac671c819a-goog
From: Luigi Rizzo <[email protected]>
Date: Tue, 3 Nov 2026 16:23:23 +0000
Quoted 20 lines
libeth_rx_alloc()always allocates withGFP_ATOMIC, including when a driver fills its Rx rings at open or on queue reconfiguration. That fill runs in process context, right afterpage_pool_create()and before the queues' NAPI is enabled, so it may sleep, andGFP_ATOMICis needlessly restrictive there: it can neither reclaim nor compact, while the initial fill can allocate tens of thousands of buffers across all queues.Patch 1 adds
__libeth_rx_alloc()taking agfp_tparameter and turnslibeth_rx_alloc()into itsGFP_ATOMICwrapper.
Patch 2 switches idpf's initial Rx ring fill (both splitq and singleq) toGFP_KERNEL.v3:
- renamelibeth_rx_alloc_gfp()to__libeth_rx_alloc()and put the gfp argument on its own line inpage_pool_alloc_netmem()(Alexander Lobakin)
v2: https://lore.kernel.org/r/[email protected]/
- split into two patches (libeth helper and idpf consumer)
v1: https://lore.kernel.org/r/[email protected]/
Quoted 3 lines
Luigi Rizzo (2):
libeth: add__libeth_rx_alloc()to specify allocation flags
idpf: useGFP_KERNELfor the initial Rx ring fill
For the series:
Thanks!
Olek
Quoted 24 lines · Alexander Lobakin
From: Luigi Rizzo <[email protected]>
Date: Tue, 3 Nov 2026 16:23:23 +0000Quoted 20 lines
libeth_rx_alloc()always allocates withGFP_ATOMIC, including when a driver fills its Rx rings at open or on queue reconfiguration. That fill runs in process context, right afterpage_pool_create()and before the queues' NAPI is enabled, so it may sleep, andGFP_ATOMICis needlessly restrictive there: it can neither reclaim nor compact, while the initial fill can allocate tens of thousands of buffers across all queues.Patch 1 adds
__libeth_rx_alloc()taking agfp_tparameter and turnslibeth_rx_alloc()into itsGFP_ATOMICwrapper.
Patch 2 switches idpf's initial Rx ring fill (both splitq and singleq) toGFP_KERNEL.v3:
- renamelibeth_rx_alloc_gfp()to__libeth_rx_alloc()and put the gfp argument on its own line inpage_pool_alloc_netmem()(Alexander Lobakin)
v2: https://lore.kernel.org/r/[email protected]/
- split into two patches (libeth helper and idpf consumer)
v1: https://lore.kernel.org/r/[email protected]/
Quoted 7 lines
Quoted 3 lines
Luigi Rizzo (2):
libeth: add__libeth_rx_alloc()to specify allocation flags
idpf: useGFP_KERNELfor the initial Rx ring fillFor the series:
Reviewed-by Alexander Lobakin <[email protected]>
Looking further at the problem, gemini pointed out that libeth_rx_alloc() is called in a way that makes it easy and robust to tell when it can use GFP_KERNEL. This would greatly simplify the patch.
Alexander, do you like this version better perhaps ?
cheers
luigi
include/net/libeth/rx.h +9 -2
@@ -104,10 +104,17 @@ void libeth_rx_fq_destroy(struct libeth_fq *fq);static inline dma_addr_t libeth_rx_alloc (const struct libeth_fq_fp *fq,u32 i) {struct libeth_fqe *buf = &fq->fqes[i]; +/* fq->fqes is zero-allocated and pre-filled in process context for +* indices [0 .. fq->count - 2]; slot fq->count - 1 is first allocated +* in NAPI. Use GFP_KERNEL for initial pre-fill and GFP_ATOMIC after. +*/ +gfp_t gfp = (buf->truesize || i == fq->count -1 ) ? +GFP_ATOMIC :GFP_KERNEL ; buf->truesize = fq->truesize; - buf->netmem =page_pool_dev_alloc_netmem (fq->pp, &buf->offset, - &buf->truesize); + buf->netmem =page_pool_alloc_netmem (fq->pp, &buf->offset, + &buf->truesize, + gfp | __GFP_NOWARN);if (unlikely (!buf->netmem))return DMA_MAPPING_ERROR ;
Quoted 3 lines
Thanks!
Olek
Alexander Lobakin
maintainerFrom: Luigi Rizzo <[email protected]>
Date: Mon, 9 Nov 2026 15:53:55 +0100
Quoted 48 lines
Quoted 24 lines · Alexander Lobakin
From: Luigi Rizzo <[email protected]>
Date: Tue, 3 Nov 2026 16:23:23 +0000Quoted 20 lines
libeth_rx_alloc()always allocates withGFP_ATOMIC, including when a driver fills its Rx rings at open or on queue reconfiguration. That fill runs in process context, right afterpage_pool_create()and before the queues' NAPI is enabled, so it may sleep, andGFP_ATOMICis needlessly restrictive there: it can neither reclaim nor compact, while the initial fill can allocate tens of thousands of buffers across all queues.Patch 1 adds
__libeth_rx_alloc()taking agfp_tparameter and turnslibeth_rx_alloc()into itsGFP_ATOMICwrapper.
Patch 2 switches idpf's initial Rx ring fill (both splitq and singleq) toGFP_KERNEL.v3:
- renamelibeth_rx_alloc_gfp()to__libeth_rx_alloc()and put the gfp argument on its own line inpage_pool_alloc_netmem()(Alexander Lobakin)
v2: https://lore.kernel.org/r/[email protected]/
- split into two patches (libeth helper and idpf consumer)
v1: https://lore.kernel.org/r/[email protected]/Quoted 7 lines
Quoted 3 lines
Luigi Rizzo (2):
libeth: add__libeth_rx_alloc()to specify allocation flags
idpf: useGFP_KERNELfor the initial Rx ring fillFor the series:
Reviewed-by Alexander Lobakin <[email protected]>Looking further at the problem, gemini pointed out that
libeth_rx_alloc()is called in a way that makes it easy and robust to tell when it can useGFP_KERNEL. This would greatly simplify the patch.Alexander, do you like this version better perhaps ?
cheers
luigiinclude/net/libeth/rx.h +0
-0
include/net/libeth/rx.h void libeth_rx_fq_destroy(struct libeth_fq *fq); · line 112
Quoted 9 lines
include/net/libeth/rx.h +6
-0@@ -104,10 +104,17 @@ void libeth_rx_fq_destroy(struct libeth_fq *fq);static inline dma_addr_t libeth_rx_alloc (const struct libeth_fq_fp *fq,u32 i) {struct libeth_fqe *buf = &fq->fqes[i]; +/* fq->fqes is zero-allocated and pre-filled in process context for +* indices [0 .. fq->count - 2]; slot fq->count - 1 is first allocated +* in NAPI. Use GFP_KERNEL for initial pre-fill and GFP_ATOMIC after. +*/ +gfp_t gfp = (buf->truesize || i == fq->count -1 ) ? +GFP_ATOMIC :GFP_KERNEL ;
The fact that fq->count - 1 is only allocated from the NAPI context is idpf's detail that doesn't belong to libeth.
Even though this is way shorter diffstat than the original series, I prefer the original as it doesn't change anything for drivers other than idpf and allows specifying GFP flags manually without such guesses. This change introduces new branches on hotpath for each driver that uses libeth.
include/net/libeth/rx.h void libeth_rx_fq_destroy(struct libeth_fq *fq); · line 119
Quoted 9 lines
include/net/libeth/rx.h +3
-2buf->truesize = fq->truesize; - buf->netmem =page_pool_dev_alloc_netmem (fq->pp, &buf->offset, - &buf->truesize); + buf->netmem =page_pool_alloc_netmem (fq->pp, &buf->offset, + &buf->truesize, + gfp | __GFP_NOWARN);if (unlikely (!buf->netmem))return DMA_MAPPING_ERROR ;
Thanks,
Olek