[RFC 3/7] mm/vmalloc: Avoid cond_resched() when blocking is not permitted

From: Uladzislau Rezki (Sony)
Date: Fri Jul 04 2025 - 11:26:17 EST


The vm_area_alloc_pages() function uses cond_resched() to yield the
CPU during potentially long-running loops. However, yielding should
only be done if the given GFP flags allow blocking.

This patch avoids calling cond_resched() when the allocation context
is non-blocking(GFP_ATOMIC, GFP_NOWAIT).

Signed-off-by: Uladzislau Rezki (Sony) <urezki@xxxxxxxxx>
---
mm/vmalloc.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 8c375b8e269d..25d09f753239 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -3624,7 +3624,9 @@ vm_area_alloc_pages(gfp_t gfp, int nid,
pages + nr_allocated);

nr_allocated += nr;
- cond_resched();
+
+ if (gfpflags_allow_blocking(gfp))
+ cond_resched();

/*
* If zero or pages were obtained partly,
@@ -3666,7 +3668,9 @@ vm_area_alloc_pages(gfp_t gfp, int nid,
for (i = 0; i < (1U << order); i++)
pages[nr_allocated + i] = page + i;

- cond_resched();
+ if (gfpflags_allow_blocking(gfp))
+ cond_resched();
+
nr_allocated += 1U << order;
}

--
2.39.5