diff mbox series

[2/5] mm: page_owner: add support for splitting to any order in split page_owner.

Message ID 20230321004829.2012847-3-zi.yan@sent.com (mailing list archive)
State New
Headers show
Series Split a folio to any lower order folios | expand

Commit Message

Zi Yan March 21, 2023, 12:48 a.m. UTC
From: Zi Yan <ziy@nvidia.com>

It adds a new_order parameter to set new page order in page owner and
uses old_order instead of nr to make the parameters look consistent.
It prepares for upcoming changes to support split huge page to any
lower order.

Signed-off-by: Zi Yan <ziy@nvidia.com>
---
 include/linux/page_owner.h | 12 +++++++-----
 mm/huge_memory.c           |  3 ++-
 mm/page_alloc.c            |  6 +++---
 mm/page_owner.c            | 11 ++++++-----
 4 files changed, 18 insertions(+), 14 deletions(-)

Comments

Michal Koutný March 24, 2023, 3:17 p.m. UTC | #1
Hello.

On Mon, Mar 20, 2023 at 08:48:26PM -0400, Zi Yan <zi.yan@sent.com> wrote:
> @@ -5746,8 +5746,8 @@ static void *make_alloc_exact(unsigned long addr, unsigned int order,
>  		struct page *page = virt_to_page((void *)addr);
>  		struct page *last = page + nr;
>  
> -		split_page_owner(page, 1 << order);
> -		split_page_memcg(page, 1 << order);
> +		split_page_owner(page, 1 << order, 1);
> +		split_page_memcg(page, 1 << order, 1);

I think here should be

> +		split_page_owner(page, order, 0);
> +		split_page_memcg(page, 1 << order, 1);

because I was wondering why split_page_memcg() doesn't use orders too?
(E.g. it wouldn't work well if nr % new_new != 0).

Thanks,
Michal
Zi Yan March 24, 2023, 3:22 p.m. UTC | #2
On 24 Mar 2023, at 11:17, Michal Koutný wrote:

> Hello.
>
> On Mon, Mar 20, 2023 at 08:48:26PM -0400, Zi Yan <zi.yan@sent.com> wrote:
>> @@ -5746,8 +5746,8 @@ static void *make_alloc_exact(unsigned long addr, unsigned int order,
>>  		struct page *page = virt_to_page((void *)addr);
>>  		struct page *last = page + nr;
>>
>> -		split_page_owner(page, 1 << order);
>> -		split_page_memcg(page, 1 << order);
>> +		split_page_owner(page, 1 << order, 1);
>> +		split_page_memcg(page, 1 << order, 1);
>
> I think here should be
>
>> +		split_page_owner(page, order, 0);
>> +		split_page_memcg(page, 1 << order, 1);
>
> because I was wondering why split_page_memcg() doesn't use orders too?
> (E.g. it wouldn't work well if nr % new_new != 0).

Thanks. Good point. I will make both use orders instead in next version.


--
Best Regards,
Yan, Zi
diff mbox series

Patch

diff --git a/include/linux/page_owner.h b/include/linux/page_owner.h
index 119a0c9d2a8b..67d98de3d5a8 100644
--- a/include/linux/page_owner.h
+++ b/include/linux/page_owner.h
@@ -11,7 +11,8 @@  extern struct page_ext_operations page_owner_ops;
 extern void __reset_page_owner(struct page *page, unsigned short order);
 extern void __set_page_owner(struct page *page,
 			unsigned short order, gfp_t gfp_mask);
-extern void __split_page_owner(struct page *page, unsigned int nr);
+extern void __split_page_owner(struct page *page, unsigned short old_order,
+			unsigned short new_order);
 extern void __folio_copy_owner(struct folio *newfolio, struct folio *old);
 extern void __set_page_owner_migrate_reason(struct page *page, int reason);
 extern void __dump_page_owner(const struct page *page);
@@ -31,10 +32,11 @@  static inline void set_page_owner(struct page *page,
 		__set_page_owner(page, order, gfp_mask);
 }
 
-static inline void split_page_owner(struct page *page, unsigned int nr)
+static inline void split_page_owner(struct page *page, unsigned short old_order,
+			unsigned short new_order)
 {
 	if (static_branch_unlikely(&page_owner_inited))
-		__split_page_owner(page, nr);
+		__split_page_owner(page, old_order, new_order);
 }
 static inline void folio_copy_owner(struct folio *newfolio, struct folio *old)
 {
@@ -56,11 +58,11 @@  static inline void reset_page_owner(struct page *page, unsigned short order)
 {
 }
 static inline void set_page_owner(struct page *page,
-			unsigned int order, gfp_t gfp_mask)
+			unsigned short order, gfp_t gfp_mask)
 {
 }
 static inline void split_page_owner(struct page *page,
-			unsigned short order)
+			unsigned short old_order, unsigned short new_order)
 {
 }
 static inline void folio_copy_owner(struct folio *newfolio, struct folio *folio)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 30e3e300c42e..710189885402 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2511,6 +2511,7 @@  static void __split_huge_page(struct page *page, struct list_head *list,
 	struct lruvec *lruvec;
 	struct address_space *swap_cache = NULL;
 	unsigned long offset = 0;
+	unsigned int order = thp_order(head);
 	unsigned int nr = thp_nr_pages(head);
 	int i;
 
@@ -2556,7 +2557,7 @@  static void __split_huge_page(struct page *page, struct list_head *list,
 	unlock_page_lruvec(lruvec);
 	/* Caller disabled irqs, so they are still disabled here */
 
-	split_page_owner(head, nr);
+	split_page_owner(head, order, 0);
 
 	/* See comment in __split_huge_page_tail() */
 	if (PageAnon(head)) {
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 59c2b6696698..ec85562865fb 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3530,7 +3530,7 @@  void split_page(struct page *page, unsigned int order)
 
 	for (i = 1; i < (1 << order); i++)
 		set_page_refcounted(page + i);
-	split_page_owner(page, 1 << order);
+	split_page_owner(page, order, 0);
 	split_page_memcg(page, 1 << order, 1);
 }
 EXPORT_SYMBOL_GPL(split_page);
@@ -5746,8 +5746,8 @@  static void *make_alloc_exact(unsigned long addr, unsigned int order,
 		struct page *page = virt_to_page((void *)addr);
 		struct page *last = page + nr;
 
-		split_page_owner(page, 1 << order);
-		split_page_memcg(page, 1 << order);
+		split_page_owner(page, 1 << order, 1);
+		split_page_memcg(page, 1 << order, 1);
 		while (page < --last)
 			set_page_refcounted(last);
 
diff --git a/mm/page_owner.c b/mm/page_owner.c
index 31169b3e7f06..33d1b6efe6a6 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -211,19 +211,20 @@  void __set_page_owner_migrate_reason(struct page *page, int reason)
 	page_ext_put(page_ext);
 }
 
-void __split_page_owner(struct page *page, unsigned int nr)
+void __split_page_owner(struct page *page, unsigned short old_order,
+			unsigned short new_order)
 {
-	int i;
+	int i, old_nr = 1 << old_order, new_nr = 1 << new_order;
 	struct page_ext *page_ext = page_ext_get(page);
 	struct page_owner *page_owner;
 
 	if (unlikely(!page_ext))
 		return;
 
-	for (i = 0; i < nr; i++) {
+	for (i = 0; i < old_nr; i += new_nr) {
+		page_ext = lookup_page_ext(page + i);
 		page_owner = get_page_owner(page_ext);
-		page_owner->order = 0;
-		page_ext = page_ext_next(page_ext);
+		page_owner->order = new_order;
 	}
 	page_ext_put(page_ext);
 }