Skip to content

Commit cfe7bef

Browse files
edumazetsashalevin
authored andcommitted
net: do not deplete pfmemalloc reserve
[ Upstream commit 79930f5 ] build_skb() should look at the page pfmemalloc status. If set, this means page allocator allocated this page in the expectation it would help to free other pages. Networking stack can do that only if skb->pfmemalloc is also set. Also, we must refrain using high order pages from the pfmemalloc reserve, so __page_frag_refill() must also use __GFP_NOMEMALLOC for them. Under memory pressure, using order-0 pages is probably the best strategy. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
1 parent b5635e4 commit cfe7bef

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎net/core/skbuff.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,11 @@ struct sk_buff *build_skb(void *data, unsigned int frag_size)
309309

310310
memset(skb, 0, offsetof(struct sk_buff, tail));
311311
skb->truesize = SKB_TRUESIZE(size);
312-
skb->head_frag = frag_size != 0;
312+
if (frag_size) {
313+
skb->head_frag = 1;
314+
if (virt_to_head_page(data)->pfmemalloc)
315+
skb->pfmemalloc = 1;
316+
}
313317
atomic_set(&skb->users, 1);
314318
skb->head = data;
315319
skb->data = data;
@@ -352,7 +356,8 @@ static void *__netdev_alloc_frag(unsigned int fragsz, gfp_t gfp_mask)
352356
gfp_t gfp = gfp_mask;
353357

354358
if (order)
355-
gfp |= __GFP_COMP | __GFP_NOWARN;
359+
gfp |= __GFP_COMP | __GFP_NOWARN |
360+
__GFP_NOMEMALLOC;
356361
nc->frag.page = alloc_pages(gfp, order);
357362
if (likely(nc->frag.page))
358363
break;

0 commit comments

Comments
 (0)