From af1500db46b4700ac61a120e88b8e9e359cc17a9 Mon Sep 17 00:00:00 2001 From: Christoph Lameter Date: Wed, 3 Oct 2007 20:42:43 -0700 Subject: [PATCH] vcompound: vmalloc_to_head page The determination of a page struct for an address in a compound page will need some more smarts in order to deal with (possibly) vmalloc addresses. We need to use the evil constants VMALLOC_START and VMALLOC_END for this and they are notoriously for referencing various arch header files or may even be variables. Uninline the function to avoid trouble. Signed-off-by: Christoph Lameter --- include/linux/mm.h | 8 ++++++++ include/linux/vmalloc.h | 2 +- mm/vmalloc.c | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) Index: linux-2.6.25-rc5-mm1/include/linux/mm.h =================================================================== --- linux-2.6.25-rc5-mm1.orig/include/linux/mm.h 2008-03-20 19:56:45.452143822 -0700 +++ linux-2.6.25-rc5-mm1/include/linux/mm.h 2008-03-20 19:57:43.860409023 -0700 @@ -262,6 +262,9 @@ static inline void get_page(struct page atomic_inc(&page->_count); } +/* + * Determine head page for a given address (cannot be a vmalloc address). + */ static inline struct page *virt_to_head_page(const void *x) { struct page *page = virt_to_page(x); @@ -269,6 +272,11 @@ static inline struct page *virt_to_head_ } /* + * Determine head page of a (possibly mapped via vmalloc) compound page. + */ +struct page *vmalloc_to_head_page(const void *x); + +/* * Setup the page count before being freed into the page allocator for * the first time (boot or memory hotplug) */ Index: linux-2.6.25-rc5-mm1/include/linux/vmalloc.h =================================================================== --- linux-2.6.25-rc5-mm1.orig/include/linux/vmalloc.h 2008-03-20 19:58:10.488529808 -0700 +++ linux-2.6.25-rc5-mm1/include/linux/vmalloc.h 2008-03-20 19:58:40.748665603 -0700 @@ -97,7 +97,7 @@ struct page *alloc_vcompound_alloc(gfp_t void free_vcompound(struct page *); void *__alloc_vcompound(gfp_t flags, int order); void __free_vcompound(void *addr); - +struct page *vcompound_head_page(const void *x); /* * Internals. Dont't use.. Index: linux-2.6.25-rc5-mm1/mm/vmalloc.c =================================================================== --- linux-2.6.25-rc5-mm1.orig/mm/vmalloc.c 2008-03-20 19:59:19.744837142 -0700 +++ linux-2.6.25-rc5-mm1/mm/vmalloc.c 2008-03-20 20:00:13.705049637 -0700 @@ -1074,6 +1074,30 @@ EXPORT_SYMBOL(vmalloc_address); * page conventions. I.e. following page->first_page if PageTail(page) is set * can be used to determine the head page. */ + +/* + * Determine the appropriate page struct given a virtual address + * (including vmalloced areas). + * + * Return the head page if this is a compound page. + * + * Cannot be inlined since VMALLOC_START and VMALLOC_END may contain + * complex calculations that depend on multiple arch includes or + * even variables. + */ +struct page *vmalloc_to_head_page(const void *x) +{ + unsigned long addr = (unsigned long)x; + struct page *page; + + if (unlikely(is_vmalloc_addr(addr))) + page = vmalloc_to_page((void *)addr); + else + page = virt_to_page(addr); + + return compound_head(page); +} + static void __vcompound_free(void *addr) {