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

From: Shivam Kalra

Date: Wed Apr 01 2026 - 22:56:44 EST


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.