🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
3 messages
3 total messages Started by Daniil Tatianin Tue, 17 Nov 2026 08:59
[PATCH net-next] net/packet: don't direct reclaim for contiguous ring blocks
#17711
Author: Daniil Tatianin
Date: Tue, 17 Nov 2026 08:59
48 lines
10115 bytes
alloc_one_pg_vec_page() first asks the page allocator for a physically
contiguous block and falls back to vmalloc if that fails.  The first
attempt uses __GFP_NORETRY, but that still allows one round of direct
compaction and reclaim before giving up.  Under fragmentation every
block of a ring pays for that round, so setting up a ring can stall the
caller for seconds even though vmalloc would have worked right away.

On hosts that run tcpdump periodically we saw ring setup (8 order-6
blocks) stall for up to 1.4 s per block and 3.5 s per ring.

The contiguous block is only an optimization.  User space maps the ring
page by page either way.  So make the first attempt without direct
reclaim, as kvmalloc() already does since commit 46459154f997
("mm: kvmalloc: make kmalloc fast path real fast path").  kswapd is
still woken.  The last resort attempt after a failed vmalloc keeps
direct reclaim.  Order-0 blocks are left alone, the vmalloc fallback
would reclaim for them anyway.

Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
---
 net/packet/af_packet.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 8250e6a791f6..38f35a4f9d49 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -4493,8 +4493,16 @@ static char *alloc_one_pg_vec_page(unsigned long order)
 	char *buffer;
 	gfp_t gfp_flags = GFP_KERNEL_ACCOUNT | __GFP_COMP |
 			  __GFP_ZERO | __GFP_NOWARN | __GFP_NORETRY;
+	gfp_t first_gfp_flags = gfp_flags;
 
-	buffer = (char *) __get_free_pages(gfp_flags, order);
+	/*
+	 * A contiguous block is only an optimization because vmalloc works
+	 * too. Do not stall in reclaim or compaction to get one.
+	 */
+	if (order)
+		first_gfp_flags &= ~__GFP_DIRECT_RECLAIM;
+
+	buffer = (char *) __get_free_pages(first_gfp_flags, order);
 	if (buffer)
 		return buffer;
 

base-commit: 073d54dc3ccc8c8109c56e4d984d1ad616554463
Re: [PATCH net-next] net/packet: don't direct reclaim for contiguous ring blocks
#18785
Author: Willem de Bruijn
Date: Wed, 18 Nov 2026 22:45
52 lines
13231 bytes
Daniil Tatianin wrote:
> alloc_one_pg_vec_page() first asks the page allocator for a physically
> contiguous block and falls back to vmalloc if that fails.  The first
> attempt uses __GFP_NORETRY, but that still allows one round of direct
> compaction and reclaim before giving up.  Under fragmentation every
> block of a ring pays for that round, so setting up a ring can stall the
> caller for seconds even though vmalloc would have worked right away.
> 
> On hosts that run tcpdump periodically we saw ring setup (8 order-6
> blocks) stall for up to 1.4 s per block and 3.5 s per ring.

