[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250710085355.54208-2-lizhe.67@bytedance.com>
Date: Thu, 10 Jul 2025 16:53:51 +0800
From: lizhe.67@...edance.com
To: alex.williamson@...hat.com,
akpm@...ux-foundation.org,
david@...hat.com,
jgg@...pe.ca,
peterx@...hat.com
Cc: kvm@...r.kernel.org,
linux-kernel@...r.kernel.org,
linux-mm@...ck.org,
lizhe.67@...edance.com
Subject: [PATCH v4 1/5] mm: introduce num_pages_contiguous()
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>
Suggested-by: Jason Gunthorpe <jgg@...pe.ca>
Signed-off-by: Li Zhe <lizhe.67@...edance.com>
Acked-by: David Hildenbrand <david@...hat.com>
---
include/linux/mm.h | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 0ef2ba0c667a..fae82df6d7d7 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1761,6 +1761,29 @@ static inline unsigned long page_to_section(const struct page *page)
}
#endif
+/*
+ * num_pages_contiguous() - determine the number of contiguous pages
+ * starting from the first page.
+ *
+ * Pages are contiguous if they represent contiguous PFNs. Depending on
+ * the memory model, this can mean that the addresses of the "struct page"s
+ * are not contiguous.
+ *
+ * @pages: an array of page pointers
+ * @nr_pages: length of the array
+ */
+static inline unsigned long num_pages_contiguous(struct page **pages,
+ size_t nr_pages)
+{
+ size_t i;
+
+ for (i = 1; i < nr_pages; i++)
+ if (pages[i] != nth_page(pages[0], i))
+ break;
+
+ return i;
+}
+
/**
* folio_pfn - Return the Page Frame Number of a folio.
* @folio: The folio.
--
2.20.1
Powered by blists - more mailing lists