Linux-ARM-Kernel Archive on lore.kernel.org
 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 2/4] mm/vmalloc: add VM_HAS_HUGE_VMAP
Date: Wed,  2 Dec 2026 17:12:10 +0800	[thread overview]
Message-ID: <20261202091212.363755-3-jiangwenxiaomi@gmail.com> (raw)
In-Reply-To: <20261202091212.363755-1-jiangwenxiaomi@gmail.com>

From: Wen Jiang <jiangwen6@xiaomi.com>

vrealloc() frees the tail pages of a shrinking area unless its
page_order is non-zero, as partial freeing would require splitting a
huge mapping, and is_vm_area_hugepages() reports huge mappings from
page_order as well. Both rely on a huge vmalloc area being mapped
either entirely with blocks of 1 << page_order pages or entirely with
base pages.

A follow-up change lets a huge vmalloc area fall back to smaller block
sizes for part of the area. page_order then has to be the smallest
order used, so that the page array can still be walked in steps of
1 << page_order. It can be 0 for an area that still contains PMD or
contiguous PTE mappings.

Add an internal VM_HAS_HUGE_VMAP flag, set when at least part of an
area is mapped with entries larger than PAGE_SIZE, and use it in
vrealloc() and is_vm_area_hugepages() instead of page_order. Together
with page_order it describes the layout:

  !VM_HAS_HUGE_VMAP                  base pages only
  VM_HAS_HUGE_VMAP, page_order == 0  huge mappings plus base pages
  VM_HAS_HUGE_VMAP, page_order > 0   huge mappings only

For vrealloc() and the powerpc set_memory_*() guard, any huge mapping
is reason enough to back off. alloc_large_system_hash() only uses the
result for its boot message.

set_vm_area_page_order() sets the flag for a non-zero order, so for
now the flag is set exactly when page_order is non-zero and there is no
functional change.

Like page_order, the flag is only set by the vmalloc allocation path.
Huge mappings created by vmap() or ioremap() are tracked by neither.

Let kho_preserve_vmalloc() accept the new flag, as it rejects any flag
it does not know about.

Suggested-by: Barry Song <baohua@kernel.org>
Assisted-by: LLM
Signed-off-by: Wen Jiang <jiangwen6@xiaomi.com>
---
 include/linux/vmalloc.h            | 7 ++++---
 kernel/liveupdate/kexec_handover.c | 3 ++-
 mm/vmalloc.c                       | 9 ++++++---
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index 034a693777ca0..31be61ad88550 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -40,6 +40,7 @@ struct iov_iter;		/* in uio.h */
 #endif
 #define VM_SPARSE		0x00001000	/* sparse vm_area. not all pages are present. */
 #define VM_REQUIRE_HUGE_VMAP	0x00002000	/* huge page mapping or nothing */
+#define VM_HAS_HUGE_VMAP	0x00004000	/* part of the area has huge mappings */
 
 /* bits [20..32] reserved for arch specific ioremap internals */
 
@@ -265,13 +266,13 @@ static inline bool is_vm_area_hugepages(const void *addr)
 	 * This may not 100% tell if the area is mapped with > PAGE_SIZE
 	 * page table entries, if for some reason the architecture indicates
 	 * larger sizes are available but decides not to use them, nothing
-	 * prevents that. This only indicates the size of the physical page
-	 * allocated in the vmalloc layer.
+	 * prevents that. This only indicates that the vmalloc layer mapped
+	 * at least part of the area with such entries.
 	 */
 #ifdef CONFIG_HAVE_ARCH_HUGE_VMALLOC
 	struct vm_struct *area = find_vm_area(addr);
 
-	return area && area->page_order > 0;
+	return area && (area->flags & VM_HAS_HUGE_VMAP);
 #else
 	return false;
 #endif
diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c
index 42c6609a1766a..c2d5823b498a3 100644
--- a/kernel/liveupdate/kexec_handover.c
+++ b/kernel/liveupdate/kexec_handover.c
@@ -1288,7 +1288,8 @@ void kho_unpreserve_pages(struct page *page, unsigned long nr_pages)
 EXPORT_SYMBOL_GPL(kho_unpreserve_pages);
 
 /* vmalloc flags KHO supports */
-#define KHO_VMALLOC_SUPPORTED_FLAGS	(VM_ALLOC | VM_ALLOW_HUGE_VMAP)
+#define KHO_VMALLOC_SUPPORTED_FLAGS	(VM_ALLOC | VM_ALLOW_HUGE_VMAP | \
+					 VM_HAS_HUGE_VMAP)
 
 /* KHO internal flags for vmalloc preservations */
 #define KHO_VMALLOC_ALLOC	0x0001
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index eb28dbd29c2e1..595b07a6cc3d1 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -3222,6 +3222,8 @@ static inline void set_vm_area_page_order(struct vm_struct *vm, unsigned int ord
 {
 #ifdef CONFIG_HAVE_ARCH_HUGE_VMALLOC
 	vm->page_order = order;
+	if (order)
+		vm->flags |= VM_HAS_HUGE_VMAP;
 #else
 	BUG_ON(order != 0);
 #endif
@@ -4613,7 +4615,7 @@ void *vrealloc_node_align_noprof(const void *p, size_t size, unsigned long align
 		/*
 		 * Free tail pages when shrink crosses a page boundary.
 		 *
-		 * Skip huge page allocations (page_order > 0) as partial
+		 * Skip areas with huge mappings (VM_HAS_HUGE_VMAP) as partial
 		 * freeing would require splitting.
 		 *
 		 * Skip VM_FLUSH_RESET_PERMS, as direct-map permissions must
@@ -4629,8 +4631,9 @@ void *vrealloc_node_align_noprof(const void *p, size_t size, unsigned long align
 		 * GFP_KERNEL, which could trigger a recursive deadlock
 		 * if we are under filesystem or I/O reclaim.
 		 */
-		if (new_nr_pages < vm->nr_pages && !vm_area_page_order(vm) &&
-		    !(vm->flags & (VM_FLUSH_RESET_PERMS | VM_USERMAP)) &&
+		if (new_nr_pages < vm->nr_pages &&
+		    !(vm->flags & (VM_HAS_HUGE_VMAP | VM_FLUSH_RESET_PERMS |
+				   VM_USERMAP)) &&
 		    gfp_has_io_fs(flags)) {
 			unsigned long addr = (unsigned long)kasan_reset_tag(p);
 			unsigned long old_nr_pages = vm->nr_pages;
-- 
2.34.1



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

Thread overview: 5+ 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 ` [RFC PATCH 1/4] mm/vmalloc: extract vmalloc_area_map_range() Wen Jiang
2026-12-02  9:12 ` Wen Jiang [this message]
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

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-3-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