folio_estimated_mapcount() takes in a folio and returns the precise number of times the first subpage of the folio is mapped. This function aims to provide an estimate for the mapcount of a subpage within a folio. This is necessary for folio conversions where we care about the mapcount of a subpage, but not necessarily the whole folio. This is in contrast to folio_mapcount() which calculates the total number of the times a folio and all its subpages are mapped. Signed-off-by: Vishal Moola (Oracle) <vishal.moola@xxxxxxxxx> --- include/linux/mm.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index c9db257f09b3..fdd5b77ac209 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1817,6 +1817,23 @@ static inline size_t folio_size(struct folio *folio) return PAGE_SIZE << folio_order(folio); } +/** + * folio_estimated_mapcount - Estimate a folio's per-page mapcount. + * @folio: The folio. + * + * folio_estimated_mapcount() aims to serve as a function to efficiently + * estimate the number of times each page in a folio is mapped. + * This may not be accurate for large folios. If you want exact mapcounts, + * look at page_mapcount() or folio_total_mapcount(). + * + * Return: The precise mapcount of the first subpage, meant to estimate + * the precise mapcount of any subpage. + */ +static inline int folio_estimated_mapcount(struct folio *folio) +{ + return page_mapcount(folio_page(folio, 0)); +} + #ifndef HAVE_ARCH_MAKE_PAGE_ACCESSIBLE static inline int arch_make_page_accessible(struct page *page) { -- 2.38.1