Skip to content

Commit 6e9b019

Browse files
committed
net: remove gfp_mask from napi_alloc_skb()
__napi_alloc_skb() is napi_alloc_skb() with the added flexibility of choosing gfp_mask. This is a NAPI function, so GFP_ATOMIC is implied. The only practical choice the caller has is whether to set __GFP_NOWARN. But that's a false choice, too, allocation failures in atomic context will happen, and printing warnings in logs, effectively for a packet drop, is both too much and very likely non-actionable. This leads me to a conclusion that most uses of napi_alloc_skb() are simply misguided, and should use __GFP_NOWARN in the first place. We also have a "standard" way of reporting allocation failures via the queue stat API (qstats::rx-alloc-fail). The direct motivation for this patch is that one of the drivers used at Meta calls napi_alloc_skb() (so prior to this patch without __GFP_NOWARN), and the resulting OOM warning is the top networking warning in our fleet. Reviewed-by: Alexander Lobakin <[email protected]> Reviewed-by: Simon Horman <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 49d665b commit 6e9b019

File tree

13 files changed

+18
-36
lines changed

13 files changed

+18
-36
lines changed

Documentation/mm/page_frags.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ to be disabled when executing the fragment allocation.
2525
The network stack uses two separate caches per CPU to handle fragment
2626
allocation. The netdev_alloc_cache is used by callers making use of the
2727
netdev_alloc_frag and __netdev_alloc_skb calls. The napi_alloc_cache is
28-
used by callers of the __napi_alloc_frag and __napi_alloc_skb calls. The
28+
used by callers of the __napi_alloc_frag and napi_alloc_skb calls. The
2929
main difference between these two calls is the context in which they may be
3030
called. The "netdev" prefixed functions are usable in any context as these
3131
functions will disable interrupts, while the "napi" prefixed functions are

Documentation/translations/zh_CN/mm/page_frags.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ sk_buff->head使用,或者用于skb_shared_info的 “frags” 部分。
2525

2626
网络堆栈在每个CPU使用两个独立的缓存来处理碎片分配。netdev_alloc_cache被使用
2727
netdev_alloc_frag和__netdev_alloc_skb调用的调用者使用。napi_alloc_cache
28-
被调用__napi_alloc_frag和__napi_alloc_skb的调用者使用。这两个调用的主要区别是
28+
被调用__napi_alloc_frag和napi_alloc_skb的调用者使用。这两个调用的主要区别是
2929
它们可能被调用的环境。“netdev” 前缀的函数可以在任何上下文中使用,因为这些函数
3030
将禁用中断,而 ”napi“ 前缀的函数只可以在softirq上下文中使用。
3131

