[PATCH net-next] net/packet: don't direct reclaim for contiguous ring blocks

From: Daniil Tatianin

Date: Tue Nov 17 2026 - 04:00:19 EST


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@xxxxxxxxxxxxxx>
---
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