Skip to contentSkip to conversation

mm/vmalloc: free unused pages on vrealloc() shrink

PATCH Applied Shivam Kalra 2 participants 9 messages May 19 – May 25

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v14 cover mm/vmalloc: free unused pages on vrealloc() shrink

This series implements the TODO in vrealloc() to unmap and free unused pages when shrinking across a page boundary.

Problem:
When vrealloc() shrinks an allocation, it updates bookkeeping (requested_size, KASAN shadow) but does not free the underlying physical pages. This wastes memory for the lifetime of the allocation.

Solution:
- Patch 1: Extracts a vm_area_free_pages(vm, start_idx, end_idx) helper from vfree() that frees a range of pages with memcg and nr_vmalloc_pages accounting. Freed page pointers are set to NULL to prevent stale references.
- Patch 2: Update the grow-in-place check in vrealloc() to compare the requested size against the actual physical page count (vm->nr_pages) rather than the virtual area sizes. This is a prerequisite for shrinking.
- Patch 3: For VM_ALLOC areas in vread_iter(), derive the vm area size from vm->nr_pages rather than get_vm_area_size(), which would overestimate the mapped range after a shrink. Other mapping types (vmap, ioremap) don't set nr_pages and keep using get_vm_area_size().
- Patch 4: Uses the helper to free tail pages when vrealloc() shrinks across a page boundary.
- Patch 5: Adds a vrealloc test case to lib/test_vmalloc that exercises grow-realloc, shrink-across-boundary, shrink-within-page, and grow-in-place paths.

The virtual address reservation is kept intact to preserve the range for potential future grow-in-place support.
A concrete user is the Rust binder driver's KVVec::shrink_to [1], which performs explicit vrealloc() shrinks for memory reclamation.

Tested:
- KASAN KUnit (vmalloc_oob passes)
- lib/test_vmalloc stress tests (3/3, 1M iterations each)
- checkpatch, sparse, W=1, allmodconfig, coccicheck clean

[1] https://lore.kernel.org/all/[email protected]/

---
Changes in v14:
- Scope nr_pages usage in vread_iter() to VM_ALLOC areas only;
vmap() areas don't initialize nr_pages. (Sashiko, Uladzislau Rezki)
- Link to v13: https://patch.msgid.link/[email protected]

Changes in v13:
- Collect all r-b tags
- Resubmit for Review.
- Link to v12: https://lore.kernel.org/r/[email protected]

Changes in v12:
- Rewrite vm_area_free_pages() to use free_pages_bulk()
following the upstream vfree() refactoring.(Andrew)
- Drop Reviewed-by tags from Patch 1 due to the rewrite
- Rebase to latest mm-new
- Link to v11: https://lore.kernel.org/r/[email protected]

Changes in v11:
- Prepare vread_iter() to use vm->nr_pages instead of
get_vm_area_size() (Uladzislau Rezki, Sashiko)
- Drop (size_t) cast from nr_pages << PAGE_SHIFT (Uladzislau Rezki)
- Link to v10: https://lore.kernel.org/r/[email protected]

Changes in v10:
- Reorder vm->nr_pages to the beginning (Alice Ryhl)
- Link to v9: https://lore.kernel.org/r/[email protected]

Changes in v9:
- Remove READ_ONCE, WRITE_ONCE and drop commit
about show_numa_info. (Uladzislau Rezki)
- Update the commit message in Patch 2. (Alice Ryhl)
- Remove zero newly exposed memory commit.
- Link to v8: https://lore.kernel.org/r/[email protected]

Changes in v8:
- Strip the KASAN tag from the pointer before addr_to_node()
to avoid acquiring the wrong node lock (Sashiko).
- Rebase to latest mm-new.
- Link to v7: https://lore.kernel.org/r/[email protected]

Changes in v7:
- Fix NULL pointer dereference in shrink path (Sashiko)
- Acquire vn->busy.lock when updating vm->nr_pages to synchronize
with concurrent readers (Uladzislau Rezki)
- Use READ_ONCE in vmalloc_dump_obj (Sashiko)
- Skip shrink path on GFP_NIO or GFP_NOFS. (Sashiko)
- Fix Overflow issue for large allocations. (Sashiko)
- Use vrealloc instead of vmalloc in vrealloc test.
- Link to v6: https://lore.kernel.org/r/[email protected]