Is this still the case with recent commit 0e05a469c294 ("mm/page_alloc:
avoid direct reclaim and compaction for costly __GFP_NORETRY allocations")?

> The contiguous block is only an optimization.  User space maps the ring
> page by page either way.  So make the first attempt without direct
> reclaim, as kvmalloc() already does since commit 46459154f997
> ("mm: kvmalloc: make kmalloc fast path real fast path").  kswapd is
> still woken.  The last resort attempt after a failed vmalloc keeps
> direct reclaim.  Order-0 blocks are left alone, the vmalloc fallback
> would reclaim for them anyway.
> 
> Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
> ---
>  net/packet/af_packet.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> index 8250e6a791f6..38f35a4f9d49 100644
> --- a/net/packet/af_packet.c
> +++ b/net/packet/af_packet.c
> @@ -4493,8 +4493,16 @@ static char *alloc_one_pg_vec_page(unsigned long order)
>  	char *buffer;
>  	gfp_t gfp_flags = GFP_KERNEL_ACCOUNT | __GFP_COMP |
>  			  __GFP_ZERO | __GFP_NOWARN | __GFP_NORETRY;
> +	gfp_t first_gfp_flags = gfp_flags;
>  
> -	buffer = (char *) __get_free_pages(gfp_flags, order);
> +	/*
> +	 * A contiguous block is only an optimization because vmalloc works
> +	 * too. Do not stall in reclaim or compaction to get one.
> +	 */
> +	if (order)
> +		first_gfp_flags &= ~__GFP_DIRECT_RECLAIM;
> +
> +	buffer = (char *) __get_free_pages(first_gfp_flags, order);
>  	if (buffer)
>  		return buffer;
>  
> 
> base-commit: 073d54dc3ccc8c8109c56e4d984d1ad616554463
Re: [PATCH net-next] net/packet: don't direct reclaim for contiguous ring blocks
#18795
Author: Daniil Tatianin
Date: Wed, 18 Nov 2026 23:12
58 lines
11001 bytes
On 11/19/26 1:45 AM, Willem de Bruijn wrote:

> Daniil Tatianin wrote:
>> alloc_one_pg_vec_page() first asks the page allocator for a physically
>> contiguous block and falls back to vmalloc if that fails.  The first
>> attempt uses __GFP_NORETRY, but that still allows one round of direct
>> compaction and reclaim before giving up.  Under fragmentation every
>> block of a ring pays for that round, so setting up a ring can stall the
>> caller for seconds even though vmalloc would have worked right away.
>>
>> On hosts that run tcpdump periodically we saw ring setup (8 order-6
>> blocks) stall for up to 1.4 s per block and 3.5 s per ring.
> Is this still the case with recent commit 0e05a469c294 ("mm/page_alloc:
> avoid direct reclaim and compaction for costly __GFP_NORETRY allocations")?

I think this fixes the issue for order > 3, so my patch is not needed 
anymore.
Thanks for pointing it out!

>
>> The contiguous block is only an optimization.  User space maps the ring
>> page by page either way.  So make the first attempt without direct
>> reclaim, as kvmalloc() already does since commit 46459154f997
>> ("mm: kvmalloc: make kmalloc fast path real fast path").  kswapd is
>> still woken.  The last resort attempt after a failed vmalloc keeps
>> direct reclaim.  Order-0 blocks are left alone, the vmalloc fallback
>> would reclaim for them anyway.
>>
>> Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
>> ---
>>   net/packet/af_packet.c | 10 +++++++++-
>>   1 file changed, 9 insertions(+), 1 deletion(-)
>>
>> diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
>> index 8250e6a791f6..38f35a4f9d49 100644
>> --- a/net/packet/af_packet.c
>> +++ b/net/packet/af_packet.c
>> @@ -4493,8 +4493,16 @@ static char *alloc_one_pg_vec_page(unsigned long order)
>>   	char *buffer;
>>   	gfp_t gfp_flags = GFP_KERNEL_ACCOUNT | __GFP_COMP |
>>   			  __GFP_ZERO | __GFP_NOWARN | __GFP_NORETRY;
>> +	gfp_t first_gfp_flags = gfp_flags;
>>   
>> -	buffer = (char *) __get_free_pages(gfp_flags, order);
>> +	/*
>> +	 * A contiguous block is only an optimization because vmalloc works
>> +	 * too. Do not stall in reclaim or compaction to get one.
>> +	 */
>> +	if (order)
>> +		first_gfp_flags &= ~__GFP_DIRECT_RECLAIM;
>> +
>> +	buffer = (char *) __get_free_pages(first_gfp_flags, order);
>>   	if (buffer)
>>   		return buffer;
>>   
>>
>> base-commit: 073d54dc3ccc8c8109c56e4d984d1ad616554463
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads