[PATCH] mm: uninline slowpath of page_mapcount()

From: Kirill A. Shutemov
Date: Sun Nov 08 2015 - 18:34:08 EST


Let's move page_mapcount() part for compound page into mm/util.c.

make allyesconfig:

text data bss dec hex filename
188515051 153360535 85458720 427334306 19789aa2 vmlinux.o.before
188512917 153356439 85458720 427328076 1978824c vmlinux.o.after

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx>
---
include/linux/mm.h | 14 +++++---------
mm/util.c | 14 ++++++++++++++
2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index f874d2a1d1a6..72edbbec7b91 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -417,19 +417,15 @@ static inline void page_mapcount_reset(struct page *page)
atomic_set(&(page)->_mapcount, -1);
}

+int __page_mapcount(struct page *page);
+
static inline int page_mapcount(struct page *page)
{
- int ret;
VM_BUG_ON_PAGE(PageSlab(page), page);

- ret = atomic_read(&page->_mapcount) + 1;
- if (PageCompound(page)) {
- page = compound_head(page);
- ret += atomic_read(compound_mapcount_ptr(page)) + 1;
- if (PageDoubleMap(page))
- ret--;
- }
- return ret;
+ if (unlikely(PageCompound(page)))
+ return __page_mapcount(page);
+ return atomic_read(&page->_mapcount) + 1;
}

#ifdef CONFIG_TRANSPARENT_HUGEPAGE
diff --git a/mm/util.c b/mm/util.c
index 902b65a43899..68535c0bb9da 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -376,6 +376,20 @@ struct address_space *page_mapping(struct page *page)
return mapping;
}

+/* Slow path of page_mapcount() for compound pages */
+int __page_mapcount(struct page *page)
+{
+ int ret;
+
+ page = compound_head(page);
+ ret = atomic_read(&page->_mapcount) + 1;
+ ret += atomic_read(compound_mapcount_ptr(page)) + 1;
+ if (PageDoubleMap(page))
+ ret--;
+ return ret;
+}
+EXPORT_SYMBOL_GPL(__page_mapcount);
+
int overcommit_ratio_handler(struct ctl_table *table, int write,
void __user *buffer, size_t *lenp,
loff_t *ppos)
--
Kirill A. Shutemov
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/