Changes in v6:
- Fix VM_USERMAP crash by explicitly bypassing early in the shrink path if the flag is set.(Sashiko)
- Fix Kmemleak scanner panic by calling kmemleak_free_part() to update tracking on shrink.(Sashiko)
- Fix /proc/vmallocinfo race condition by protecting vm->nr_pages access with READ_ONCE()/WRITE_ONCE() for concurrent readers.(Sashiko)
- Fix stale data leak on grow-after-shrink by enforcing mandatory zeroing of the newly exposed memory.(Sashiko)
- Fix memory leaks in vrealloc_test() by using a temporary pointer to preserve and
free the original allocation upon failure.(Sashiko)
- Rename vmalloc_free_pages parameters from start/end to start_idx/end_idx for better clarity.(Uladzislau Rezki)
- Link to v5: https://lore.kernel.org/r/[email protected]
- Link to Sashiko: https://sashiko.dev/#/patchset/20260317-vmalloc-shrink-v5-0-bbfbf54c5265%40zohomail.in

Changes in v5:
- Skip vrealloc shrink for VM_FLUSH_RESET_PERMS (Uladzislau Rezki)
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Rename vmalloc_free_pages() to vm_area_free_pages() to align with vm_area_alloc_pages() (Uladzislau Rezki)
- NULL out freed vm->pages[] entries to prevent stale pointers (Alice Ryhl)
- Remove redundant if (vm->nr_pages) guard in vfree() (Uladzislau Rezki)
- Add vrealloc test case to lib/test_vmalloc (new patch 3/3)
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Restore the comment.
- Rebase to the latest mm-new
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Updated the base-commit to mm-new
- Fix conflicts after rebase
- Ran clang-format on the changes made
- Use a single kasan_vrealloc (Alice Ryhl)
- Link to v1: https://lore.kernel.org/r/[email protected]

To: Andrew Morton <[email protected]>
To: Uladzislau Rezki <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
Shivam Kalra (5):
mm/vmalloc: extract vm_area_free_pages() helper from vfree() mm/vmalloc: use physical page count for vrealloc() grow-in-place check mm/vmalloc: use physical page count in vread_iter() for VM_ALLOC areas mm/vmalloc: free unused pages on vrealloc() shrink lib/test_vmalloc: add vrealloc test case

 lib/test_vmalloc.c |  62 ++++++++++++++++++++++++++++++
 mm/vmalloc.c       | 111 ++++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 160 insertions(+), 13 deletions(-)

---
base-commit: a277a07d19bffcad38dea57bc234d0810a328657
change-id: 20260302-vmalloc-shrink-04b2fa688a14

Best regards,

Signature · 1 line
Shivam Kalra <[email protected]>
#1 lore raw

PATCH v14 1/5 mm/vmalloc: extract vm_area_free_pages() helper from vfree()

Extract page freeing and NR_VMALLOC stat accounting from vfree() into a reusable vm_area_free_pages() helper. The helper operates on a range [start_idx, end_idx) of pages from a vm_struct, making it suitable for both full free (vfree) and partial free (upcoming vrealloc shrink).

Freed page pointers in vm->pages[] are set to NULL to prevent stale references when the vm_struct outlives the free (as in vrealloc shrink).

---
 mm/vmalloc.c | 34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)
mm/vmalloc.c +27 -7
index eabb86b13b7e..5555601b9529 100644
@@ -3416,6 +3416,32 @@ void vfree_atomic(const void *addr)
 		schedule_work(&p->wq);
 }
 
