From: Vlastimil Babka <vbabka@suse.cz>
To: Muchun Song <songmuchun@bytedance.com>,
akpm@linux-foundation.org, willy@infradead.org,
william.kucharski@oracle.com, kirill.shutemov@linux.intel.com,
dhowells@redhat.com, hannes@cmpxchg.org
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH] mm: remove redundant compound_head() calling
Date: Fri, 13 Aug 2021 16:02:33 +0200 [thread overview]
Message-ID: <808194f6-e5d0-59e4-ffd5-2c77a907232c@suse.cz> (raw)
In-Reply-To: <20210811101431.83940-1-songmuchun@bytedance.com>
On 8/11/21 12:14 PM, Muchun Song wrote:
> There is a READ_ONCE() in the macro of compound_head(), which will
> prevent compiler from optimizing the code when there are more than
> once calling of it in a function. Remove the redundant calling of
> compound_head() from page_to_index() and page_add_file_rmap() for
> better code generation.
>
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
Seems to be compatible with folio/for-next and not made redundant by that (yet?
didn't check the branches planned for future versions), so OK. But long-term I'd
expect these optimizations to be obsoleted by the folio work.
> ---
> include/linux/pagemap.h | 7 +++----
> mm/rmap.c | 6 ++++--
> 2 files changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
> index 79ec90e97e94..03b9a957ef10 100644
> --- a/include/linux/pagemap.h
> +++ b/include/linux/pagemap.h
> @@ -608,18 +608,17 @@ static inline struct page *read_mapping_page(struct address_space *mapping,
> */
> static inline pgoff_t page_to_index(struct page *page)
> {
> - pgoff_t pgoff;
> + struct page *head;
>
> if (likely(!PageTransTail(page)))
> return page->index;
>
> + head = compound_head(page);
> /*
> * We don't initialize ->index for tail pages: calculate based on
> * head page
> */
> - pgoff = compound_head(page)->index;
> - pgoff += page - compound_head(page);
> - return pgoff;
> + return head->index + page - head;
> }
>
> extern pgoff_t hugetlb_basepage_index(struct page *page);
> diff --git a/mm/rmap.c b/mm/rmap.c
> index 232494888628..2e216835f07c 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -1231,11 +1231,13 @@ void page_add_file_rmap(struct page *page, bool compound)
> nr_pages);
> } else {
> if (PageTransCompound(page) && page_mapping(page)) {
> + struct page *head = compound_head(page);
> +
> VM_WARN_ON_ONCE(!PageLocked(page));
>
> - SetPageDoubleMap(compound_head(page));
> + SetPageDoubleMap(head);
> if (PageMlocked(page))
> - clear_page_mlock(compound_head(page));
> + clear_page_mlock(head);
> }
> if (!atomic_inc_and_test(&page->_mapcount))
> goto out;
>
next prev parent reply other threads:[~2021-08-13 14:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-11 10:14 [PATCH] mm: remove redundant compound_head() calling Muchun Song
2021-08-13 14:02 ` Vlastimil Babka [this message]
2021-08-13 14:24 ` Matthew Wilcox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=808194f6-e5d0-59e4-ffd5-2c77a907232c@suse.cz \
--to=vbabka@suse.cz \
--cc=akpm@linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=songmuchun@bytedance.com \
--cc=william.kucharski@oracle.com \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).