diff mbox series

[v1,01/17] mm: factor out large folio handling from folio_order() into folio_large_order()

Message ID 20240829165627.2256514-2-david@redhat.com (mailing list archive)
State New
Headers show
Series mm: MM owner tracking for large folios (!hugetlb) + CONFIG_NO_PAGE_MAPCOUNT | expand

Commit Message

David Hildenbrand Aug. 29, 2024, 4:56 p.m. UTC
Let's factor it out into a simple helper function. This helper will
also come in handy when working with code where we know that our
folio is large.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 include/linux/mm.h | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

Comments

Lance Yang Sept. 23, 2024, 4:44 a.m. UTC | #1
On Fri, Aug 30, 2024 at 12:57 AM David Hildenbrand <david@redhat.com> wrote:
>
> Let's factor it out into a simple helper function. This helper will
> also come in handy when working with code where we know that our
> folio is large.
>
> Signed-off-by: David Hildenbrand <david@redhat.com>

LGTM. Feel feel to add:

Reviewed-by: Lance Yang <ioworker0@gmail.com>

Thanks,
Lance

> ---
>  include/linux/mm.h | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index b31d4bdd65ad5..3c6270f87bdc3 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -1071,6 +1071,11 @@ int vma_is_stack_for_current(struct vm_area_struct *vma);
>  struct mmu_gather;
>  struct inode;
>
> +static inline unsigned int folio_large_order(const struct folio *folio)
> +{
> +       return folio->_flags_1 & 0xff;
> +}
> +
>  /*
>   * compound_order() can be called without holding a reference, which means
>   * that niceties like page_folio() don't work.  These callers should be
> @@ -1084,7 +1089,7 @@ static inline unsigned int compound_order(struct page *page)
>
>         if (!test_bit(PG_head, &folio->flags))
>                 return 0;
> -       return folio->_flags_1 & 0xff;
> +       return folio_large_order(folio);
>  }
>
>  /**
> @@ -1100,7 +1105,7 @@ static inline unsigned int folio_order(const struct folio *folio)
>  {
>         if (!folio_test_large(folio))
>                 return 0;
> -       return folio->_flags_1 & 0xff;
> +       return folio_large_order(folio);
>  }
>
>  #include <linux/huge_mm.h>
> @@ -2035,7 +2040,7 @@ static inline long folio_nr_pages(const struct folio *folio)
>  #ifdef CONFIG_64BIT
>         return folio->_folio_nr_pages;
>  #else
> -       return 1L << (folio->_flags_1 & 0xff);
> +       return 1L << folio_large_order(folio);
>  #endif
>  }
>
> @@ -2060,7 +2065,7 @@ static inline unsigned long compound_nr(struct page *page)
>  #ifdef CONFIG_64BIT
>         return folio->_folio_nr_pages;
>  #else
> -       return 1L << (folio->_flags_1 & 0xff);
> +       return 1L << folio_large_order(folio);
>  #endif
>  }
>
> --
> 2.46.0
>
>
Kirill A. Shutemov Oct. 23, 2024, 11:11 a.m. UTC | #2
On Thu, Aug 29, 2024 at 06:56:04PM +0200, David Hildenbrand wrote:
> Let's factor it out into a simple helper function. This helper will
> also come in handy when working with code where we know that our
> folio is large.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
diff mbox series

Patch

diff --git a/include/linux/mm.h b/include/linux/mm.h
index b31d4bdd65ad5..3c6270f87bdc3 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1071,6 +1071,11 @@  int vma_is_stack_for_current(struct vm_area_struct *vma);
 struct mmu_gather;
 struct inode;
 
+static inline unsigned int folio_large_order(const struct folio *folio)
+{
+	return folio->_flags_1 & 0xff;
+}
+
 /*
  * compound_order() can be called without holding a reference, which means
  * that niceties like page_folio() don't work.  These callers should be
@@ -1084,7 +1089,7 @@  static inline unsigned int compound_order(struct page *page)
 
 	if (!test_bit(PG_head, &folio->flags))
 		return 0;
-	return folio->_flags_1 & 0xff;
+	return folio_large_order(folio);
 }
 
 /**
@@ -1100,7 +1105,7 @@  static inline unsigned int folio_order(const struct folio *folio)
 {
 	if (!folio_test_large(folio))
 		return 0;
-	return folio->_flags_1 & 0xff;
+	return folio_large_order(folio);
 }
 
 #include <linux/huge_mm.h>
@@ -2035,7 +2040,7 @@  static inline long folio_nr_pages(const struct folio *folio)
 #ifdef CONFIG_64BIT
 	return folio->_folio_nr_pages;
 #else
-	return 1L << (folio->_flags_1 & 0xff);
+	return 1L << folio_large_order(folio);
 #endif
 }
 
@@ -2060,7 +2065,7 @@  static inline unsigned long compound_nr(struct page *page)
 #ifdef CONFIG_64BIT
 	return folio->_folio_nr_pages;
 #else
-	return 1L << (folio->_flags_1 & 0xff);
+	return 1L << folio_large_order(folio);
 #endif
 }