Re: [PATCH v10 0/4] mm/vmalloc: free unused pages on vrealloc() shrink
From: Uladzislau Rezki
Date: Mon Apr 20 2026 - 06:35:39 EST
On Fri, Apr 17, 2026 at 11:04:21PM +0530, Shivam Kalra wrote:
> On 17/04/26 22:54, Uladzislau Rezki wrote:
> > I have some questions to clarify.
> >
> > Why should we use min()?
> > Checking vm->nr_pages, can it be 0?
> >
> > Can we just do:
> >
> > if (vm)
> > /* Can not use get_vm_area_size() because of realloc(). */
> > size = vm->nr_pages << PAGE_SHIFT;
> > else
> > size = va_size(va);
> >
> > or i am missing something?
> >
> > Thanks!
> >
> > --
> > Uladzislau Rezki
> I honestly don't know much about the usage
> of this function, so wanted to be cautious.
>
> 1. We can skip the usage of min though.
> 2. Do need (size_t) for overflow issue
>
> I can include this simple version with size_t,
> let me know your thoughts.
>
<snip>
if (vm)
/*
* Use the actual number of mapped pages, since realloc()
* may shrink the mapping and area->size may be outdated.
*/
size = vm->nr_pages << PAGE_SHIFT;
else
size = va_size(va);
<snip>
As for the cast to size_t, i think it is unnecessary. An overflow
can occur in either case. So let's keep it simple :)
--
Uladzislau Rezki