2020-03-11 17:25:31

by Vlastimil Babka

[permalink] [raw]
Subject: [PATCH] mm/hugetlb: remove unnecessary memory fetch in PageHeadHuge()

Commit f1e61557f023 ("mm: pack compound_dtor and compound_order into one word
in struct page") changed compound_dtor from a pointer to an array index in
order to pack it. To check if page has the hugeltbfs compound_dtor, we can
just compare the index directly without fetching the function pointer.
Said commit did that with PageHuge() and we can do the same with PageHeadHuge()
to make the code a bit smaller and faster.

Signed-off-by: Vlastimil Babka <[email protected]>
Cc: Mike Kravetz <[email protected]>
Cc: Kirill A. Shutemov <[email protected]>
---
mm/hugetlb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index dd8737a94bec..ba1ca452aa7f 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1313,7 +1313,7 @@ int PageHeadHuge(struct page *page_head)
if (!PageHead(page_head))
return 0;

- return get_compound_page_dtor(page_head) == free_huge_page;
+ return page_head[1].compound_dtor == HUGETLB_PAGE_DTOR;
}

pgoff_t __basepage_index(struct page *page)
--
2.25.1


2020-03-11 18:21:13

by Mike Kravetz

[permalink] [raw]
Subject: Re: [PATCH] mm/hugetlb: remove unnecessary memory fetch in PageHeadHuge()

On 3/11/20 10:24 AM, Vlastimil Babka wrote:
> Commit f1e61557f023 ("mm: pack compound_dtor and compound_order into one word
> in struct page") changed compound_dtor from a pointer to an array index in
> order to pack it. To check if page has the hugeltbfs compound_dtor, we can
> just compare the index directly without fetching the function pointer.
> Said commit did that with PageHuge() and we can do the same with PageHeadHuge()
> to make the code a bit smaller and faster.
>
> Signed-off-by: Vlastimil Babka <[email protected]>
> Cc: Mike Kravetz <[email protected]>
> Cc: Kirill A. Shutemov <[email protected]>

Thanks!

Reviewed-by: Mike Kravetz <[email protected]>
--
Mike Kravetz

2020-03-11 19:27:31

by David Rientjes

[permalink] [raw]
Subject: Re: [PATCH] mm/hugetlb: remove unnecessary memory fetch in PageHeadHuge()

On Wed, 11 Mar 2020, Vlastimil Babka wrote:

> Commit f1e61557f023 ("mm: pack compound_dtor and compound_order into one word
> in struct page") changed compound_dtor from a pointer to an array index in
> order to pack it. To check if page has the hugeltbfs compound_dtor, we can
> just compare the index directly without fetching the function pointer.
> Said commit did that with PageHuge() and we can do the same with PageHeadHuge()
> to make the code a bit smaller and faster.
>
> Signed-off-by: Vlastimil Babka <[email protected]>
> Cc: Mike Kravetz <[email protected]>
> Cc: Kirill A. Shutemov <[email protected]>

Fixes: f1e61557f023 ("mm: pack compound_dtor and compound_order into one
word in struct page")

Acked-by: David Rientjes <[email protected]>

[+nehaagarwal]

We've been running with this patch for a few years and it works as
intended.

> ---
> mm/hugetlb.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index dd8737a94bec..ba1ca452aa7f 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -1313,7 +1313,7 @@ int PageHeadHuge(struct page *page_head)
> if (!PageHead(page_head))
> return 0;
>
> - return get_compound_page_dtor(page_head) == free_huge_page;
> + return page_head[1].compound_dtor == HUGETLB_PAGE_DTOR;
> }
>
> pgoff_t __basepage_index(struct page *page)

2020-03-12 00:43:23

by Kirill A. Shutemov

[permalink] [raw]
Subject: Re: [PATCH] mm/hugetlb: remove unnecessary memory fetch in PageHeadHuge()

On Wed, Mar 11, 2020 at 06:24:40PM +0100, Vlastimil Babka wrote:
> Commit f1e61557f023 ("mm: pack compound_dtor and compound_order into one word
> in struct page") changed compound_dtor from a pointer to an array index in
> order to pack it. To check if page has the hugeltbfs compound_dtor, we can
> just compare the index directly without fetching the function pointer.
> Said commit did that with PageHuge() and we can do the same with PageHeadHuge()
> to make the code a bit smaller and faster.
>
> Signed-off-by: Vlastimil Babka <[email protected]>
> Cc: Mike Kravetz <[email protected]>
> Cc: Kirill A. Shutemov <[email protected]>

Acked-by: Kirill A. Shutemov <[email protected]>

We use literaly the same check in the function next to this one --
PageHuge().


--
Kirill A. Shutemov

2020-03-12 00:43:44

by Kirill A. Shutemov

[permalink] [raw]
Subject: Re: [PATCH] mm/hugetlb: remove unnecessary memory fetch in PageHeadHuge()

On Thu, Mar 12, 2020 at 03:41:19AM +0300, Kirill A. Shutemov wrote:
> On Wed, Mar 11, 2020 at 06:24:40PM +0100, Vlastimil Babka wrote:
> > Commit f1e61557f023 ("mm: pack compound_dtor and compound_order into one word
> > in struct page") changed compound_dtor from a pointer to an array index in
> > order to pack it. To check if page has the hugeltbfs compound_dtor, we can
> > just compare the index directly without fetching the function pointer.
> > Said commit did that with PageHuge() and we can do the same with PageHeadHuge()
> > to make the code a bit smaller and faster.
> >
> > Signed-off-by: Vlastimil Babka <[email protected]>
> > Cc: Mike Kravetz <[email protected]>
> > Cc: Kirill A. Shutemov <[email protected]>
>
> Acked-by: Kirill A. Shutemov <[email protected]>
>
> We use literaly the same check in the function next to this one --
> PageHuge().

Ugh.. I have to read the commit message, not only the code :P

--
Kirill A. Shutemov