linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Small cleanups
@ 2025-09-10 14:29 Matthew Wilcox (Oracle)
  2025-09-10 14:29 ` [PATCH 1/3] mm: Constify compound_order() and page_size() Matthew Wilcox (Oracle)
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Matthew Wilcox (Oracle) @ 2025-09-10 14:29 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm

These small cleanups can be applied now to reduce conflicts during the
next merge window.  They're all from various efforts to split struct
page from other memdescs.  Thanks to Vlastimil for the suggestion.

Matthew Wilcox (Oracle) (3):
  mm: Constify compound_order() and page_size()
  mm: Remove redundant test in validate_page_before_insert()
  mm: Remove page->order

 include/linux/mm.h       | 6 +++---
 include/linux/mm_types.h | 8 +++-----
 mm/memory.c              | 3 +--
 mm/page_alloc.c          | 4 ++--
 4 files changed, 9 insertions(+), 12 deletions(-)

-- 
2.47.2



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] mm: Constify compound_order() and page_size()
  2025-09-10 14:29 [PATCH 0/3] Small cleanups Matthew Wilcox (Oracle)
@ 2025-09-10 14:29 ` Matthew Wilcox (Oracle)
  2025-09-10 14:42   ` Vlastimil Babka
  2025-09-10 14:29 ` [PATCH 2/3] mm: Remove redundant test in validate_page_before_insert() Matthew Wilcox (Oracle)
  2025-09-10 14:29 ` [PATCH 3/3] mm: Remove page->order Matthew Wilcox (Oracle)
  2 siblings, 1 reply; 8+ messages in thread
From: Matthew Wilcox (Oracle) @ 2025-09-10 14:29 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Matthew Wilcox (Oracle), linux-mm, Zi Yan, David Hildenbrand

These functions do not modify their arguments.  Telling the compiler
this may improve code generation, and allows us to pass const arguments
from other functions.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Acked-by: David Hildenbrand <david@redhat.com>
---
 include/linux/mm.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 892fe5dbf9de..5ba30a8c6c6d 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1036,9 +1036,9 @@ static inline long folio_large_nr_pages(const struct folio *folio)
  * set before the order is initialised, or this may be a tail page.
  * See compaction.c for some good examples.
  */
-static inline unsigned int compound_order(struct page *page)
+static inline unsigned int compound_order(const struct page *page)
 {
-	struct folio *folio = (struct folio *)page;
+	const struct folio *folio = (struct folio *)page;
 
 	if (!test_bit(PG_head, &folio->flags.f))
 		return 0;
@@ -1257,7 +1257,7 @@ int folio_mc_copy(struct folio *dst, struct folio *src);
 unsigned long nr_free_buffer_pages(void);
 
 /* Returns the number of bytes in this potentially compound page. */
-static inline unsigned long page_size(struct page *page)
+static inline unsigned long page_size(const struct page *page)
 {
 	return PAGE_SIZE << compound_order(page);
 }
-- 
2.47.2



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/3] mm: Remove redundant test in validate_page_before_insert()
  2025-09-10 14:29 [PATCH 0/3] Small cleanups Matthew Wilcox (Oracle)
  2025-09-10 14:29 ` [PATCH 1/3] mm: Constify compound_order() and page_size() Matthew Wilcox (Oracle)
@ 2025-09-10 14:29 ` Matthew Wilcox (Oracle)
  2025-09-10 14:42   ` Vlastimil Babka
  2025-09-10 14:29 ` [PATCH 3/3] mm: Remove page->order Matthew Wilcox (Oracle)
  2 siblings, 1 reply; 8+ messages in thread
From: Matthew Wilcox (Oracle) @ 2025-09-10 14:29 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm, David Hildenbrand

The page_has_type() call would have included slab since commit
46df8e73a4a3 and now we don't even get that far because slab
pages have a zero refcount since commit 9aec2fb0fd5e.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Acked-by: David Hildenbrand <david@redhat.com>
---
 mm/memory.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index 3e0404bd57a0..46fa459d9a11 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2268,8 +2268,7 @@ static int validate_page_before_insert(struct vm_area_struct *vma,
 			return -EINVAL;
 		return 0;
 	}
-	if (folio_test_anon(folio) || folio_test_slab(folio) ||
-	    page_has_type(page))
+	if (folio_test_anon(folio) || page_has_type(page))
 		return -EINVAL;
 	flush_dcache_folio(folio);
 	return 0;
-- 
2.47.2



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3/3] mm: Remove page->order
  2025-09-10 14:29 [PATCH 0/3] Small cleanups Matthew Wilcox (Oracle)
  2025-09-10 14:29 ` [PATCH 1/3] mm: Constify compound_order() and page_size() Matthew Wilcox (Oracle)
  2025-09-10 14:29 ` [PATCH 2/3] mm: Remove redundant test in validate_page_before_insert() Matthew Wilcox (Oracle)
@ 2025-09-10 14:29 ` Matthew Wilcox (Oracle)
  2025-09-10 14:50   ` Vlastimil Babka
  2025-09-10 20:03   ` Alexei Starovoitov
  2 siblings, 2 replies; 8+ messages in thread
