Skip to contentSkip to conversation

net/packet: simply allocations in alloc_one_pg_vec_page

PATCH In review Shakeel Butt 3 participants 7 messages May 16, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/packet: simply allocations in alloc_one_pg_vec_page

Currently the initial allocation for pg_vec buffers are done through page allocator with __GFP_NORETRY, the first fallbacks is vzalloc and the second fallback is page allocator without __GFP_NORETRY.

First, there is no need to do vzalloc if the order is 0 and second the vzalloc internally use GFP_KERNEL for each individual page allocation and thus there is no need to have any fallback after vzalloc.

---
 net/packet/af_packet.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
net/packet/af_packet.c +4 -11
index 29bd405adbbd..d6f96b9f5b01 100644
@@ -4243,19 +4243,12 @@ static char *alloc_one_pg_vec_page(unsigned long order)
 	if (buffer)
 		return buffer;
 
-	/* __get_free_pages failed, fall back to vmalloc */
-	buffer = vzalloc(array_size((1 << order), PAGE_SIZE));
-	if (buffer)
-		return buffer;
+	/* __get_free_pages failed, fall back to vmalloc for high order. */
+	if (order)
+		return vzalloc(array_size((1 << order), PAGE_SIZE));
 
-	/* vmalloc failed, lets dig into swap here */
 	gfp_flags &= ~__GFP_NORETRY;
-	buffer = (char *) __get_free_pages(gfp_flags, order);
-	if (buffer)
-		return buffer;
-
-	/* complete and utter failure */
-	return NULL;
+	return (char *)__get_free_pages(gfp_flags, order);
 }
 
 static struct pgv *alloc_pg_vec(struct tpacket_req *req, int order)
Signature · 1 line
2.26.2.761.g0e0b3e54be-goog
maintainer
#1 lore raw

From: Shakeel Butt <[email protected]>
Date: Fri, 15 May 2020 19:17:36 -0700

Quoted 1 line

and thus there is no need to have any fallback after vzalloc.

This statement is false.

The virtual mapping allocation or the page table allocations can fail.

A fallback is therefore indeed necessary.

#2 lore raw
Quoted 11 lines · David Miller

From: Shakeel Butt <[email protected]>
Date: Fri, 15 May 2020 19:17:36 -0700

Quoted 1 line

and thus there is no need to have any fallback after vzalloc.

This statement is false.

The virtual mapping allocation or the page table allocations can fail.

A fallback is therefore indeed necessary.

I am assuming that you at least agree that vzalloc should only be called for non-zero order allocations. So, my argument is if non-zero order vzalloc has failed (allocations internal to vzalloc, including virtual mapping allocation and page table allocations, are order 0 and use GFP_KERNEL i.e. triggering reclaim and oom-killer) then the next non-zero order page allocation has very low chance of succeeding.

#3 lore raw
Quoted 12 lines · Shakeel Butt
Quoted 10 lines · David Miller

From: Shakeel Butt <[email protected]>
Date: Fri, 15 May 2020 19:17:36 -0700

Quoted 1 line

and thus there is no need to have any fallback after vzalloc.

This statement is false.

The virtual mapping allocation or the page table allocations can fail.

Quoted 8 lines
Quoted 1 line

A fallback is therefore indeed necessary.

I am assuming that you at least agree that vzalloc should only be called for non-zero order allocations. So, my argument is if non-zero order vzalloc has failed (allocations internal to vzalloc, including virtual mapping allocation and page table allocations, are order 0 and use GFP_KERNEL i.e. triggering reclaim and oom-killer) then the next non-zero order page allocation has very low chance of succeeding.

32bit kernels might have exhausted their vmalloc space, yet they can still allocate order-0 pages.

#4 lore raw
Quoted 24 lines · Eric Dumazet
Quoted 12 lines · Shakeel Butt
Quoted 10 lines · David Miller

From: Shakeel Butt <[email protected]>
Date: Fri, 15 May 2020 19:17:36 -0700

Quoted 1 line

and thus there is no need to have any fallback after vzalloc.

This statement is false.

The virtual mapping allocation or the page table allocations can fail.

Quoted 8 lines
Quoted 1 line

A fallback is therefore indeed necessary.

I am assuming that you at least agree that vzalloc should only be called for non-zero order allocations. So, my argument is if non-zero order vzalloc has failed (allocations internal to vzalloc, including virtual mapping allocation and page table allocations, are order 0 and use GFP_KERNEL i.e. triggering reclaim and oom-killer) then the next non-zero order page allocation has very low chance of succeeding.

Quoted 2 lines

32bit kernels might have exhausted their vmalloc space, yet they can still allocate order-0 pages.

Oh ok it makes sense.

maintainer
#5 lore raw
In reply to Shakeel Butt

From: Shakeel Butt <[email protected]>
Date: Sat, 16 May 2020 15:35:46 -0700

Quoted 5 lines

So, my argument is if non-zero order vzalloc has failed (allocations internal to vzalloc, including virtual mapping allocation and page table allocations, are order 0 and use GFP_KERNEL i.e. triggering reclaim and oom-killer) then the next non-zero order page allocation has very low chance of succeeding.

Also not true.

Page table allocation strategies and limits vary by architecture, they may even need virtual mappings themselves. So they can fail in situations where a non-zero GFP_KERNEL page allocator allocation would succeed.

#6 lore raw
Quoted 10 lines · David Miller

From: Shakeel Butt <[email protected]>
Date: Sat, 16 May 2020 15:35:46 -0700

Quoted 5 lines

So, my argument is if non-zero order vzalloc has failed (allocations internal to vzalloc, including virtual mapping allocation and page table allocations, are order 0 and use GFP_KERNEL i.e. triggering reclaim and oom-killer) then the next non-zero order page allocation has very low chance of succeeding.

Quoted 5 lines

Also not true.

Page table allocation strategies and limits vary by architecture, they may even need virtual mappings themselves. So they can fail in situations where a non-zero GFP_KERNEL page allocator allocation would succeed.

Thanks for the explanation. Do you think calling vzalloc only for non-zero order here has any value?