mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wen Jiang <jiangwenxiaomi@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	Uladzislau Rezki <urezki@gmail.com>,
	linux-mm@kvack.org
Cc: Barry Song <baohua@kernel.org>,
	Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
	Anshuman Khandual <anshuman.khandual@arm.com>,
	David Hildenbrand <david@kernel.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>, Leo Yan <leo.yan@arm.com>,
	Xueyuan Chen <xueyuan.chen21@gmail.com>,
	Mike Rapoport <rppt@kernel.org>,
	Pasha Tatashin <pasha.tatashin@soleen.com>,
	Pratyush Yadav <pratyush@kernel.org>,
	Alexander Graf <graf@amazon.com>,
	kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Wen Jiang <jiangwen6@xiaomi.com>
Subject: [RFC PATCH 1/4] mm/vmalloc: extract vmalloc_area_map_range()
Date: Wed,  2 Dec 2026 17:12:09 +0800	[thread overview]
Message-ID: <20261202091212.363755-2-jiangwenxiaomi@gmail.com> (raw)
In-Reply-To: <20261202091212.363755-1-jiangwenxiaomi@gmail.com>

From: Wen Jiang <jiangwen6@xiaomi.com>

Move the mapping of a vmalloc area's pages, including the gfp scope,
the __GFP_NOFAIL retry loop and the failure warning, out of
__vmalloc_area_node() into vmalloc_area_map_range(). It maps the pages
[start, end) of the area, where start and end are indices into the page
array, with the given shift.

The warning for a failed mapping reports the size of the mapped range
instead of area->nr_pages. Both are the same at the only call site,
which maps the whole area.

__vmalloc_area_node() still maps the whole area in one go. A follow-up
change will map an area in several runs with different shifts.

No functional change.

Suggested-by: Barry Song <baohua@kernel.org>
Assisted-by: LLM
Signed-off-by: Wen Jiang <jiangwen6@xiaomi.com>
---
 mm/vmalloc.c | 64 +++++++++++++++++++++++++++++++---------------------
 1 file changed, 38 insertions(+), 26 deletions(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index aeb1cd4a53850..eb28dbd29c2e1 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -4005,6 +4005,42 @@ vm_area_alloc_pages(gfp_t gfp, int nid,
 	return nr_allocated;
 }
 
+static int vmalloc_area_map_range(struct vm_struct *area,
+		unsigned long start, unsigned long end, unsigned int shift,
+		pgprot_t prot, gfp_t gfp)
+{
+	const gfp_t nested_gfp = (gfp & GFP_RECLAIM_MASK) | __GFP_ZERO;
+	unsigned long addr = (unsigned long)area->addr;
+	bool nofail = gfp & __GFP_NOFAIL;
+	unsigned int flags;
+	int ret;
+
+	/* __GFP_NOFAIL and "noblock" flags are mutually exclusive. */
+	if (!gfpflags_allow_blocking(gfp))
+		nofail = false;
+
+	/*
+	 * page tables allocations ignore external gfp mask, enforce it
+	 * by the scope API
+	 */
+	flags = memalloc_apply_gfp_scope(gfp);
+	do {
+		ret = __vmap_pages_range(addr + (start << PAGE_SHIFT),
+				addr + (end << PAGE_SHIFT), prot,
+				area->pages + start, shift, nested_gfp);
+		if (nofail && (ret < 0))
+			schedule_timeout_uninterruptible(1);
+	} while (nofail && (ret < 0));
+	memalloc_restore_scope(flags);
+
+	if (ret < 0)
+		warn_alloc(gfp, NULL,
+			"vmalloc error: size %lu, failed to map pages",
+			(end - start) << PAGE_SHIFT);
+
+	return ret;
+}
+
 static LLIST_HEAD(pending_vm_area_cleanup);
 static void cleanup_vm_area_work(struct work_struct *work)
 {
@@ -4078,21 +4114,13 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
 				 int node)
 {
 	const gfp_t nested_gfp = (gfp_mask & GFP_RECLAIM_MASK) | __GFP_ZERO;
-	bool nofail = gfp_mask & __GFP_NOFAIL;
-	unsigned long addr = (unsigned long)area->addr;
 	unsigned long size = get_vm_area_size(area);
 	unsigned long array_size;
 	unsigned long nr_small_pages = size >> PAGE_SHIFT;
 	unsigned int page_order = page_shift - PAGE_SHIFT;
-	unsigned int flags;
-	int ret;
 
 	array_size = nr_small_pages * sizeof(struct page *);
 
-	/* __GFP_NOFAIL and "noblock" flags are mutually exclusive. */
-	if (!gfpflags_allow_blocking(gfp_mask))
-		nofail = false;
-
 	if (!(gfp_mask & (GFP_DMA | GFP_DMA32)))
 		gfp_mask |= __GFP_HIGHMEM;
 
@@ -4145,25 +4173,9 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
 		goto fail;
 	}
 
-	/*
-	 * page tables allocations ignore external gfp mask, enforce it
-	 * by the scope API
-	 */
-	flags = memalloc_apply_gfp_scope(gfp_mask);
-	do {
-		ret = __vmap_pages_range(addr, addr + size, prot, area->pages,
-				page_shift, nested_gfp);
-		if (nofail && (ret < 0))
-			schedule_timeout_uninterruptible(1);
-	} while (nofail && (ret < 0));
-	memalloc_restore_scope(flags);
-
-	if (ret < 0) {
-		warn_alloc(gfp_mask, NULL,
-			"vmalloc error: size %lu, failed to map pages",
-			area->nr_pages * PAGE_SIZE);
+	if (vmalloc_area_map_range(area, 0, nr_small_pages, page_shift, prot,
+				   gfp_mask))
 		goto fail;
-	}
 
 	set_vm_area_page_order(area, page_order);
 	return area->addr;
-- 
2.34.1


  reply	other threads:[~2026-12-02  9:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  9:12 [RFC PATCH 0/4] mm/vmalloc: Reduce memory usage and speed up huge vmalloc Wen Jiang
2026-12-02  9:12 ` Wen Jiang [this message]
2026-12-02  9:12 ` [RFC PATCH 2/4] mm/vmalloc: add VM_HAS_HUGE_VMAP Wen Jiang
2026-12-02  9:12 ` [RFC PATCH 3/4] mm/vmalloc: try smaller block sizes before base pages Wen Jiang
2026-12-02  9:12 ` [RFC PATCH 4/4] mm/vmalloc: page align huge vmalloc sizes Wen Jiang
2026-12-02 12:09 ` [RFC PATCH 0/4] mm/vmalloc: Reduce memory usage and speed up huge vmalloc Dev Jain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202091212.363755-2-jiangwenxiaomi@gmail.com \
    --to=jiangwenxiaomi@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=anshuman.khandual@arm.com \
    --cc=baohua@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=graf@amazon.com \
    --cc=jiangwen6@xiaomi.com \
    --cc=kexec@lists.infradead.org \
    --cc=leo.yan@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=pasha.tatashin@soleen.com \
    --cc=pratyush@kernel.org \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=urezki@gmail.com \
    --cc=will@kernel.org \
    --cc=xueyuan.chen21@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®