[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250704171015.GJ904431@ziepe.ca>
Date: Fri, 4 Jul 2025 14:10:15 -0300
From: Jason Gunthorpe <jgg@...pe.ca>
To: lizhe.67@...edance.com
Cc: alex.williamson@...hat.com, akpm@...ux-foundation.org, david@...hat.com,
peterx@...hat.com, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-mm@...ck.org
Subject: Re: [PATCH v2 1/5] mm: introduce num_pages_contiguous()
On Fri, Jul 04, 2025 at 02:25:58PM +0800, lizhe.67@...edance.com wrote:
> From: Li Zhe <lizhe.67@...edance.com>
>
> Function num_pages_contiguous() determine the number of contiguous
> pages starting from the first page in the given array of page pointers.
> VFIO will utilize this interface to accelerate the VFIO DMA map process.
>
> Suggested-by: David Hildenbrand <david@...hat.com>
> Signed-off-by: Li Zhe <lizhe.67@...edance.com>
> ---
> include/linux/mm.h | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 0ef2ba0c667a..1d26203d1ced 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -205,6 +205,26 @@ extern unsigned long sysctl_admin_reserve_kbytes;
> #define folio_page_idx(folio, p) ((p) - &(folio)->page)
> #endif
>
> +/*
> + * num_pages_contiguous() - determine the number of contiguous pages
> + * starting from the first page.
> + *
> + * @pages: an array of page pointers
> + * @nr_pages: length of the array
> + */
> +static inline unsigned long num_pages_contiguous(struct page **pages,
> + unsigned long nr_pages)
Both longs should be size_t I think
> +{
> + struct page *first_page = pages[0];
> + unsigned long i;
Size_t
> +
> + for (i = 1; i < nr_pages; i++)
> + if (pages[i] != nth_page(first_page, i))
> + break;
It seems OK. So the reasoning here is this is faster on
CONFIG_SPARSEMEM_VMEMMAP/nonsparse and about the same on sparse mem?
(or we don't care?)
Jason
Powered by blists - more mailing lists