Commit 4b0f3261 authored by Denys Vlasenko's avatar Denys Vlasenko Committed by Linus Torvalds

include/linux/page-flags.h: force inlining of selected page flag modifications

Sometimes gcc mysteriously doesn't inline
very small functions we expect to be inlined. See

    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66122

With this .config:
http://busybox.net/~vda/kernel_config_OPTIMIZE_INLINING_and_Os,
the following functions get deinlined many times.
Examples of disassembly:

<SetPageUptodate> (43 copies, 141 calls):
       55                      push   %rbp
       48 89 e5                mov    %rsp,%rbp
       f0 80 0f 08             lock orb $0x8,(%rdi)
       5d                      pop    %rbp
       c3                      retq

<PagePrivate> (10 copies, 134 calls):
       48 8b 07                mov    (%rdi),%rax
       55                      push   %rbp
       48 89 e5                mov    %rsp,%rbp
       48 c1 e8 0b             shr    $0xb,%rax
       83 e0 01                and    $0x1,%eax
       5d                      pop    %rbp
       c3                      retq

This patch fixes this via s/inline/__always_inline/.

Code size decrease after the patch is ~7k:

    text     data      bss       dec     hex filename
92125002 20826048 36417536 149368586 8e72f0a vmlinux
92118087 20826112 36417536 149361735 8e71447 vmlinux7_pageops_after
Signed-off-by: default avatarDenys Vlasenko <dvlasenk@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Thomas Graf <tgraf@suug.ch>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ee91ef61
...@@ -144,12 +144,12 @@ static inline struct page *compound_head(struct page *page) ...@@ -144,12 +144,12 @@ static inline struct page *compound_head(struct page *page)
return page; return page;
} }
static inline int PageTail(struct page *page) static __always_inline int PageTail(struct page *page)
{ {
return READ_ONCE(page->compound_head) & 1; return READ_ONCE(page->compound_head) & 1;
} }
static inline int PageCompound(struct page *page) static __always_inline int PageCompound(struct page *page)
{ {
return test_bit(PG_head, &page->flags) || PageTail(page); return test_bit(PG_head, &page->flags) || PageTail(page);
} }
...@@ -184,31 +184,31 @@ static inline int PageCompound(struct page *page) ...@@ -184,31 +184,31 @@ static inline int PageCompound(struct page *page)
* Macros to create function definitions for page flags * Macros to create function definitions for page flags
*/ */
#define TESTPAGEFLAG(uname, lname, policy) \ #define TESTPAGEFLAG(uname, lname, policy) \
static inline int Page##uname(struct page *page) \ static __always_inline int Page##uname(struct page *page) \
{ return test_bit(PG_##lname, &policy(page, 0)->flags); } { return test_bit(PG_##lname, &policy(page, 0)->flags); }
#define SETPAGEFLAG(uname, lname, policy) \ #define SETPAGEFLAG(uname, lname, policy) \
static inline void SetPage##uname(struct page *page) \ static __always_inline void SetPage##uname(struct page *page) \
{ set_bit(PG_##lname, &policy(page, 1)->flags); } { set_bit(PG_##lname, &policy(page, 1)->flags); }
#define CLEARPAGEFLAG(uname, lname, policy) \ #define CLEARPAGEFLAG(uname, lname, policy) \
static inline void ClearPage##uname(struct page *page) \ static __always_inline void ClearPage##uname(struct page *page) \
{ clear_bit(PG_##lname, &policy(page, 1)->flags); } { clear_bit(PG_##lname, &policy(page, 1)->flags); }
#define __SETPAGEFLAG(uname, lname, policy) \ #define __SETPAGEFLAG(uname, lname, policy) \
static inline void __SetPage##uname(struct page *page) \ static __always_inline void __SetPage##uname(struct page *page) \
{ __set_bit(PG_##lname, &policy(page, 1)->flags); } { __set_bit(PG_##lname, &policy(page, 1)->flags); }
#define __CLEARPAGEFLAG(uname, lname, policy) \ #define __CLEARPAGEFLAG(uname, lname, policy) \
static inline void __ClearPage##uname(struct page *page) \ static __always_inline void __ClearPage##uname(struct page *page) \
{ __clear_bit(PG_##lname, &policy(page, 1)->flags); } { __clear_bit(PG_##lname, &policy(page, 1)->flags); }
#define TESTSETFLAG(uname, lname, policy) \ #define TESTSETFLAG(uname, lname, policy) \
static inline int TestSetPage##uname(struct page *page) \ static __always_inline int TestSetPage##uname(struct page *page) \
{ return test_and_set_bit(PG_##lname, &policy(page, 1)->flags); } { return test_and_set_bit(PG_##lname, &policy(page, 1)->flags); }
#define TESTCLEARFLAG(uname, lname, policy) \ #define TESTCLEARFLAG(uname, lname, policy) \
static inline int TestClearPage##uname(struct page *page) \ static __always_inline int TestClearPage##uname(struct page *page) \
{ return test_and_clear_bit(PG_##lname, &policy(page, 1)->flags); } { return test_and_clear_bit(PG_##lname, &policy(page, 1)->flags); }
#define PAGEFLAG(uname, lname, policy) \ #define PAGEFLAG(uname, lname, policy) \
...@@ -371,7 +371,7 @@ PAGEFLAG(Idle, idle, PF_ANY) ...@@ -371,7 +371,7 @@ PAGEFLAG(Idle, idle, PF_ANY)
#define PAGE_MAPPING_KSM 2 #define PAGE_MAPPING_KSM 2
#define PAGE_MAPPING_FLAGS (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM) #define PAGE_MAPPING_FLAGS (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM)
static inline int PageAnon(struct page *page) static __always_inline int PageAnon(struct page *page)
{ {
page = compound_head(page); page = compound_head(page);
return ((unsigned long)page->mapping & PAGE_MAPPING_ANON) != 0; return ((unsigned long)page->mapping & PAGE_MAPPING_ANON) != 0;
...@@ -384,7 +384,7 @@ static inline int PageAnon(struct page *page) ...@@ -384,7 +384,7 @@ static inline int PageAnon(struct page *page)
* is found in VM_MERGEABLE vmas. It's a PageAnon page, pointing not to any * is found in VM_MERGEABLE vmas. It's a PageAnon page, pointing not to any
* anon_vma, but to that page's node of the stable tree. * anon_vma, but to that page's node of the stable tree.
*/ */
static inline int PageKsm(struct page *page) static __always_inline int PageKsm(struct page *page)
{ {
page = compound_head(page); page = compound_head(page);
return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) == return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) ==
...@@ -415,14 +415,14 @@ static inline int PageUptodate(struct page *page) ...@@ -415,14 +415,14 @@ static inline int PageUptodate(struct page *page)
return ret; return ret;
} }
static inline void __SetPageUptodate(struct page *page) static __always_inline void __SetPageUptodate(struct page *page)
{ {
VM_BUG_ON_PAGE(PageTail(page), page); VM_BUG_ON_PAGE(PageTail(page), page);
smp_wmb(); smp_wmb();
__set_bit(PG_uptodate, &page->flags); __set_bit(PG_uptodate, &page->flags);
} }
static inline void SetPageUptodate(struct page *page) static __always_inline void SetPageUptodate(struct page *page)
{ {
VM_BUG_ON_PAGE(PageTail(page), page); VM_BUG_ON_PAGE(PageTail(page), page);
/* /*
...@@ -456,12 +456,12 @@ static inline void set_page_writeback_keepwrite(struct page *page) ...@@ -456,12 +456,12 @@ static inline void set_page_writeback_keepwrite(struct page *page)
__PAGEFLAG(Head, head, PF_ANY) CLEARPAGEFLAG(Head, head, PF_ANY) __PAGEFLAG(Head, head, PF_ANY) CLEARPAGEFLAG(Head, head, PF_ANY)
static inline void set_compound_head(struct page *page, struct page *head) static __always_inline void set_compound_head(struct page *page, struct page *head)
{ {
WRITE_ONCE(page->compound_head, (unsigned long)head + 1); WRITE_ONCE(page->compound_head, (unsigned long)head + 1);
} }
static inline void clear_compound_head(struct page *page) static __always_inline void clear_compound_head(struct page *page)
{ {
WRITE_ONCE(page->compound_head, 0); WRITE_ONCE(page->compound_head, 0);
} }
......
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