diff mbox series

[mm-unstable,v4,1/6] mm: add folio_estimated_sharers()

Message ID 20230130201833.27042-2-vishal.moola@gmail.com (mailing list archive)
State New
Headers show
Series Convert various mempolicy.c functions to use folios | expand

Commit Message

Vishal Moola Jan. 30, 2023, 8:18 p.m. UTC
folio_estimated_sharers() 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 number of sharers of a
folio. This is necessary for folio conversions where we care
about the number of processes that share a folio, but don't necessarily
want to check every single page within that 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@gmail.com>
---
 include/linux/mm.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Yin, Fengwei Jan. 31, 2023, 1:30 a.m. UTC | #1
On 1/31/2023 4:18 AM, Vishal Moola (Oracle) wrote:
> folio_estimated_sharers() 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 number of sharers of a
> folio. This is necessary for folio conversions where we care
> about the number of processes that share a folio, but don't necessarily
> want to check every single page within that 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@gmail.com>
Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>


Regards
Yin, Fengwei

> ---
>  include/linux/mm.h | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 27b34f7730e7..c91bf9cdb3d0 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -1905,6 +1905,24 @@ static inline size_t folio_size(struct folio *folio)
>  	return PAGE_SIZE << folio_order(folio);
>  }
>  
> +/**
> + * folio_estimated_sharers - Estimate the number of sharers of a folio.
> + * @folio: The folio.
> + *
> + * folio_estimated_sharers() aims to serve as a function to efficiently
> + * estimate the number of processes sharing a folio. This is done by
> + * looking at the precise mapcount of the first subpage in the folio, and
> + * assuming the other subpages are the same. This may not be true for large
> + * folios. If you want exact mapcounts for exact calculations, look at
> + * page_mapcount() or folio_total_mapcount().
> + *
> + * Return: The estimated number of processes sharing a folio.
> + */
> +static inline int folio_estimated_sharers(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)
>  {
David Hildenbrand Jan. 31, 2023, 10:59 a.m. UTC | #2
On 30.01.23 21:18, Vishal Moola (Oracle) wrote:
> folio_estimated_sharers() 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 number of sharers of a
> folio. This is necessary for folio conversions where we care
> about the number of processes that share a folio, but don't necessarily
> want to check every single page within that 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@gmail.com>
> ---
>   include/linux/mm.h | 18 ++++++++++++++++++
>   1 file changed, 18 insertions(+)
> 
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 27b34f7730e7..c91bf9cdb3d0 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -1905,6 +1905,24 @@ static inline size_t folio_size(struct folio *folio)
>   	return PAGE_SIZE << folio_order(folio);
>   }
>   
> +/**
> + * folio_estimated_sharers - Estimate the number of sharers of a folio.
> + * @folio: The folio.
> + *
> + * folio_estimated_sharers() aims to serve as a function to efficiently
> + * estimate the number of processes sharing a folio. This is done by
> + * looking at the precise mapcount of the first subpage in the folio, and
> + * assuming the other subpages are the same. This may not be true for large
> + * folios. If you want exact mapcounts for exact calculations, look at
> + * page_mapcount() or folio_total_mapcount().
> + *
> + * Return: The estimated number of processes sharing a folio.
> + */
> +static inline int folio_estimated_sharers(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)
>   {


Acked-by: David Hildenbrand <david@redhat.com>
diff mbox series

Patch

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 27b34f7730e7..c91bf9cdb3d0 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1905,6 +1905,24 @@  static inline size_t folio_size(struct folio *folio)
 	return PAGE_SIZE << folio_order(folio);
 }
 
+/**
+ * folio_estimated_sharers - Estimate the number of sharers of a folio.
+ * @folio: The folio.
+ *
+ * folio_estimated_sharers() aims to serve as a function to efficiently
+ * estimate the number of processes sharing a folio. This is done by
+ * looking at the precise mapcount of the first subpage in the folio, and
+ * assuming the other subpages are the same. This may not be true for large
+ * folios. If you want exact mapcounts for exact calculations, look at
+ * page_mapcount() or folio_total_mapcount().
+ *
+ * Return: The estimated number of processes sharing a folio.
+ */
+static inline int folio_estimated_sharers(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)
 {