Commit fe3df441 authored by Muchun Song's avatar Muchun Song Committed by Linus Torvalds

mm: remove redundant compound_head() calling

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.

Link: https://lkml.kernel.org/r/20210811101431.83940-1-songmuchun@bytedance.comSigned-off-by: default avatarMuchun Song <songmuchun@bytedance.com>
Reviewed-by: default avatarDavid Howells <dhowells@redhat.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: William Kucharski <william.kucharski@oracle.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 5ef5f810
...@@ -521,18 +521,17 @@ static inline struct page *read_mapping_page(struct address_space *mapping, ...@@ -521,18 +521,17 @@ static inline struct page *read_mapping_page(struct address_space *mapping,
*/ */
static inline pgoff_t page_to_index(struct page *page) static inline pgoff_t page_to_index(struct page *page)
{ {
pgoff_t pgoff; struct page *head;
if (likely(!PageTransTail(page))) if (likely(!PageTransTail(page)))
return page->index; return page->index;
head = compound_head(page);
/* /*
* We don't initialize ->index for tail pages: calculate based on * We don't initialize ->index for tail pages: calculate based on
* head page * head page
*/ */
pgoff = compound_head(page)->index; return head->index + page - head;
pgoff += page - compound_head(page);
return pgoff;
} }
extern pgoff_t hugetlb_basepage_index(struct page *page); extern pgoff_t hugetlb_basepage_index(struct page *page);
......
...@@ -1230,11 +1230,13 @@ void page_add_file_rmap(struct page *page, bool compound) ...@@ -1230,11 +1230,13 @@ void page_add_file_rmap(struct page *page, bool compound)
nr_pages); nr_pages);
} else { } else {
if (PageTransCompound(page) && page_mapping(page)) { if (PageTransCompound(page) && page_mapping(page)) {
struct page *head = compound_head(page);
VM_WARN_ON_ONCE(!PageLocked(page)); VM_WARN_ON_ONCE(!PageLocked(page));
SetPageDoubleMap(compound_head(page)); SetPageDoubleMap(head);
if (PageMlocked(page)) if (PageMlocked(page))
clear_page_mlock(compound_head(page)); clear_page_mlock(head);
} }
if (!atomic_inc_and_test(&page->_mapcount)) if (!atomic_inc_and_test(&page->_mapcount))
goto out; goto out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment