All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC/PATCH 2/3] SLUB: make ksize() more strict for page allocator pass-through
@ 2008-05-21 18:25 Pekka J Enberg
  2008-05-21 18:52 ` Christoph Lameter
  0 siblings, 1 reply; 6+ messages in thread
From: Pekka J Enberg @ 2008-05-21 18:25 UTC (permalink / raw)
  To: linux-kernel; +Cc: clameter, mpm, lethal, dhowells

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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [RFC/PATCH 2/3] SLUB: make ksize() more strict for page allocator pass-through
  2008-05-21 18:25 [RFC/PATCH 2/3] SLUB: make ksize() more strict for page allocator pass-through Pekka J Enberg
@ 2008-05-21 18:52 ` Christoph Lameter
  2008-05-21 18:56   ` Pekka Enberg
  0 siblings, 1 reply; 6+ messages in thread
From: Christoph Lameter @ 2008-05-21 18:52 UTC (permalink / raw)
  To: Pekka J Enberg; +Cc: linux-kernel, mpm, lethal, dhowells

On Wed, 21 May 2008, Pekka J Enberg wrote:

> 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.

Why is it too big? Without your additions it is converting kmallocs 
inline to get_free_pages(). That results in a simple function call with 
two constant parameters.

The patch touches the page struct uselessly. I think the PageSlab marking 
is useful for debugging but not for a production kernel.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC/PATCH 2/3] SLUB: make ksize() more strict for page allocator pass-through
  2008-05-21 18:52 ` Christoph Lameter
@ 2008-05-21 18:56   ` Pekka Enberg
  2008-05-21 21:14     ` Christoph Lameter
  2008-05-21 21:18     ` Christoph Lameter
  0 siblings, 2 replies; 6+ messages in thread
From: Pekka Enberg @ 2008-05-21 18:56 UTC (permalink / raw)
  To: Christoph Lameter; +Cc: linux-kernel, mpm, lethal, dhowells

Christoph Lameter wrote:
> Why is it too big? Without your additions it is converting kmallocs 
> inline to get_free_pages(). That results in a simple function call with 
> two constant parameters.

Well, it's a PITA because of #include dependencies in any case. Is 
moving it out-of-line a problem?

Christoph Lameter wrote:
> The patch touches the page struct uselessly. I think the PageSlab marking 
> is useful for debugging but not for a production kernel.

Hmm, where? page_address() already references ->virtual. I suppose 
CONFIG_SLUB_DEBUG is a no no as well then so do we want to add a 
CONFIG_KSIZE_DEBUG config option...? (Btw, I removed the BUG_ON() from 
kfree() as spotted by Vegard Nossum.)

			Pekka

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC/PATCH 2/3] SLUB: make ksize() more strict for page allocator pass-through
  2008-05-21 18:56   ` Pekka Enberg
@ 2008-05-21 21:14     ` Christoph Lameter
  2008-05-21 21:15       ` Pekka Enberg
  2008-05-21 21:18     ` Christoph Lameter
  1 sibling, 1 reply; 6+ messages in thread
From: Christoph Lameter @ 2008-05-21 21:14 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: linux-kernel, mpm, lethal, dhowells

On Wed, 21 May 2008, Pekka Enberg wrote:

> Christoph Lameter wrote:
> > Why is it too big? Without your additions it is converting kmallocs inline
> > to get_free_pages(). That results in a simple function call with two
> > constant parameters.
> 
> Well, it's a PITA because of #include dependencies in any case. Is moving it
> out-of-line a problem?
> 
> Christoph Lameter wrote:
> > The patch touches the page struct uselessly. I think the PageSlab marking is
> > useful for debugging but not for a production kernel.
> 
> Hmm, where? page_address() already references ->virtual. I suppose
> CONFIG_SLUB_DEBUG is a no no as well then so do we want to add a
> CONFIG_KSIZE_DEBUG config option...? (Btw, I removed the BUG_ON() from kfree()
> as spotted by Vegard Nossum.)

If it has to be then add CONFIG_KSIZE_DEBUG. There are a number of 
debugging techniques (kmem_check?) that should not be compiled in. Maybe 
add a new config option for those. CONFIG_SLUB_ENABLE_EXPENSIVE_DEBUG?


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC/PATCH 2/3] SLUB: make ksize() more strict for page allocator pass-through
  2008-05-21 21:14     ` Christoph Lameter
@ 2008-05-21 21:15       ` Pekka Enberg
  0 siblings, 0 replies; 6+ messages in thread
From: Pekka Enberg @ 2008-05-21 21:15 UTC (permalink / raw)
  To: Christoph Lameter, Vegard Nossum; +Cc: linux-kernel, mpm, lethal, dhowells

Christoph Lameter wrote:
>> Hmm, where? page_address() already references ->virtual. I suppose
>> CONFIG_SLUB_DEBUG is a no no as well then so do we want to add a
>> CONFIG_KSIZE_DEBUG config option...? (Btw, I removed the BUG_ON() from kfree()
>> as spotted by Vegard Nossum.)
> 
> If it has to be then add CONFIG_KSIZE_DEBUG. There are a number of 
> debugging techniques (kmem_check?) that should not be compiled in. Maybe 
> add a new config option for those. CONFIG_SLUB_ENABLE_EXPENSIVE_DEBUG?

Oh, kmemcheck is a separate config option already and it's *much much* 
more expensive than the ksize() checks will ever be so they shouldn't be 
bundled together anyway.

		Pekka

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC/PATCH 2/3] SLUB: make ksize() more strict for page allocator pass-through
  2008-05-21 18:56   ` Pekka Enberg
  2008-05-21 21:14     ` Christoph Lameter
@ 2008-05-21 21:18     ` Christoph Lameter
  1 sibling, 0 replies; 6+ messages in thread
From: Christoph Lameter @ 2008-05-21 21:18 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: linux-kernel, mpm, lethal, dhowells

On Wed, 21 May 2008, Pekka Enberg wrote:

> Hmm, where? page_address() already references ->virtual. I suppose

The ->virtual case is a very special case. page_address() currently should 
reduce to a simple shift and an add with VMEMMAP.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-05-21 21:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-21 18:25 [RFC/PATCH 2/3] SLUB: make ksize() more strict for page allocator pass-through Pekka J Enberg
2008-05-21 18:52 ` Christoph Lameter
2008-05-21 18:56   ` Pekka Enberg
2008-05-21 21:14     ` Christoph Lameter
2008-05-21 21:15       ` Pekka Enberg
2008-05-21 21:18     ` Christoph Lameter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.