From: Pekka Enberg <penberg@cs.helsinki.fi>
This patch changes ksize() to be more strict with objets passed to it. We now
set PageSlab also for objects allocated with page allocator and use page->slab
to check whether page is a regular slab page or a pass-through page.
Also moves kmalloc_large() out-of-line as it's too big for inlining now.
Cc: Christoph Lameter <clameter@sgi.com>
Cc: Matt Mackall <mpm@selenic.com>
Cc: Paul Mundt <lethal@linux-sh.org>
Cc: David Howells <dhowells@redhat.com>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
---
include/linux/slub_def.h | 5 +----
mm/slub.c | 34 ++++++++++++++++++++++++++--------
2 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
index 71e43a1..542f828 100644
--- a/include/linux/slub_def.h
+++ b/include/linux/slub_def.h
@@ -201,10 +201,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
void *__kmalloc(size_t size, gfp_t flags);
-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
-{
- return (void *)__get_free_pages(flags | __GFP_COMP, get_order(size));
-}
+void *kmalloc_large(size_t, gfp_t);
static __always_inline void *kmalloc(size_t size, gfp_t flags)
{
diff --git a/mm/slub.c b/mm/slub.c
index a505a82..84b9689 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2687,15 +2687,29 @@ void *__kmalloc(size_t size, gfp_t flags)
}
EXPORT_SYMBOL(__kmalloc);
+void *kmalloc_large(size_t size, gfp_t flags)
+{
+ struct page *page;
+
+ page = alloc_pages(flags | __GFP_COMP, get_order(size));
+ if (!page)
+ return NULL;
+
+ __SetPageSlab(page);
+ return page_address(page);
+}
+EXPORT_SYMBOL(kmalloc_large);
+
static void *kmalloc_large_node(size_t size, gfp_t flags, int node)
{
struct page *page = alloc_pages_node(node, flags | __GFP_COMP,
get_order(size));
- if (page)
- return page_address(page);
- else
+ if (!page)
return NULL;
+
+ __SetPageSlab(page);
+ return page_address(page);
}
#ifdef CONFIG_NUMA
@@ -2725,12 +2739,12 @@ size_t ksize(const void *object)
return 0;
page = virt_to_head_page(object);
+ BUG_ON(!PageSlab(page));
+ s = page->slab;
- if (unlikely(!PageSlab(page)))
+ if (unlikely(!s))
return PAGE_SIZE << compound_order(page);
- s = page->slab;
-
#ifdef CONFIG_SLUB_DEBUG
/*
* Debugging requires use of the padding between object
@@ -2756,6 +2770,7 @@ EXPORT_SYMBOL(ksize);
void kfree(const void *x)
{
+ struct kmem_cache *s;
struct page *page;
void *object = (void *)x;
@@ -2763,11 +2778,14 @@ void kfree(const void *x)
return;
page = virt_to_head_page(x);
- if (unlikely(!PageSlab(page))) {
+ BUG_ON(!PageSlab(page));
+ s = page->slab;
+ if (unlikely(!s)) {
+ __ClearPageSlab(page);
put_page(page);
return;
}
- slab_free(page->slab, page, object, __builtin_return_address(0));
+ slab_free(s, page, object, __builtin_return_address(0));
}
EXPORT_SYMBOL(kfree);
--
1.5.2.5
--
| Christoph Lameter | [04/14] vcompound: Core piece |
| Rafael J. Wysocki | 2.6.24-rc4-git5: Reported regressions from 2.6.23 |
| Greg Kroah-Hartman | [PATCH 001/196] Chinese: Add the known_regression URI to the HOWTO |
| Andrew Morton | Re: 2.6.21-rc2-mm1 |
git: | |
| Ken Pratt | pack operation is thrashing my server |
| Kyle Moffett | Using GIT to store /etc (Or: How to make GIT store all file permission bits) |
| Nicolas Pitre | Re: Cleaning up git user-interface warts |
| Toby White | Using Filemerge.app as a git-diff viewer |
| Richard Stallman | Real men don't attack straw men |
| Peter | OpenBSD as Virtualbox guest |
| Richard Daemon | OpenBSD 4.3 running in VirtualBox? Anyone have it working properly? |
| Mark Zimmerman | alix 2c3 bios version |
| Christoph Hellwig | Re: silent semantic changes with reiser4 |
| Al Boldi | Re: [RFD] Incremental fsck |
| Theodore Tso | Re: [RFC 0/13] extents and 48bit ext3 |
| Josef Jeff Sipek | [PATCH 22 of 23] Unionfs: Unlink |
