libeth, idpf: use GFP_KERNEL for the initial Rx ring fill
v2 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_gfp() 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.
v2:
- 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_gfp() 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 | 23 +++++++++++++++---- 4 files changed, 30 insertions(+), 11 deletions(-)
Signature · 1 line
2.56.0.212.g129ede20d9-goog
PATCH v2 1/2 libeth: add libeth_rx_alloc_gfp() 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_gfp(), 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 | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
include/net/libeth/rx.h +19 -4
@@ -96,20 +96,23 @@ 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_gfp - 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_gfp (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 +120,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_gfp(). +*/ +static inline dma_addr_t libeth_rx_alloc (const struct libeth_fq_fp *fq,u32 i) +{ +return libeth_rx_alloc_gfp (fq, i,GFP_ATOMIC ); +} +void libeth_rx_recycle_slow (netmem_ref netmem);/**
Signature · 1 line
2.56.0.212.g129ede20d9-goog
PATCH v2 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(..., 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_gfp(&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
@@ -600,6 +600,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)
@@ -618,7 +621,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_gfp (&fq, buf_id,GFP_KERNEL );if (addr ==DMA_MAPPING_ERROR )return false;
@@ -629,7 +632,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_gfp (&fq, buf_id,GFP_KERNEL );if (addr ==DMA_MAPPING_ERROR )return false;
@@ -675,7 +678,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
@@ -1123,7 +1123,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.212.g129ede20d9-goog
RE: [PATCH iwl-next v2 1/2] libeth: add libeth_rx_alloc_gfp() to specify allocation flags
In reply to Luigi RizzoQuoted 94 lines
-----Original Message-----
From: Luigi Rizzo <[email protected]>
Sent: Monday, October 19, 2026 11:06 PM
To: [email protected]
Cc: [email protected]; Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Lobakin, Aleksander <[email protected]>; Andrew Lunn <[email protected]>; David S . Miller <[email protected]>; Eric Dumazet <[email protected]>; Luigi Rizzo <[email protected]>; Brian Vazquez <[email protected]>; Hay, Joshua A <[email protected]>; Zaremba, Larysa <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Simon Horman <[email protected]>; [email protected]; Luigi Rizzo <[email protected]>
Subject: [PATCH iwl-next v2 1/2] libeth: addlibeth_rx_alloc_gfp()to specify allocation flags
libeth_rx_alloc()callspage_pool_dev_alloc_netmem(), which always allocates withGFP_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 andGFP_ATOMICis 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_gfp(), which takes agfp_tparameter and passes gfp |__GFP_NOWARNtopage_pool_alloc_netmem(), and makelibeth_rx_alloc()itsGFP_ATOMICwrapper.Signed-off-by Luigi Rizzo <[email protected]>--- include/net/libeth/rx.h | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)include/net/libeth/rx.h index renamed from include/net/libeth/rx.h +0
-0
0e736846c5e8a..14a528ea8a075100644include/net/libeth/rx.h +2
-1@@ -96,20 +96,23 @@ 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_gfp - 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_ATOMICfrom NAPI
*
* Return: DMA address to be passed to HW for Rx on successful
allocation,
* ```DMA_MAPPING_ERROR``` otherwise.
*/
-static inlinedma_addr_tlibeth_rx_alloc(const struct libeth_fq_fp *fq, u32 i)
+static inlinedma_addr_tlibeth_rx_alloc_gfp(const structlibeth_fq_fp*fq,include/net/libeth/rx.h +3
-2+ 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);include/net/libeth/rx.h +11
-1if (unlikely (!buf->netmem))return DMA_MAPPING_ERROR ;@@ -117,6 +120,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_gfp(). +*/ +static inline dma_addr_t libeth_rx_alloc (const struct libeth_fq_fp *fq, +u32 i) { +return libeth_rx_alloc_gfp (fq, i,GFP_ATOMIC ); } +void libeth_rx_recycle_slow (netmem_ref netmem);/** --
Quoted 1 line
2.56.0.212.g129ede20d9-goog
RE: [PATCH iwl-next v2 2/2] idpf: use GFP_KERNEL for the initial Rx ring fill
In reply to Luigi RizzoQuoted 146 lines
-----Original Message-----
From: Luigi Rizzo <[email protected]>
Sent: Monday, October 19, 2026 11:06 PM
To: [email protected]
Cc: [email protected]; Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Lobakin, Aleksander <[email protected]>; Andrew Lunn <[email protected]>; David S . Miller <[email protected]>; Eric Dumazet <[email protected]>; Luigi Rizzo <[email protected]>; Brian Vazquez <[email protected]>; Hay, Joshua A <[email protected]>; Zaremba, Larysa <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Simon Horman <[email protected]>; [email protected]; Luigi Rizzo <[email protected]>
Subject: [PATCH iwl-next v2 2/2] idpf: useGFP_KERNELfor the initial Rx ring fillWhen 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 withGFP_ATOMICis 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 tolibeth_rx_alloc_gfp(..., GFP_KERNEL).In singleq mode, add a
gfp_tparameter toidpf_rx_singleq_buf_hw_alloc_all()and passGFP_KERNELfromidpf_rx_buf_alloc_singleq()andGFP_ATOMICfromidpf_rx_singleq_clean().Signed-off-by Luigi Rizzo <[email protected]>--- 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 +2
-1@@ -885,11 +885,12 @@ static void idpf_rx_buf_hw_update(structidpf_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;drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +2
-2const 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_gfp (&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 );drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +0
-0u64_stats_update_begin (&rx_q->stats_sync); u64_stats_add(&rx_q->q_stats.packets, rs.packets); diff --git
a/drivers/net/ethernet/intel/idpf/idpf_txrx.cb/drivers/net/ethernet/intel/idpf/idpf_txrx.c
index4311ffa30bb18..b1127ab48ef3f100644drivers/net/ethernet/intel/idpf/idpf_txrx.c +4
-0@@ -600,6 +600,9 @@ static void idpf_post_buf_refill(structidpf_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) @@ -618,7 +621,7 @@ static boolidpf_rx_post_buf_desc(struct idpf_buf_queue *bufq, u16 buf_id)drivers/net/ethernet/intel/idpf/idpf_txrx.c +4
-3fq.fqes = bufq->hdr_buf; fq.truesize = bufq->hdr_truesize; - addr =libeth_rx_alloc (&fq, buf_id); + addr =libeth_rx_alloc_gfp (&fq, buf_id,GFP_KERNEL );if (addr ==DMA_MAPPING_ERROR )return false;@@ -629,7 +632,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_gfp (&fq, buf_id,GFP_KERNEL );if (addr ==DMA_MAPPING_ERROR )return false;@@ -675,7 +678,7 @@ static bool idpf_rx_post_init_bufs(structidpf_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@@ -1123,7 +1123,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,drivers/net/ethernet/intel/idpf/idpf_txrx.h +0
-1const struct libeth_xdp_buff *xdp, struct libeth_rq_napi_stats *rs); --
Quoted 1 line
2.56.0.212.g129ede20d9-goog
Alexander Lobakin
maintainerFrom: Luigi Rizzo <[email protected]>
Date: Mon, 19 Oct 2026 21:06:02 +0000
Quoted 8 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.
Quoted 4 lines
Patch 1 adds
libeth_rx_alloc_gfp()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.
This is done for simplicity and performance reasons (although I've just realized that this helper is fully inline, so it will inline your new GFP argument as well).
But could anyone explain me why the initial fill is bad to do with GFP_ATOMIC?
Quoted 9 lines
v2:
- split into two patches (libeth helper and idpf consumer)
v1: https://lore.kernel.org/r/[email protected]/Luigi Rizzo (2):
libeth: addlibeth_rx_alloc_gfp()to specify allocation flags
idpf: useGFP_KERNELfor the initial Rx ring fill
Quoted 5 lines
.../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 | 23 +++++++++++++++---- 4 files changed, 30 insertions(+), 11 deletions(-)
Thanks,
Olek
Quoted 17 lines · Alexander Lobakin
From: Luigi Rizzo <[email protected]>
Date: Mon, 19 Oct 2026 21:06:02 +0000Quoted 8 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.Quoted 4 lines
Patch 1 adds
libeth_rx_alloc_gfp()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.
Quoted 6 lines
This is done for simplicity and performance reasons (although I've just realized that this helper is fully inline, so it will inline your new GFP argument as well).
But could anyone explain me why the initial fill is bad to do with
GFP_ATOMIC?
It might not be so bad now, but consider something like DMA-PMD
https://lore.kernel.org/all/[email protected]/
that allocates buffers from larger chunks to reduce IOTLB pressure and iommu-related costs.
An innocent request for one buffer could cause the pagepool provider to request a higher order page, which in turn may require some compaction work and sleeping.
Using GFP_ATOMIC could cause unnecessary allocation failures if pages are not readily available (and in O(100K) allocations something could easily go wrong).
FWIW other drivers are not very consistent in their use of flags for initial allocations, but I think this is more to simplify code reuse (as you pointed out) than for a real requirement.
cheers
luigi
Alexander Lobakin
maintainerRe: [PATCH iwl-next v2 1/2] libeth: add libeth_rx_alloc_gfp() to specify allocation flags
In reply to Luigi RizzoFrom: Luigi Rizzo <[email protected]>
Date: Mon, 19 Oct 2026 21:06:03 +0000
Quoted 11 lines
libeth_rx_alloc()callspage_pool_dev_alloc_netmem(), which always allocates withGFP_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 andGFP_ATOMICis 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_gfp(), which takes agfp_tparameter and passes gfp |__GFP_NOWARNtopage_pool_alloc_netmem(), and makelibeth_rx_alloc()itsGFP_ATOMICwrapper.
If you'd really like to go ahead (I'm still not really convinced, even with "O(100k)" which is not that realistic), here's a couple style wishes from me:
Quoted 17 lines
Signed-off-by Luigi Rizzo <[email protected]>--- include/net/libeth/rx.h | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)include/net/libeth/rx.h +1
-1@@ -96,20 +96,23 @@ 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_gfp - allocate a new Rx buffer * @fq: fill queue to allocate for
include/net/libeth/rx.h int libeth_rx_fq_create(struct libeth_fq *fq, void *napi_dev); · line 109
Quoted 10 lines
include/net/libeth/rx.h +4
-1* @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_gfp (const struct libeth_fq_fp *fq, +u32 i,gfp_t gfp)
Mayb just __libeth_rx_alloc()?
include/net/libeth/rx.h int libeth_rx_fq_create(struct libeth_fq *fq, void *napi_dev); · line 115
Quoted 8 lines
include/net/libeth/rx.h +2
-2{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);
And here I'd also place the gfp argument on a separate line.
Quoted 12 lines
include/net/libeth/rx.h +5
-0if (unlikely (!buf->netmem))return DMA_MAPPING_ERROR ;@@ -117,6 +120,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 +*
include/net/libeth/rx.h static inline dma_addr_t libeth_rx_alloc(const struct libeth_fq_fp *fq, u32 i) · line 137
Quoted 10 lines
include/net/libeth/rx.h +7
-0+* Return: as libeth_rx_alloc_gfp(). +*/ +static inline dma_addr_t libeth_rx_alloc (const struct libeth_fq_fp *fq,u32 i) +{ +return libeth_rx_alloc_gfp (fq, i,GFP_ATOMIC ); +} +void libeth_rx_recycle_slow (netmem_ref netmem);/**
Thanks,
Olek
Re: [PATCH iwl-next v2 1/2] libeth: add libeth_rx_alloc_gfp() to specify allocation flags
Quoted 12 lines · Alexander Lobakin
From: Luigi Rizzo <[email protected]>
Date: Mon, 19 Oct 2026 21:06:03 +0000Quoted 8 lines
libeth_rx_alloc()callspage_pool_dev_alloc_netmem(), which always allocates withGFP_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 andGFP_ATOMICis needlessly restrictive: it can neither reclaim nor compact, while the initial fill can allocate tens of thousands of buffers across all queues.
Quoted 5 lines
Quoted 3 lines
Add
libeth_rx_alloc_gfp(), which takes agfp_tparameter and passes gfp |__GFP_NOWARNtopage_pool_alloc_netmem(), and makelibeth_rx_alloc()itsGFP_ATOMICwrapper.If you'd really like to go ahead (I'm still not really convinced, even
To be clear, GFP_ATOMIC is not a problem right now, but it becomes a problem if we try to back the buffers with 2MB pages as in DMA_PMD, and those 2MB pages may not be available without sleeping.
Quoted 1 line
with "O(100k)" which is not that realistic),
On a large system, which is definitely the target for a 200G NIC that uses idpf, we can easily get there and above.
The system I am testing now uses 4096 slots per queue, 32 queues, meaning 128K entries at initialization. Under load, the pool has grown to 197K entries.
Ok for the style changes, will resend an updated version
cheers
luigi