Re: [PATCH 1/9] mm/rmap: make nr_pages signed in try_to_unmap_one
From: Lorenzo Stoakes (Oracle)
Date: Tue Mar 10 2026 - 04:01:02 EST
On Tue, Mar 10, 2026 at 01:00:05PM +0530, Dev Jain wrote:
> Currently, nr_pages is defined as unsigned long. We use nr_pages to
> manipulate mm rss counters for lazyfree folios as follows:
>
> add_mm_counter(mm, MM_ANONPAGES, -nr_pages);
>
> Suppose nr_pages = 3. -nr_pages underflows and becomes ULONG_MAX - 2. Then,
> since add_mm_counter() uses this -nr_pages as a long, ULONG_MAX - 2 does
> not fit into the positive range of long, and is converted to -3. Eventually
> all of this works out, but for keeping things simple, declare nr_pages as
> a signed variable.
>
> Signed-off-by: Dev Jain <dev.jain@xxxxxxx>
> ---
> mm/rmap.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/mm/rmap.c b/mm/rmap.c
> index 6398d7eef393f..087c9f5b884fe 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -1979,9 +1979,10 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
> struct page *subpage;
> struct mmu_notifier_range range;
> enum ttu_flags flags = (enum ttu_flags)(long)arg;
> - unsigned long nr_pages = 1, end_addr;
> + unsigned long end_addr;
> unsigned long pfn;
> unsigned long hsz = 0;
> + long nr_pages = 1;
This is a non-issue that makes the code confusing, so let's not?
The convention throughout the kernel is nr_pages generally is unsigned because
you can't have negative nr_pages.
> int ptes = 0;
>
> /*
> --
> 2.34.1
>