]> Gentwo Git Trees - linux/.git/commit
mm: introduce num_pages_contiguous()
authorLi Zhe <lizhe.67@bytedance.com>
Thu, 14 Aug 2025 06:47:10 +0000 (14:47 +0800)
committerAlex Williamson <alex.williamson@redhat.com>
Mon, 6 Oct 2025 17:21:26 +0000 (11:21 -0600)
commit929bf010e0599ddef6b640cd314f1de65dd1ca3e
treedbc415dccb8eb568740567f3766e8903e7242f4a
parentfd94619c43360eb44d28bd3ef326a4f85c600a07
mm: introduce num_pages_contiguous()

Let's add a simple helper for determining the number of contiguous pages
that represent contiguous PFNs.

In an ideal world, this helper would be simpler or not even required.
Unfortunately, on some configs we still have to maintain (SPARSEMEM
without VMEMMAP), the memmap is allocated per memory section, and we might
run into weird corner cases of false positives when blindly testing for
contiguous pages only.

One example of such false positives would be a memory section-sized hole
that does not have a memmap. The surrounding memory sections might get
"struct pages" that are contiguous, but the PFNs are actually not.

This helper will, for example, be useful for determining contiguous PFNs
in a GUP result, to batch further operations across returned "struct
page"s. VFIO will utilize this interface to accelerate the VFIO DMA map
process.

Implementation based on Linus' suggestions to avoid new usage of
nth_page() where avoidable.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Suggested-by: Jason Gunthorpe <jgg@ziepe.ca>
Signed-off-by: Li Zhe <lizhe.67@bytedance.com>
Co-developed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
Link: https://lore.kernel.org/r/20250814064714.56485-2-lizhe.67@bytedance.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
include/linux/mm.h
include/linux/mm_inline.h