On Mon, Apr 19, 2021 at 12:36:19PM +0300, Mike Rapoport wrote:
Well, most if the -4.2% of the performance regression kbuild reported were due to repeated compount_head(page) in page_mapping(). So the whole point of this patch is to avoid calling page_mapping().
It's quite ludicrous how many times we call compound_head() in page_mapping() today:
page = compound_head(page); if (__builtin_expect(!!(PageSlab(page)), 0)) if (__builtin_expect(!!(PageSwapCache(page)), 0)) {
TESTPAGEFLAG(Slab, slab, PF_NO_TAIL) expands to:
static __always_inline int PageSlab(struct page *page) { PF_POISONED_CHECK(compound_head(page)); return test_bit(PG_slab, &compound_head(page)); }
static __always_inline int PageSwapCache(struct page *page) { page = compound_head(page); return PageSwapBacked(page) && test_bit(PG_swapcache, &page->flags); }
but then!
TESTPAGEFLAG(SwapBacked, swapbacked, PF_NO_TAIL) also expands like Slab does.
So that's six calls to compound_head(), depending what Kconfig options you have enabled.
And folio_mapping() is one of the functions I add in the first batch of patches, so review, etc will be helpful.