+/*
+ * vm_area_free_pages - free a range of pages from a vmalloc allocation
+ * @vm: the vm_struct containing the pages
+ * @start_idx: first page index to free (inclusive)
+ * @end_idx: last page index to free (exclusive)
+ *
+ * Free pages [start_idx, end_idx) updating NR_VMALLOC stat accounting.
+ * Freed vm->pages[] entries are set to NULL.
+ * Caller is responsible for unmapping (vunmap_range) and KASAN
+ * poisoning before calling this.
+ */
+static void vm_area_free_pages(struct vm_struct *vm, unsigned int start_idx,
+			       unsigned int end_idx)
+{
+	unsigned int i;
+
+	if (!(vm->flags & VM_MAP_PUT_PAGES)) {
+		for (i = start_idx; i < end_idx; i++)
+			mod_lruvec_page_state(vm->pages[i], NR_VMALLOC, -1);
+	}
+	free_pages_bulk(vm->pages + start_idx, end_idx - start_idx);
+
+	for (i = start_idx; i < end_idx; i++)
+		vm->pages[i] = NULL;
+}
+
 /**
  * vfree - Release memory allocated by vmalloc()
  * @addr:  Memory base address
@@ -3436,7 +3462,6 @@ void vfree_atomic(const void *addr)
 void vfree(const void *addr)
 {
 	struct vm_struct *vm;
-	int i;
 
 	if (unlikely(in_interrupt())) {
 		vfree_atomic(addr);
@@ -3460,12 +3485,7 @@ void vfree(const void *addr)
 	if (unlikely(vm->flags & VM_FLUSH_RESET_PERMS))
 		vm_reset_perms(vm);
 
-	if (!(vm->flags & VM_MAP_PUT_PAGES)) {
-		for (i = 0; i < vm->nr_pages; i++)
-			mod_lruvec_page_state(vm->pages[i], NR_VMALLOC, -1);
-	}
-	free_pages_bulk(vm->pages, vm->nr_pages);
-
+	vm_area_free_pages(vm, 0, vm->nr_pages);
 	kvfree(vm->pages);
 	kfree(vm);
 }
Signature · 1 line
2.43.0
#2 lore raw

PATCH v14 2/5 mm/vmalloc: use physical page count for vrealloc() grow-in-place check

In reply to Shivam Kalra

Update the grow-in-place check in vrealloc() to compare the requested size against the actual physical page count (vm->nr_pages) rather than the virtual area size (alloced_size, derived from get_vm_area_size()).

Currently both values are equivalent, but the upcoming vrealloc() shrink functionality will free pages without reducing the virtual reservation size. After such a shrink, the old alloced_size-based comparison would incorrectly allow a grow-in-place operation to succeed and attempt to access freed pages. Switch to vm->nr_pages now so the check remains correct once shrink support is added.

---
 mm/vmalloc.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
mm/vmalloc.c +7 -1
index 5555601b9529..3e159b74cfab 100644
@@ -4343,6 +4343,12 @@ void *vrealloc_node_align_noprof(const void *p, size_t size, unsigned long align
 		if (unlikely(flags & __GFP_THISNODE) && nid != NUMA_NO_NODE &&
 			     nid != page_to_nid(vmalloc_to_page(p)))
 			goto need_realloc;
+	} else {
+		/*
+		 * If p is NULL, vrealloc behaves exactly like vmalloc.
+		 * Skip the shrink and in-place grow paths.
+		 */
+		goto need_realloc;
 	}
 
 	/*
@@ -4361,7 +4367,7 @@ void *vrealloc_node_align_noprof(const void *p, size_t size, unsigned long align
 	/*
 	 * We already have the bytes available in the allocation; use them.
 	 */
-	if (size <= alloced_size) {
+	if (size <= vm->nr_pages << PAGE_SHIFT) {
 		/*
 		 * No need to zero memory here, as unused memory will have
 		 * already been zeroed at initial allocation time or during
Signature · 1 line
2.43.0
#3 lore raw

PATCH v14 3/5 mm/vmalloc: use physical page count in vread_iter() for VM_ALLOC areas

In reply to Shivam Kalra

For VM_ALLOC areas in vread_iter(), derive the vm area size from vm->nr_pages rather than get_vm_area_size().

Only VM_ALLOC areas are subject to vrealloc() shrinking, which frees pages without reducing the virtual reservation size. Switch to using vm->nr_pages for VM_ALLOC areas so the reader remains correct once shrink support is added. Other mapping types (vmap, ioremap) do not initialize nr_pages and will continue using get_vm_area_size().

---
 mm/vmalloc.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
mm/vmalloc.c +12 -1
index 3e159b74cfab..2f606cfade9b 100644
@@ -4666,7 +4666,18 @@ long vread_iter(struct iov_iter *iter, const char *addr, size_t count)
 		smp_rmb();
 
 		vaddr = (char *) va->va_start;
-		size = vm ? get_vm_area_size(vm) : va_size(va);
+		if (vm)
+			/*
+			 * For VM_ALLOC areas, use nr_pages rather than
+			 * get_vm_area_size() because vrealloc() may shrink
+			 * the mapping without updating area->size. Other
+			 * mapping types (vmap, ioremap) don't set nr_pages.
+			 */
+			size = (vm->flags & VM_ALLOC) ?
+				       (vm->nr_pages << PAGE_SHIFT) :
+				       get_vm_area_size(vm);
+		else
+			size = va_size(va);
 
 		if (addr >= vaddr + size)
 			goto next_va;
Signature · 1 line
2.43.0
#4 lore raw

PATCH v14 4/5 mm/vmalloc: free unused pages on vrealloc() shrink

In reply to Shivam Kalra

When vrealloc() shrinks an allocation and the new size crosses a page boundary, unmap and free the tail pages that are no longer needed. This reclaims physical memory that was previously wasted for the lifetime of the allocation.

The heuristic is simple: always free when at least one full page becomes unused. Huge page allocations (page_order > 0) are skipped, as partial freeing would require splitting. Allocations with VM_FLUSH_RESET_PERMS are also skipped, as their direct-map permissions must be reset before pages are returned to the page allocator, which is handled by vm_reset_perms() during vfree().

Additionally, allocations with VM_USERMAP are skipped because remap_vmalloc_range_partial() validates mapping requests against the unchanged vm->size; freeing tail pages would cause vmalloc_to_page() to return NULL for the unmapped range.

To protect concurrent readers, the shrink path uses Node lock to synchronize before freeing the pages.

Finally, we notify kmemleak of the reduced allocation size using kmemleak_free_part() to prevent the kmemleak scanner from faulting on the newly unmapped virtual addresses.

The virtual address reservation (vm->size / vmap_area) is intentionally kept unchanged, preserving the address for potential future grow-in-place support.

---
 mm/vmalloc.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 52 insertions(+), 4 deletions(-)
mm/vmalloc.c +52 -4
index 2f606cfade9b..12b750bb6d70 100644
@@ -4351,14 +4351,62 @@ void *vrealloc_node_align_noprof(const void *p, size_t size, unsigned long align
 		goto need_realloc;
 	}
 
-	/*
-	 * TODO: Shrink the vm_area, i.e. unmap and free unused pages. What
-	 * would be a good heuristic for when to shrink the vm_area?
-	 */
 	if (size <= old_size) {
+		unsigned int new_nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
+
 		/* Zero out "freed" memory, potentially for future realloc. */
 		if (want_init_on_free() || want_init_on_alloc(flags))
 			memset((void *)p + size, 0, old_size - size);
+
+		/*
+		 * Free tail pages when shrink crosses a page boundary.
+		 *
+		 * Skip huge page allocations (page_order > 0) as partial
+		 * freeing would require splitting.
+		 *
+		 * Skip VM_FLUSH_RESET_PERMS, as direct-map permissions must
+		 * be reset before pages are returned to the allocator.
+		 *
+		 * Skip VM_USERMAP, as remap_vmalloc_range_partial() validates
+		 * mapping requests against the unchanged vm->size; freeing
+		 * tail pages would cause vmalloc_to_page() to return NULL for
+		 * the unmapped range.
+		 *
+		 * Skip if either GFP_NOFS or GFP_NOIO are used.
+		 * kmemleak_free_part() internally allocates with
+		 * 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)) &&
+		    gfp_has_io_fs(flags)) {
+			unsigned long addr = (unsigned long)kasan_reset_tag(p);
+			unsigned int old_nr_pages = vm->nr_pages;
+
+			/*
+			 * Use the node lock to synchronize with concurrent
+			 * readers (vmalloc_info_show).
+			 */
+			struct vmap_node *vn = addr_to_node(addr);
+
+			spin_lock(&vn->busy.lock);
+			vm->nr_pages = new_nr_pages;
+			spin_unlock(&vn->busy.lock);
+
+			/* Notify kmemleak of the reduced allocation size before unmapping. */
+			kmemleak_free_part(
+				(void *)addr + ((unsigned long)new_nr_pages
+						<< PAGE_SHIFT),
+				(unsigned long)(old_nr_pages - new_nr_pages)
+					<< PAGE_SHIFT);
+
+			vunmap_range(addr + ((unsigned long)new_nr_pages
+					     << PAGE_SHIFT),
+				     addr + ((unsigned long)old_nr_pages
+					     << PAGE_SHIFT));
+
+			vm_area_free_pages(vm, new_nr_pages, old_nr_pages);
+		}
 		vm->requested_size = size;
 		kasan_vrealloc(p, old_size, size);
 		return (void *)p;
Signature · 1 line
2.43.0
#5 lore raw

PATCH v14 5/5 lib/test_vmalloc: add vrealloc test case

In reply to Shivam Kalra

Introduce a new test case "vrealloc_test" that exercises the vrealloc() shrink and in-place grow paths:

- Grow beyond allocated pages (triggers full reallocation).
- Shrink crossing a page boundary (frees tail pages).
- Shrink within the same page (no page freeing).
- Grow within the already allocated page count (in-place).

Data integrity is validated after each realloc step by checking that the first byte of the original allocation is preserved.

The test is gated behind run_test_mask bit 12 (id 4096).

---
 lib/test_vmalloc.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
lib/test_vmalloc.c +62 -0
index 876c72c18a0c..b23f85e8f8ca 100644
@@ -55,6 +55,7 @@ __param(int, run_test_mask, 7,
 		"\t\tid: 512,  name: kvfree_rcu_2_arg_vmalloc_test\n"
 		"\t\tid: 1024, name: vm_map_ram_test\n"
 		"\t\tid: 2048, name: no_block_alloc_test\n"
+		"\t\tid: 4096, name: vrealloc_test\n"
 		/* Add a new test case description here. */
 );
 
@@ -421,6 +422,66 @@ vm_map_ram_test(void)
 	return nr_allocated != map_nr_pages;
 }
 
+static int vrealloc_test(void)
+{
+	void *ptr, *tmp;
+	int i;
+
+	for (i = 0; i < test_loop_count; i++) {
+		int err = -1;
+
+		ptr = vrealloc(NULL, PAGE_SIZE, GFP_KERNEL);
+		if (!ptr)
+			return -1;
+
+		*((__u8 *)ptr) = 'a';
+
+		/* Grow: beyond allocated pages, triggers full realloc. */
+		tmp = vrealloc(ptr, 4 * PAGE_SIZE, GFP_KERNEL);
+		if (!tmp)
+			goto error;
+		ptr = tmp;
+
+		if (*((__u8 *)ptr) != 'a')
+			goto error;
+
+		/* Shrink: crosses page boundary, frees tail pages. */
+		tmp = vrealloc(ptr, PAGE_SIZE, GFP_KERNEL);
+		if (!tmp)
+			goto error;
+		ptr = tmp;
+
+		if (*((__u8 *)ptr) != 'a')
+			goto error;
+
+		/* Shrink: within same page, no page freeing. */
+		tmp = vrealloc(ptr, PAGE_SIZE / 2, GFP_KERNEL);
+		if (!tmp)
+			goto error;
+		ptr = tmp;
+
+		if (*((__u8 *)ptr) != 'a')
+			goto error;
+
+		/* Grow: within allocated page, in-place, no realloc. */
+		tmp = vrealloc(ptr, PAGE_SIZE, GFP_KERNEL);
+		if (!tmp)
+			goto error;
+		ptr = tmp;
+
+		if (*((__u8 *)ptr) != 'a')
+			goto error;
+
+		err = 0;
+error:
+		vfree(ptr);
+		if (err)
+			return err;
+	}
+
+	return 0;
+}
+
 struct test_case_desc {
 	const char *test_name;
 	int (*test_func)(void);
@@ -440,6 +501,7 @@ static struct test_case_desc test_case_array[] = {
 	{ "kvfree_rcu_2_arg_vmalloc_test", kvfree_rcu_2_arg_vmalloc_test, },
 	{ "vm_map_ram_test", vm_map_ram_test, },
 	{ "no_block_alloc_test", no_block_alloc_test, true },
+	{ "vrealloc_test", vrealloc_test, },
 	/* Add a new test case here. */
 };
 
Signature · 1 line
2.43.0
maintainer
#6 lore raw
In reply to Shivam Kalra
Quoted 2 lines · On Tue, 19 May 2026 17:42:13 +0530 Shivam Kalra via B4 Relay…

This series implements the TODO in vrealloc() to unmap and free unused pages when shrinking across a page boundary.

Thanks, I'll add this to mm.git's mm-new branch for testing. A few days hence I'll hopefully move it into the mm-unstable branch for linux-next exposure.

Sashiko is still saying things. Please double-check that it's all been dealt with and there's nothing new in there?

	https://sashiko.dev/#/patchset/[email protected]
#7 lore raw
Quoted 5 lines · Andrew Morton
Quoted 2 lines · On Tue, 19 May 2026 17:42:13 +0530 Shivam Kalra via B4 Relay…

This series implements the TODO in vrealloc() to unmap and free unused pages when shrinking across a page boundary.

Quoted 8 lines

Thanks, I'll add this to mm.git's mm-new branch for testing. A few days hence I'll hopefully move it into the mm-unstable branch for linux-next exposure.

Sashiko is still saying things. Please double-check that it's all been dealt with and there's nothing new in there?

	https://sashiko.dev/#/patchset/[email protected]

I've reviewed all five Sashiko findings:

- Issues 1+2 (32-bit shift overflow in nr_pages << PAGE_SHIFT):
nr_pages is unsigned int; a pre-existing type choice in struct vm_struct. Uladzislau reviewed this and explicitly asked to drop the (size_t) cast in v11.

- Issue 3 (VM_ALLOC areas with nr_pages==0): Valid point. pcpu_get_vm_areas() creates VM_ALLOC areas but manages pages through its own path and never sets nr_pages. With patch 3, vread_iter would skip these areas instead of reading them; a minor /proc/kcore observability regression. I'll send a follow-up fix to fall back to get_vm_area_size() when nr_pages is 0.

- Issue 4 (kmemleak scanner race): __delete_object() clears OBJECT_ALLOCATED under object->lock, and
scan_object() re-checks that flag under the same lock after cond_resched(). Additionally, kmemleak_free_part()
is called before vunmap_range(), so pages are still mapped during any scan window.

- Issue 5 (__GFP_ZERO on grow-after-shrink): Not a regression per Sashiko's own assessment. The API doc already requires callers to consistently pass __GFP_ZERO for every call.

#8 lore raw
Quoted 35 lines · Shivam Kalra
Quoted 5 lines · Andrew Morton
Quoted 2 lines · On Tue, 19 May 2026 17:42:13 +0530 Shivam Kalra via B4 Relay…

This series implements the TODO in vrealloc() to unmap and free unused pages when shrinking across a page boundary.

Quoted 8 lines

Thanks, I'll add this to mm.git's mm-new branch for testing. A few days hence I'll hopefully move it into the mm-unstable branch for linux-next exposure.

Sashiko is still saying things. Please double-check that it's all been dealt with and there's nothing new in there?

	https://sashiko.dev/#/patchset/[email protected]

I've reviewed all five Sashiko findings:

- Issues 1+2 (32-bit shift overflow in nr_pages << PAGE_SHIFT):
nr_pages is unsigned int; a pre-existing type choice in struct vm_struct. Uladzislau reviewed this and explicitly asked to drop the (size_t) cast in v11.

- Issue 3 (VM_ALLOC areas with nr_pages==0): Valid point. pcpu_get_vm_areas() creates VM_ALLOC areas but manages pages through its own path and never sets nr_pages. With patch 3, vread_iter would skip these areas instead of reading them; a minor /proc/kcore observability regression. I'll send a follow-up fix to fall back to get_vm_area_size() when nr_pages is 0.

- Issue 4 (kmemleak scanner race): __delete_object() clears OBJECT_ALLOCATED under object->lock, and
scan_object() re-checks that flag under the same lock after cond_resched(). Additionally, kmemleak_free_part()
is called before vunmap_range(), so pages are still mapped during any scan window.

Quoted 4 lines

- Issue 5 (__GFP_ZERO on grow-after-shrink): Not a regression per Sashiko's own assessment. The API doc already requires callers to consistently pass __GFP_ZERO for every call.

Andrew, could you please fold this into
"mm/vmalloc: use physical page count in vread_iter() for VM_ALLOC areas"?

pcpu_get_vm_areas() creates VM_ALLOC areas without setting nr_pages. Add an nr_pages check to fall back to get_vm_area_size() for these areas.

- size = (vm->flags & VM_ALLOC) ?
+ size = (vm->flags & VM_ALLOC && vm->nr_pages) ?