Re: [PATCH v9 3/4] mm/vmalloc: free unused pages on vrealloc() shrink

Alice Ryhl
2026-04-07T08:06:43Z

On Thu, Apr 02, 2026 at 08:23:42AM +0530, Shivam Kalra wrote:
> On 02/04/26 07:31, Shivam Kalra wrote:
> > On 02/04/26 02:49, Alice Ryhl wrote:
> > Should we set nr_pages first? Right now, another thread may observe the
> > range being unmapped but still see the old nr_pages value.
>
> Or is this what you mean?
> <snip>
> struct vmap_node *vn = addr_to_node(addr);
> /* Notify kmemleak of the reduced allocation size before unmapping. */
> kmemleak_free_part(...);
>
> spin_lock(&vn->busy.lock);
> vm->nr_pages = new_nr_pages;
> spin_unlock(&vn->busy.lock);
>
> vunmap_range(...);
> vm_area_free_pages(vm, new_nr_pages, old_nr_pages);
>
> <snip>
> If this is the case, then I agree this will be much cleaner.

Yes, I mean that you should change nr_pages first, before you calling
vunmap_range().

Alice