drivers/net/ethernet/intel/i40e/i40e_txrx.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,9 +2144,7 @@ static struct sk_buff *i40e_construct_skb(struct i40e_ring *rx_ring,
21442144
*/
21452145

21462146
/* allocate a skb to store the frags */
2147-
skb = __napi_alloc_skb(&rx_ring->q_vector->napi,
2148-
I40E_RX_HDR_SIZE,
2149-
GFP_ATOMIC | __GFP_NOWARN);
2147+
skb = napi_alloc_skb(&rx_ring->q_vector->napi, I40E_RX_HDR_SIZE);
21502148
if (unlikely(!skb))
21512149
return NULL;
21522150

drivers/net/ethernet/intel/i40e/i40e_xsk.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,7 @@ static struct sk_buff *i40e_construct_skb_zc(struct i40e_ring *rx_ring,
301301
net_prefetch(xdp->data_meta);
302302

303303
/* allocate a skb to store the frags */
304-
skb = __napi_alloc_skb(&rx_ring->q_vector->napi, totalsize,
305-
GFP_ATOMIC | __GFP_NOWARN);
304+
skb = napi_alloc_skb(&rx_ring->q_vector->napi, totalsize);
306305
if (unlikely(!skb))
307306
goto out;
308307

drivers/net/ethernet/intel/iavf/iavf_txrx.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,9 +1334,7 @@ static struct sk_buff *iavf_construct_skb(struct iavf_ring *rx_ring,
13341334
net_prefetch(va);
13351335

13361336
/* allocate a skb to store the frags */
1337-
skb = __napi_alloc_skb(&rx_ring->q_vector->napi,
1338-
IAVF_RX_HDR_SIZE,
1339-
GFP_ATOMIC | __GFP_NOWARN);
1337+
skb = napi_alloc_skb(&rx_ring->q_vector->napi, IAVF_RX_HDR_SIZE);
13401338
if (unlikely(!skb))
13411339
return NULL;
13421340

drivers/net/ethernet/intel/ice/ice_txrx.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,8 +1051,7 @@ ice_construct_skb(struct ice_rx_ring *rx_ring, struct xdp_buff *xdp)
10511051
}
10521052

10531053
/* allocate a skb to store the frags */
1054-
skb = __napi_alloc_skb(&rx_ring->q_vector->napi, ICE_RX_HDR_SIZE,
1055-
GFP_ATOMIC | __GFP_NOWARN);
1054+
skb = napi_alloc_skb(&rx_ring->q_vector->napi, ICE_RX_HDR_SIZE);
10561055
if (unlikely(!skb))
10571056
return NULL;
10581057

drivers/net/ethernet/intel/ice/ice_xsk.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,7 @@ ice_construct_skb_zc(struct ice_rx_ring *rx_ring, struct xdp_buff *xdp)
555555
}
556556
net_prefetch(xdp->data_meta);
557557

558-
skb = __napi_alloc_skb(&rx_ring->q_vector->napi, totalsize,
559-
GFP_ATOMIC | __GFP_NOWARN);
558+
skb = napi_alloc_skb(&rx_ring->q_vector->napi, totalsize);
560559
if (unlikely(!skb))
561560
return NULL;
562561

drivers/net/ethernet/intel/idpf/idpf_txrx.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3005,8 +3005,7 @@ struct sk_buff *idpf_rx_construct_skb(struct idpf_queue *rxq,
30053005
/* prefetch first cache line of first page */
30063006
net_prefetch(va);
30073007
/* allocate a skb to store the frags */
3008-
skb = __napi_alloc_skb(&rxq->q_vector->napi, IDPF_RX_HDR_SIZE,
3009-
GFP_ATOMIC);
3008+
skb = napi_alloc_skb(&rxq->q_vector->napi, IDPF_RX_HDR_SIZE);
30103009
if (unlikely(!skb)) {
30113010
idpf_rx_put_page(rx_buf);
30123011

@@ -3060,7 +3059,7 @@ static struct sk_buff *idpf_rx_hdr_construct_skb(struct idpf_queue *rxq,
30603059
struct sk_buff *skb;
30613060

30623061
/* allocate a skb to store the frags */
3063-
skb = __napi_alloc_skb(&rxq->q_vector->napi, size, GFP_ATOMIC);
3062+
skb = napi_alloc_skb(&rxq->q_vector->napi, size);
30643063
if (unlikely(!skb))
30653064
return NULL;
30663065

drivers/net/ethernet/intel/igc/igc_main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,8 +2712,7 @@ static struct sk_buff *igc_construct_skb_zc(struct igc_ring *ring,
27122712

27132713
net_prefetch(xdp->data_meta);
27142714

2715-
skb = __napi_alloc_skb(&ring->q_vector->napi, totalsize,
2716-
GFP_ATOMIC | __GFP_NOWARN);
2715+
skb = napi_alloc_skb(&ring->q_vector->napi, totalsize);
27172716
if (unlikely(!skb))
27182717
return NULL;
27192718

drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,7 @@ static struct sk_buff *ixgbe_construct_skb_zc(struct ixgbe_ring *rx_ring,
220220
net_prefetch(xdp->data_meta);
221221

222222
/* allocate a skb to store the frags */
223-
skb = __napi_alloc_skb(&rx_ring->q_vector->napi, totalsize,
224-
GFP_ATOMIC | __GFP_NOWARN);
223+
skb = napi_alloc_skb(&rx_ring->q_vector->napi, totalsize);
225224
if (unlikely(!skb))
226225
return NULL;
227226

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5109,9 +5109,8 @@ static struct sk_buff *stmmac_construct_skb_zc(struct stmmac_channel *ch,
51095109
unsigned int datasize = xdp->data_end - xdp->data;
51105110
struct sk_buff *skb;
51115111

5112-
skb = __napi_alloc_skb(&ch->rxtx_napi,
5113-
xdp->data_end - xdp->data_hard_start,
5114-
GFP_ATOMIC | __GFP_NOWARN);
5112+
skb = napi_alloc_skb(&ch->rxtx_napi,
5113+
xdp->data_end - xdp->data_hard_start);
51155114
if (unlikely(!skb))
51165115
return NULL;
51175116

include/linux/skbuff.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3350,13 +3350,7 @@ static inline void *napi_alloc_frag_align(unsigned int fragsz,
33503350
return __napi_alloc_frag_align(fragsz, -align);
33513351
}
33523352

3353-
struct sk_buff *__napi_alloc_skb(struct napi_struct *napi,
3354-
unsigned int length, gfp_t gfp_mask);
3355-
static inline struct sk_buff *napi_alloc_skb(struct napi_struct *napi,
3356-
unsigned int length)
3357-
{
3358-
return __napi_alloc_skb(napi, length, GFP_ATOMIC);
3359-
}
3353+
struct sk_buff *napi_alloc_skb(struct napi_struct *napi, unsigned int length);
33603354
void napi_consume_skb(struct sk_buff *skb, int budget);
33613355

33623356
void napi_skb_free_stolen_head(struct sk_buff *skb);

net/core/skbuff.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -775,10 +775,9 @@ struct sk_buff *__netdev_alloc_skb(struct net_device *dev, unsigned int len,
775775
EXPORT_SYMBOL(__netdev_alloc_skb);
776776

777777
/**
778-
* __napi_alloc_skb - allocate skbuff for rx in a specific NAPI instance
778+
* napi_alloc_skb - allocate skbuff for rx in a specific NAPI instance
779779
* @napi: napi instance this buffer was allocated for
780780
* @len: length to allocate
781-
* @gfp_mask: get_free_pages mask, passed to alloc_skb and alloc_pages
782781
*
783782
* Allocate a new sk_buff for use in NAPI receive. This buffer will
784783
* attempt to allocate the head from a special reserved region used
@@ -787,9 +786,9 @@ EXPORT_SYMBOL(__netdev_alloc_skb);
787786
*
788787
* %NULL is returned if there is no free memory.
789788
*/
790-
struct sk_buff *__napi_alloc_skb(struct napi_struct *napi, unsigned int len,
791-
gfp_t gfp_mask)
789+
struct sk_buff *napi_alloc_skb(struct napi_struct *napi, unsigned int len)
792790
{
791+
gfp_t gfp_mask = GFP_ATOMIC | __GFP_NOWARN;
793792
struct napi_alloc_cache *nc;
794793
struct sk_buff *skb;
795794
bool pfmemalloc;
@@ -860,7 +859,7 @@ struct sk_buff *__napi_alloc_skb(struct napi_struct *napi, unsigned int len,
860859
skb_fail:
861860
return skb;
862861
}
863-
EXPORT_SYMBOL(__napi_alloc_skb);
862+
EXPORT_SYMBOL(napi_alloc_skb);
864863

865864
void skb_add_rx_frag_netmem(struct sk_buff *skb, int i, netmem_ref netmem,
866865
int off, int size, unsigned int truesize)

0 commit comments

Comments
 (0)