Skip to content

Commit

Permalink
mm: remove redundant compound_head() calling
Browse files Browse the repository at this point in the history
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/[email protected]
Signed-off-by: Muchun Song <[email protected]>
Reviewed-by: David Howells <[email protected]>
Cc: Matthew Wilcox (Oracle) <[email protected]>
Cc: William Kucharski <[email protected]>
Cc: Kirill A. Shutemov <[email protected]>
Cc: Johannes Weiner <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Muchun Song authored and torvalds committed Sep 8, 2021
1 parent 5ef5f81 commit fe3df44
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 3 additions & 4 deletions include/linux/pagemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
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);
Expand Down
6 changes: 4 additions & 2 deletions mm/rmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fe3df44

Please sign in to comment.