]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: remove redundant compound_head() calling
authorMuchun Song <songmuchun@bytedance.com>
Mon, 23 Aug 2021 23:59:43 +0000 (09:59 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 25 Aug 2021 23:34:26 +0000 (09:34 +1000)
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.com
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
Reviewed-by: David 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: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
include/linux/pagemap.h
mm/rmap.c

index 45f5ab7496cc6d6488ce6803a0ba20575005b8c9..5c74a45ff97a02168c302d85fb856569bf21a785 100644 (file)
@@ -571,18 +571,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);
index b9eb5c12f3fe10bc83ce0d26d3f804d7f252f517..b2cebf35ffe7a02196a864dca06a5ae7b2b1ff74 100644 (file)
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1230,11 +1230,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;