From: Matthew Wilcox (Oracle) @ 2025-09-10 14:29 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm, Alexei Starovoitov

We already use page->private for storing the order of a page while it's
in the buddy allocator system; extend that to also storing the order
while it's in the pcp_llist.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Alexei Starovoitov <ast@kernel.org>
---
 include/linux/mm_types.h | 8 +++-----
 mm/page_alloc.c          | 4 ++--
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 4a441f78340d..569265d159a5 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -97,10 +97,7 @@ struct page {
 				/* Or, free page */
 				struct list_head buddy_list;
 				struct list_head pcp_list;
-				struct {
-					struct llist_node pcp_llist;
-					unsigned int order;
-				};
+				struct llist_node pcp_llist;
 			};
 			struct address_space *mapping;
 			union {
@@ -111,7 +108,8 @@ struct page {
 			 * @private: Mapping-private opaque data.
 			 * Usually used for buffer_heads if PagePrivate.
 			 * Used for swp_entry_t if swapcache flag set.
-			 * Indicates order in the buddy system if PageBuddy.
+			 * Indicates order in the buddy system if PageBuddy
+			 * or on pcp_llist.
 			 */
 			unsigned long private;
 		};
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index d21a411e807e..e71e23d1a747 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1520,7 +1520,7 @@ static void add_page_to_zone_llist(struct zone *zone, struct page *page,
 				   unsigned int order)
 {
 	/* Remember the order */
-	page->order = order;
+	page->private = order;
 	/* Add the page to the free list */
 	llist_add(&page->pcp_llist, &zone->trylock_free_pages);
 }
@@ -1549,7 +1549,7 @@ static void free_one_page(struct zone *zone, struct page *page,
 
 		llnode = llist_del_all(llhead);
 		llist_for_each_entry_safe(p, tmp, llnode, pcp_llist) {
-			unsigned int p_order = p->order;
+			unsigned int p_order = p->private;
 
 			split_large_buddy(zone, p, page_to_pfn(p), p_order, fpi_flags);
 			__count_vm_events(PGFREE, 1 << p_order);
-- 
2.47.2



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] mm: Constify compound_order() and page_size()
  2025-09-10 14:29 ` [PATCH 1/3] mm: Constify compound_order() and page_size() Matthew Wilcox (Oracle)
@ 2025-09-10 14:42   ` Vlastimil Babka
  0 siblings, 0 replies; 8+ messages in thread
From: Vlastimil Babka @ 2025-09-10 14:42 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle), Andrew Morton
  Cc: linux-mm, Zi Yan, David Hildenbrand

On 9/10/25 16:29, Matthew Wilcox (Oracle) wrote:
> These functions do not modify their arguments.  Telling the compiler
> this may improve code generation, and allows us to pass const arguments
> from other functions.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> Reviewed-by: Zi Yan <ziy@nvidia.com>
> Acked-by: David Hildenbrand <david@redhat.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>  include/linux/mm.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 892fe5dbf9de..5ba30a8c6c6d 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -1036,9 +1036,9 @@ static inline long folio_large_nr_pages(const struct folio *folio)
>   * set before the order is initialised, or this may be a tail page.
>   * See compaction.c for some good examples.
>   */
> -static inline unsigned int compound_order(struct page *page)
> +static inline unsigned int compound_order(const struct page *page)
>  {
> -	struct folio *folio = (struct folio *)page;
> +	const struct folio *folio = (struct folio *)page;
>  
>  	if (!test_bit(PG_head, &folio->flags.f))
>  		return 0;
> @@ -1257,7 +1257,7 @@ int folio_mc_copy(struct folio *dst, struct folio *src);
>  unsigned long nr_free_buffer_pages(void);
>  
>  /* Returns the number of bytes in this potentially compound page. */
> -static inline unsigned long page_size(struct page *page)
> +static inline unsigned long page_size(const struct page *page)
>  {
>  	return PAGE_SIZE << compound_order(page);
>  }



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] mm: Remove redundant test in validate_page_before_insert()
  2025-09-10 14:29 ` [PATCH 2/3] mm: Remove redundant test in validate_page_before_insert() Matthew Wilcox (Oracle)
@ 2025-09-10 14:42   ` Vlastimil Babka
  0 siblings, 0 replies; 8+ messages in thread
From: Vlastimil Babka @ 2025-09-10 14:42 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle), Andrew Morton; +Cc: linux-mm, David Hildenbrand

On 9/10/25 16:29, Matthew Wilcox (Oracle) wrote:
> The page_has_type() call would have included slab since commit
> 46df8e73a4a3 and now we don't even get that far because slab
> pages have a zero refcount since commit 9aec2fb0fd5e.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> Acked-by: David Hildenbrand <david@redhat.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>  mm/memory.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/mm/memory.c b/mm/memory.c
> index 3e0404bd57a0..46fa459d9a11 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -2268,8 +2268,7 @@ static int validate_page_before_insert(struct vm_area_struct *vma,
>  			return -EINVAL;
>  		return 0;
>  	}
> -	if (folio_test_anon(folio) || folio_test_slab(folio) ||
> -	    page_has_type(page))
> +	if (folio_test_anon(folio) || page_has_type(page))
>  		return -EINVAL;
>  	flush_dcache_folio(folio);
>  	return 0;



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] mm: Remove page->order
  2025-09-10 14:29 ` [PATCH 3/3] mm: Remove page->order Matthew Wilcox (Oracle)
@ 2025-09-10 14:50   ` Vlastimil Babka
  2025-09-10 20:03   ` Alexei Starovoitov
  1 sibling, 0 replies; 8+ messages in thread
From: Vlastimil Babka @ 2025-09-10 14:50 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle), Andrew Morton; +Cc: linux-mm, Alexei Starovoitov

On 9/10/25 16:29, Matthew Wilcox (Oracle) wrote:
> We already use page->private for storing the order of a page while it's
> in the buddy allocator system; extend that to also storing the order
> while it's in the pcp_llist.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> Cc: Alexei Starovoitov <ast@kernel.org>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

Nit below:

> ---
>  include/linux/mm_types.h | 8 +++-----
>  mm/page_alloc.c          | 4 ++--
>  2 files changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> index 4a441f78340d..569265d159a5 100644
> --- a/include/linux/mm_types.h
> +++ b/include/linux/mm_types.h
> @@ -97,10 +97,7 @@ struct page {
>  				/* Or, free page */
>  				struct list_head buddy_list;
>  				struct list_head pcp_list;
> -				struct {
> -					struct llist_node pcp_llist;
> -					unsigned int order;
> -				};
> +				struct llist_node pcp_llist;
>  			};
>  			struct address_space *mapping;
>  			union {
> @@ -111,7 +108,8 @@ struct page {
>  			 * @private: Mapping-private opaque data.
>  			 * Usually used for buffer_heads if PagePrivate.
>  			 * Used for swp_entry_t if swapcache flag set.
> -			 * Indicates order in the buddy system if PageBuddy.
> +			 * Indicates order in the buddy system if PageBuddy
> +			 * or on pcp_llist.

In fact pcp_list too, so "or on pcp_list or pcp_llist" ?

>  			 */
>  			unsigned long private;
>  		};
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index d21a411e807e..e71e23d1a747 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -1520,7 +1520,7 @@ static void add_page_to_zone_llist(struct zone *zone, struct page *page,
>  				   unsigned int order)
>  {
>  	/* Remember the order */
> -	page->order = order;
> +	page->private = order;
>  	/* Add the page to the free list */
>  	llist_add(&page->pcp_llist, &zone->trylock_free_pages);
>  }
> @@ -1549,7 +1549,7 @@ static void free_one_page(struct zone *zone, struct page *page,
>  
>  		llnode = llist_del_all(llhead);
>  		llist_for_each_entry_safe(p, tmp, llnode, pcp_llist) {
> -			unsigned int p_order = p->order;
> +			unsigned int p_order = p->private;
>  
>  			split_large_buddy(zone, p, page_to_pfn(p), p_order, fpi_flags);
>  			__count_vm_events(PGFREE, 1 << p_order);



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] mm: Remove page->order
  2025-09-10 14:29 ` [PATCH 3/3] mm: Remove page->order Matthew Wilcox (Oracle)
  2025-09-10 14:50   ` Vlastimil Babka
@ 2025-09-10 20:03   ` Alexei Starovoitov
  1 sibling, 0 replies; 8+ messages in thread
From: Alexei Starovoitov @ 2025-09-10 20:03 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle); +Cc: Andrew Morton, linux-mm, Alexei Starovoitov

On Wed, Sep 10, 2025 at 7:29 AM Matthew Wilcox (Oracle)
<willy@infradead.org> wrote:
>
> We already use page->private for storing the order of a page while it's
> in the buddy allocator system; extend that to also storing the order
> while it's in the pcp_llist.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> Cc: Alexei Starovoitov <ast@kernel.org>

Makes sense to me.
Acked-by: Alexei Starovoitov <ast@kernel.org>


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-09-10 20:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-10 14:29 [PATCH 0/3] Small cleanups Matthew Wilcox (Oracle)
2025-09-10 14:29 ` [PATCH 1/3] mm: Constify compound_order() and page_size() Matthew Wilcox (Oracle)
2025-09-10 14:42   ` Vlastimil Babka
2025-09-10 14:29 ` [PATCH 2/3] mm: Remove redundant test in validate_page_before_insert() Matthew Wilcox (Oracle)
2025-09-10 14:42   ` Vlastimil Babka
2025-09-10 14:29 ` [PATCH 3/3] mm: Remove page->order Matthew Wilcox (Oracle)
2025-09-10 14:50   ` Vlastimil Babka
2025-09-10 20:03   ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox