* [RFC/PATCH 3/3] SLOB: make ksize() more strict for page allocator pass-through
@ 2008-05-21 18:26 Pekka J Enberg
2008-05-21 19:07 ` Matt Mackall
0 siblings, 1 reply; 6+ messages in thread
From: Pekka J Enberg @ 2008-05-21 18:26 UTC (permalink / raw)
To: linux-kernel; +Cc: clameter, mpm, lethal, dhowells
From: Pekka Enberg <penberg@cs.helsinki.fi>
This patch re-uses the PG_slab flag for marking SLOB bigblock pages so we can
check that the pointer passed ksize() was really allocated by SLOB.
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>
---
mm/slob.c | 34 ++++++++++++++++++++++++++++++----
1 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/mm/slob.c b/mm/slob.c
index a3ad667..4dc077e 100644
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -144,6 +144,24 @@ static inline void clear_slob_page(struct slob_page *sp)
}
/*
+ * slob_bigpage: True for slob bigblock pages
+ */
+static inline int slob_bigpage(struct page *page)
+{
+ return test_bit(PG_slab, &page->flags);
+}
+
+static inline void set_slob_bigpage(struct page *page)
+{
+ __set_bit(PG_slab, &page->flags);
+}
+
+static inline void clear_slob_bigpage(struct page *page)
+{
+ __clear_bit(PG_slab, &page->flags);
+}
+
+/*
* slob_page_free: true for pages on free_slob_pages list.
*/
static inline int slob_page_free(struct slob_page *sp)
@@ -481,6 +499,7 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
struct page *page;
page = virt_to_page(ret);
page->private = size;
+ set_slob_bigpage(page);
}
return ret;
}
@@ -499,8 +518,12 @@ void kfree(const void *block)
int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
unsigned int *m = (unsigned int *)(block - align);
slob_free(m, *m + align);
- } else
- put_page(&sp->page);
+ } else {
+ struct page *page = &sp->page;
+
+ clear_slob_bigpage(page);
+ put_page(page);
+ }
}
EXPORT_SYMBOL(kfree);
@@ -508,6 +531,7 @@ EXPORT_SYMBOL(kfree);
size_t ksize(const void *block)
{
struct slob_page *sp;
+ struct page *page;
BUG_ON(!block);
if (unlikely(block == ZERO_SIZE_PTR))
@@ -516,8 +540,10 @@ size_t ksize(const void *block)
sp = (struct slob_page *)virt_to_page(block);
if (slob_page(sp))
return ((slob_t *)block - 1)->units + SLOB_UNIT;
- else
- return sp->page.private;
+
+ page = &sp->page;
+ BUG_ON(!slob_bigpage(page));
+ return page->private;
}
EXPORT_SYMBOL(ksize);
--
1.5.2.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [RFC/PATCH 3/3] SLOB: make ksize() more strict for page allocator pass-through
2008-05-21 18:26 [RFC/PATCH 3/3] SLOB: make ksize() more strict for page allocator pass-through Pekka J Enberg
@ 2008-05-21 19:07 ` Matt Mackall
2008-05-21 19:11 ` Pekka Enberg
0 siblings, 1 reply; 6+ messages in thread
From: Matt Mackall @ 2008-05-21 19:07 UTC (permalink / raw)
To: Pekka J Enberg; +Cc: linux-kernel, clameter, lethal, dhowells
On Wed, 2008-05-21 at 21:26 +0300, Pekka J Enberg wrote:
> From: Pekka Enberg <penberg@cs.helsinki.fi>
>
> This patch re-uses the PG_slab flag for marking SLOB bigblock pages so we can
> check that the pointer passed ksize() was really allocated by SLOB.
Ok, first, BUG_ON is wrong.
We already know users (ie nommu memory usage reporting) are abusing this
interface. Making them blow up is unnecessary. Just give them wrong
answers. Issuing a warning might be a good idea for debugging.
Second, I'd prefer to keep this sort of debugging code out of SLOB.
SLUB is much better suited to debugging allocator abuse.
--
Mathematics is the supreme nostalgia of our time.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC/PATCH 3/3] SLOB: make ksize() more strict for page allocator pass-through
2008-05-21 19:07 ` Matt Mackall
@ 2008-05-21 19:11 ` Pekka Enberg
2008-05-21 21:12 ` Christoph Lameter
0 siblings, 1 reply; 6+ messages in thread
From: Pekka Enberg @ 2008-05-21 19:11 UTC (permalink / raw)
To: Matt Mackall; +Cc: linux-kernel, clameter, lethal, dhowells
Matt Mackall wrote:
> We already know users (ie nommu memory usage reporting) are abusing this
> interface. Making them blow up is unnecessary. Just give them wrong
> answers. Issuing a warning might be a good idea for debugging.
But kobjsize() never calls ksize() with SLOB as it doesn't set PageSlab.
Or are you talking about something else here?
Matt Mackall wrote:
> Second, I'd prefer to keep this sort of debugging code out of SLOB.
> SLUB is much better suited to debugging allocator abuse.
Fair enough. I'll drop the patch.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC/PATCH 3/3] SLOB: make ksize() more strict for page allocator pass-through
2008-05-21 19:11 ` Pekka Enberg
@ 2008-05-21 21:12 ` Christoph Lameter
2008-05-21 21:13 ` Pekka Enberg
0 siblings, 1 reply; 6+ messages in thread
From: Christoph Lameter @ 2008-05-21 21:12 UTC (permalink / raw)
To: Pekka Enberg; +Cc: Matt Mackall, linux-kernel, lethal, dhowells
On Wed, 21 May 2008, Pekka Enberg wrote:
> Matt Mackall wrote:
> > We already know users (ie nommu memory usage reporting) are abusing this
> > interface. Making them blow up is unnecessary. Just give them wrong
> > answers. Issuing a warning might be a good idea for debugging.
>
> But kobjsize() never calls ksize() with SLOB as it doesn't set PageSlab. Or
> are you talking about something else here?
>
> Matt Mackall wrote:
> > Second, I'd prefer to keep this sort of debugging code out of SLOB.
> > SLUB is much better suited to debugging allocator abuse.
>
> Fair enough. I'll drop the patch.
I also would prefer to keep this out of SLUB. Set/Clear PageSlab dirties
the cacheline and it forces the unlining of kmalloc_large.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC/PATCH 3/3] SLOB: make ksize() more strict for page allocator pass-through
2008-05-21 21:12 ` Christoph Lameter
@ 2008-05-21 21:13 ` Pekka Enberg
2008-05-21 21:16 ` Christoph Lameter
0 siblings, 1 reply; 6+ messages in thread
From: Pekka Enberg @ 2008-05-21 21:13 UTC (permalink / raw)
To: Christoph Lameter; +Cc: Matt Mackall, linux-kernel, lethal, dhowells
Christoph Lameter wrote:
> I also would prefer to keep this out of SLUB. Set/Clear PageSlab dirties
> the cacheline and it forces the unlining of kmalloc_large.
Hmm, well, that leaves ksize() open for more abuse. I guess we'll just
have to live with that then.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC/PATCH 3/3] SLOB: make ksize() more strict for page allocator pass-through
2008-05-21 21:13 ` Pekka Enberg
@ 2008-05-21 21:16 ` Christoph Lameter
0 siblings, 0 replies; 6+ messages in thread
From: Christoph Lameter @ 2008-05-21 21:16 UTC (permalink / raw)
To: Pekka Enberg; +Cc: Matt Mackall, linux-kernel, lethal, dhowells
On Thu, 22 May 2008, Pekka Enberg wrote:
> Christoph Lameter wrote:
> > I also would prefer to keep this out of SLUB. Set/Clear PageSlab dirties the
> > cacheline and it forces the unlining of kmalloc_large.
>
> Hmm, well, that leaves ksize() open for more abuse. I guess we'll just have to
> live with that then.
SLUB could add a BUG_ON(!PageCompound ) since we added buffering for order
0 allocs. So only order 1 and higher go through kmalloc large. That should
catch the general case.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-05-21 21:17 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:26 [RFC/PATCH 3/3] SLOB: make ksize() more strict for page allocator pass-through Pekka J Enberg
2008-05-21 19:07 ` Matt Mackall
2008-05-21 19:11 ` Pekka Enberg
2008-05-21 21:12 ` Christoph Lameter
2008-05-21 21:13 ` Pekka Enberg
2008-05-21 21:16 ` 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.