diff mbox series

[v1,02/11] mm/page_alloc: split prep_compound_page into head and tail subparts

Message ID 20210325230938.30752-3-joao.m.martins@oracle.com (mailing list archive)
State New, archived
Headers show
Series mm, sparse-vmemmap: Introduce compound pagemaps | expand

Commit Message

Joao Martins March 25, 2021, 11:09 p.m. UTC
Split the utility function prep_compound_page() into head and tail
counterparts, and use them accordingly.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
---
 mm/page_alloc.c | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

Comments

Dan Williams April 24, 2021, 12:16 a.m. UTC | #1
On Thu, Mar 25, 2021 at 4:10 PM Joao Martins <joao.m.martins@oracle.com> wrote:
>
> Split the utility function prep_compound_page() into head and tail
> counterparts, and use them accordingly.

To make this patch stand alone better lets add another sentence:

"This is in preparation for sharing the storage for / deduplicating
compound page metadata."

Other than that, looks good to me.

>
> Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
> ---
>  mm/page_alloc.c | 32 +++++++++++++++++++++-----------
>  1 file changed, 21 insertions(+), 11 deletions(-)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index c53fe4fa10bf..43dd98446b0b 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -692,24 +692,34 @@ void free_compound_page(struct page *page)
>         __free_pages_ok(page, compound_order(page), FPI_NONE);
>  }
>
> +static void prep_compound_head(struct page *page, unsigned int order)
> +{
> +       set_compound_page_dtor(page, COMPOUND_PAGE_DTOR);
> +       set_compound_order(page, order);
> +       atomic_set(compound_mapcount_ptr(page), -1);
> +       if (hpage_pincount_available(page))
> +               atomic_set(compound_pincount_ptr(page), 0);
> +}
> +
> +static void prep_compound_tail(struct page *head, int tail_idx)
> +{
> +       struct page *p = head + tail_idx;
> +
> +       set_page_count(p, 0);
> +       p->mapping = TAIL_MAPPING;
> +       set_compound_head(p, head);
> +}
> +
>  void prep_compound_page(struct page *page, unsigned int order)
>  {
>         int i;
>         int nr_pages = 1 << order;
>
>         __SetPageHead(page);
> -       for (i = 1; i < nr_pages; i++) {
> -               struct page *p = page + i;
> -               set_page_count(p, 0);
> -               p->mapping = TAIL_MAPPING;
> -               set_compound_head(p, page);
> -       }
> +       for (i = 1; i < nr_pages; i++)
> +               prep_compound_tail(page, i);
>
> -       set_compound_page_dtor(page, COMPOUND_PAGE_DTOR);
> -       set_compound_order(page, order);
> -       atomic_set(compound_mapcount_ptr(page), -1);
> -       if (hpage_pincount_available(page))
> -               atomic_set(compound_pincount_ptr(page), 0);
> +       prep_compound_head(page, order);
>  }
>
>  #ifdef CONFIG_DEBUG_PAGEALLOC
> --
> 2.17.1
>
Joao Martins April 24, 2021, 7:05 p.m. UTC | #2
On 4/24/21 1:16 AM, Dan Williams wrote:
> On Thu, Mar 25, 2021 at 4:10 PM Joao Martins <joao.m.martins@oracle.com> wrote:
>>
>> Split the utility function prep_compound_page() into head and tail
>> counterparts, and use them accordingly.
> 
> To make this patch stand alone better lets add another sentence:
> 
> "This is in preparation for sharing the storage for / deduplicating
> compound page metadata."
> 
Yeap, I've fixed it up.

> Other than that, looks good to me.
> 
/me nods

>>
>> Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
>> ---
>>  mm/page_alloc.c | 32 +++++++++++++++++++++-----------
>>  1 file changed, 21 insertions(+), 11 deletions(-)
>>
>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>> index c53fe4fa10bf..43dd98446b0b 100644
>> --- a/mm/page_alloc.c
>> +++ b/mm/page_alloc.c
>> @@ -692,24 +692,34 @@ void free_compound_page(struct page *page)
>>         __free_pages_ok(page, compound_order(page), FPI_NONE);
>>  }
>>
>> +static void prep_compound_head(struct page *page, unsigned int order)
>> +{
>> +       set_compound_page_dtor(page, COMPOUND_PAGE_DTOR);
>> +       set_compound_order(page, order);
>> +       atomic_set(compound_mapcount_ptr(page), -1);
>> +       if (hpage_pincount_available(page))
>> +               atomic_set(compound_pincount_ptr(page), 0);
>> +}
>> +
>> +static void prep_compound_tail(struct page *head, int tail_idx)
>> +{
>> +       struct page *p = head + tail_idx;
>> +
>> +       set_page_count(p, 0);
>> +       p->mapping = TAIL_MAPPING;
>> +       set_compound_head(p, head);
>> +}
>> +
>>  void prep_compound_page(struct page *page, unsigned int order)
>>  {
>>         int i;
>>         int nr_pages = 1 << order;
>>
>>         __SetPageHead(page);
>> -       for (i = 1; i < nr_pages; i++) {
>> -               struct page *p = page + i;
>> -               set_page_count(p, 0);
>> -               p->mapping = TAIL_MAPPING;
>> -               set_compound_head(p, page);
>> -       }
>> +       for (i = 1; i < nr_pages; i++)
>> +               prep_compound_tail(page, i);
>>
>> -       set_compound_page_dtor(page, COMPOUND_PAGE_DTOR);
>> -       set_compound_order(page, order);
>> -       atomic_set(compound_mapcount_ptr(page), -1);
>> -       if (hpage_pincount_available(page))
>> -               atomic_set(compound_pincount_ptr(page), 0);
>> +       prep_compound_head(page, order);
>>  }
>>
>>  #ifdef CONFIG_DEBUG_PAGEALLOC
>> --
>> 2.17.1
>>
>
diff mbox series

Patch

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index c53fe4fa10bf..43dd98446b0b 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -692,24 +692,34 @@  void free_compound_page(struct page *page)
 	__free_pages_ok(page, compound_order(page), FPI_NONE);
 }
 
+static void prep_compound_head(struct page *page, unsigned int order)
+{
+	set_compound_page_dtor(page, COMPOUND_PAGE_DTOR);
+	set_compound_order(page, order);
+	atomic_set(compound_mapcount_ptr(page), -1);
+	if (hpage_pincount_available(page))
+		atomic_set(compound_pincount_ptr(page), 0);
+}
+
+static void prep_compound_tail(struct page *head, int tail_idx)
+{
+	struct page *p = head + tail_idx;
+
+	set_page_count(p, 0);
+	p->mapping = TAIL_MAPPING;
+	set_compound_head(p, head);
+}
+
 void prep_compound_page(struct page *page, unsigned int order)
 {
 	int i;
 	int nr_pages = 1 << order;
 
 	__SetPageHead(page);
-	for (i = 1; i < nr_pages; i++) {
-		struct page *p = page + i;
-		set_page_count(p, 0);
-		p->mapping = TAIL_MAPPING;
-		set_compound_head(p, page);
-	}
+	for (i = 1; i < nr_pages; i++)
+		prep_compound_tail(page, i);
 
-	set_compound_page_dtor(page, COMPOUND_PAGE_DTOR);
-	set_compound_order(page, order);
-	atomic_set(compound_mapcount_ptr(page), -1);
-	if (hpage_pincount_available(page))
-		atomic_set(compound_pincount_ptr(page), 0);
+	prep_compound_head(page, order);
 }
 
 #ifdef CONFIG_DEBUG_PAGEALLOC