Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next] net/packet: don't direct reclaim for contiguous ring blocks
@ 2026-11-17  8:59 Daniil Tatianin
  2026-11-18 22:45 ` Willem de Bruijn
  0 siblings, 1 reply; 2+ messages in thread
From: Daniil Tatianin @ 2026-11-17  8:59 UTC (permalink / raw)
  To: Willem de Bruijn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: Daniil Tatianin, Simon Horman, netdev, linux-kernel

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] net/packet: don't direct reclaim for contiguous ring blocks
  2026-11-17  8:59 [PATCH net-next] net/packet: don't direct reclaim for contiguous ring blocks Daniil Tatianin
@ 2026-11-18 22:45 ` Willem de Bruijn
  0 siblings, 0 replies; 2+ messages in thread
From: Willem de Bruijn @ 2026-11-18 22:45 UTC (permalink / raw)
  To: Daniil Tatianin, Willem de Bruijn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Daniil Tatianin, Simon Horman, netdev, linux-kernel

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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-18 22:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17  8:59 [PATCH net-next] net/packet: don't direct reclaim for contiguous ring blocks Daniil Tatianin
2026-11-18 22:45 ` Willem de Bruijn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox