Re: [PATCH v11 1/5] mm/vmalloc: extract vm_area_free_pages() helper from vfree()

From: Andrew Morton

Date: Thu Apr 23 2026 - 13:37:35 EST


On Mon, 20 Apr 2026 22:27:09 +0530 Shivam Kalra via B4 Relay <devnull+shivamkalra98.zohomail.in@xxxxxxxxxx> wrote:

> From: Shivam Kalra <shivamkalra98@xxxxxxxxxxx>
>
> Extract the page-freeing loop 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).
>
> ...
>
> * vfree - Release memory allocated by vmalloc()
> * @addr: Memory base address
> @@ -3436,7 +3468,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);
> @@ -3459,19 +3490,7 @@ void vfree(const void *addr)
>
> if (unlikely(vm->flags & VM_FLUSH_RESET_PERMS))
> vm_reset_perms(vm);
> - for (i = 0; i < vm->nr_pages; i++) {
> - struct page *page = vm->pages[i];
> -
> - BUG_ON(!page);
> - /*
> - * High-order allocs for huge vmallocs are split, so
> - * can be freed as an array of order-0 allocations
> - */
> - if (!(vm->flags & VM_MAP_PUT_PAGES))
> - mod_lruvec_page_state(page, NR_VMALLOC, -1);
> - __free_page(page);
> - cond_resched();
> - }
> + vm_area_free_pages(vm, 0, vm->nr_pages);
> kvfree(vm->pages);
> kfree(vm);

Ryan's "vmalloc: optimize vfree with free_pages_bulk()" just altered
all of this.

Can you please redo this series against mm.git's mm-new branch? I'll
be pushing that out later today.

Thanks.