* [RFC/PATCH 1/3] SLAB: Add PageSlab checking to ksize()
@ 2008-05-21 18:25 Pekka J Enberg
2008-05-21 23:45 ` Paul Mundt
0 siblings, 1 reply; 13+ 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>
The ksize() function is meant for objects allocated from the slab caches, not
for arbitrary objects. Add a BUG_ON() to enforce that.
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/slab.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/mm/slab.c b/mm/slab.c
index 06236e4..b98bb7c 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -4472,10 +4472,14 @@ const struct seq_operations slabstats_op = {
*/
size_t ksize(const void *objp)
{
+ struct page *page;
+
BUG_ON(!objp);
if (unlikely(objp == ZERO_SIZE_PTR))
return 0;
- return obj_size(virt_to_cache(objp));
+ page = virt_to_page(objp);
+ BUG_ON(!PageSlab(page));
+ return obj_size(page_get_cache(page));
}
EXPORT_SYMBOL(ksize);
--
1.5.2.5
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [RFC/PATCH 1/3] SLAB: Add PageSlab checking to ksize()
2008-05-21 18:25 [RFC/PATCH 1/3] SLAB: Add PageSlab checking to ksize() Pekka J Enberg
@ 2008-05-21 23:45 ` Paul Mundt
2008-05-22 4:13 ` Pekka Enberg
0 siblings, 1 reply; 13+ messages in thread
From: Paul Mundt @ 2008-05-21 23:45 UTC (permalink / raw)
To: Pekka J Enberg; +Cc: linux-kernel, clameter, mpm, dhowells
On Wed, May 21, 2008 at 09:25:26PM +0300, Pekka J Enberg wrote:
> From: Pekka Enberg <penberg@cs.helsinki.fi>
>
> The ksize() function is meant for objects allocated from the slab caches, not
> for arbitrary objects. Add a BUG_ON() to enforce that.
>
> 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>
This series seems to work ok with all of SLAB/SLUB/SLOB when also
applying the kobjsize() patch. Without the kobjsize() patch in place,
SLAB and SLUB both work, while SLOB still triggers the >= MAX_ORDER
BUG_ON() for page cache pages. Note that this is still an improvement
over SLUB blowing up, as it was before, even without the kobjsize()
change.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [RFC/PATCH 1/3] SLAB: Add PageSlab checking to ksize()
2008-05-21 23:45 ` Paul Mundt
@ 2008-05-22 4:13 ` Pekka Enberg
2008-05-22 4:17 ` Christoph Lameter
0 siblings, 1 reply; 13+ messages in thread
From: Pekka Enberg @ 2008-05-22 4:13 UTC (permalink / raw)
To: Paul Mundt, Pekka J Enberg, linux-kernel, clameter, mpm, dhowells
Paul Mundt wrote:
> This series seems to work ok with all of SLAB/SLUB/SLOB when also
> applying the kobjsize() patch. Without the kobjsize() patch in place,
> SLAB and SLUB both work, while SLOB still triggers the >= MAX_ORDER
> BUG_ON() for page cache pages. Note that this is still an improvement
> over SLUB blowing up, as it was before, even without the kobjsize()
> change.
That's probably due to the fact that we use PageSlab for all pages with
SLUB and for bigblock pages in SLOB with this patch. Christoph, Matt,
any suggestions how to fix the PageSlab check in nommu btw?
Pekka
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [RFC/PATCH 1/3] SLAB: Add PageSlab checking to ksize()
2008-05-22 4:13 ` Pekka Enberg
@ 2008-05-22 4:17 ` Christoph Lameter
2008-05-22 4:21 ` Pekka Enberg
0 siblings, 1 reply; 13+ messages in thread
From: Christoph Lameter @ 2008-05-22 4:17 UTC (permalink / raw)
To: Pekka Enberg; +Cc: Paul Mundt, linux-kernel, mpm, dhowells
On Thu, 22 May 2008, Pekka Enberg wrote:
> Paul Mundt wrote:
> > This series seems to work ok with all of SLAB/SLUB/SLOB when also
> > applying the kobjsize() patch. Without the kobjsize() patch in place,
> > SLAB and SLUB both work, while SLOB still triggers the >= MAX_ORDER
> > BUG_ON() for page cache pages. Note that this is still an improvement
> > over SLUB blowing up, as it was before, even without the kobjsize()
> > change.
>
> That's probably due to the fact that we use PageSlab for all pages with SLUB
> and for bigblock pages in SLOB with this patch. Christoph, Matt, any
> suggestions how to fix the PageSlab check in nommu btw?
I already posted a patch and commented numerous times. What else needs
to be said? SLUB only uses PageSlab for kmalloc <=4kb.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [RFC/PATCH 1/3] SLAB: Add PageSlab checking to ksize()
2008-05-22 4:17 ` Christoph Lameter
@ 2008-05-22 4:21 ` Pekka Enberg
2008-05-22 4:34 ` Paul Mundt
0 siblings, 1 reply; 13+ messages in thread
From: Pekka Enberg @ 2008-05-22 4:21 UTC (permalink / raw)
To: Christoph Lameter; +Cc: Paul Mundt, linux-kernel, mpm, dhowells
Christoph Lameter wrote:
>> That's probably due to the fact that we use PageSlab for all pages with SLUB
>> and for bigblock pages in SLOB with this patch. Christoph, Matt, any
>> suggestions how to fix the PageSlab check in nommu btw?
>
> I already posted a patch and commented numerous times. What else needs
> to be said? SLUB only uses PageSlab for kmalloc <=4kb.
(I missed your patch, btw.)
For SLOB, we will never use ksize() as it doesn't set PageSlab. Is that
not a problem?
Pekka
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [RFC/PATCH 1/3] SLAB: Add PageSlab checking to ksize()
2008-05-22 4:21 ` Pekka Enberg
@ 2008-05-22 4:34 ` Paul Mundt
2008-05-22 4:43 ` Pekka Enberg
0 siblings, 1 reply; 13+ messages in thread
From: Paul Mundt @ 2008-05-22 4:34 UTC (permalink / raw)
To: Pekka Enberg; +Cc: Christoph Lameter, linux-kernel, mpm, dhowells
On Thu, May 22, 2008 at 07:21:48AM +0300, Pekka Enberg wrote:
> Christoph Lameter wrote:
> >>That's probably due to the fact that we use PageSlab for all pages with
> >>SLUB
> >>and for bigblock pages in SLOB with this patch. Christoph, Matt, any
> >>suggestions how to fix the PageSlab check in nommu btw?
> >
> >I already posted a patch and commented numerous times. What else needs
> >to be said? SLUB only uses PageSlab for kmalloc <=4kb.
>
> (I missed your patch, btw.)
>
> For SLOB, we will never use ksize() as it doesn't set PageSlab. Is that
> not a problem?
>
That means that kobjsize() will hand back PAGE_SIZE for non-compound
pages, which is what it's presently doing anyways. In the case of SLOB
bigblock pages allocated on pass-through to the page allocator, these are
compound pages anyways, so compound_page() should do the right thing
there? That only handles the kmalloc() path though, and not the
kmem_cache_alloc() cases.
Shouldn't SLOB's PageSlab usage should mimic that of SLUB in this case
instead? PG_slab doesn't buy us much if we can already sort out the size
through compound_order(), it's the kmem_cache_alloc() and <= PAGE_SIZE
kmalloc()'s where __GFP_COMP isn't true and where PG_slab should be set.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [RFC/PATCH 1/3] SLAB: Add PageSlab checking to ksize()
2008-05-22 4:34 ` Paul Mundt
@ 2008-05-22 4:43 ` Pekka Enberg
2008-05-22 4:55 ` Paul Mundt
2008-05-22 15:01 ` Matt Mackall
0 siblings, 2 replies; 13+ messages in thread
From: Pekka Enberg @ 2008-05-22 4:43 UTC (permalink / raw)
To: Paul Mundt, Pekka Enberg, Christoph Lameter, linux-kernel, mpm,
dhowells
Hi Paul,
Paul Mundt wrote:
> Shouldn't SLOB's PageSlab usage should mimic that of SLUB in this case
> instead? PG_slab doesn't buy us much if we can already sort out the size
> through compound_order(), it's the kmem_cache_alloc() and <= PAGE_SIZE
> kmalloc()'s where __GFP_COMP isn't true and where PG_slab should be set.
Well, we should really be calling ksize() in the nommu case and although
Matt and Christoph don't seem to agree with me here, I'd much rather
have *all* allocators set PageSlab for all the pages they return (yes,
including pass-through ones) to get us back where we were with SLAB. We
currently don't have any means to see whether an arbitrary page is part
of the slab or not and I'd argue that's PageSlab is an established API
(that makes sense).
Furthermore, if ksize() in SLOB doesn't work for kmem_cache_alloc()
pages, I think it should be fixed as well.
Pekka
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [RFC/PATCH 1/3] SLAB: Add PageSlab checking to ksize()
2008-05-22 4:43 ` Pekka Enberg
@ 2008-05-22 4:55 ` Paul Mundt
2008-05-22 15:01 ` Matt Mackall
1 sibling, 0 replies; 13+ messages in thread
From: Paul Mundt @ 2008-05-22 4:55 UTC (permalink / raw)
To: Pekka Enberg; +Cc: Christoph Lameter, linux-kernel, mpm, dhowells
On Thu, May 22, 2008 at 07:43:02AM +0300, Pekka Enberg wrote:
> Paul Mundt wrote:
> >Shouldn't SLOB's PageSlab usage should mimic that of SLUB in this case
> >instead? PG_slab doesn't buy us much if we can already sort out the size
> >through compound_order(), it's the kmem_cache_alloc() and <= PAGE_SIZE
> >kmalloc()'s where __GFP_COMP isn't true and where PG_slab should be set.
>
> Well, we should really be calling ksize() in the nommu case and although
> Matt and Christoph don't seem to agree with me here, I'd much rather
> have *all* allocators set PageSlab for all the pages they return (yes,
> including pass-through ones) to get us back where we were with SLAB. We
> currently don't have any means to see whether an arbitrary page is part
> of the slab or not and I'd argue that's PageSlab is an established API
> (that makes sense).
>
> Furthermore, if ksize() in SLOB doesn't work for kmem_cache_alloc()
> pages, I think it should be fixed as well.
>
SLOB's kmem_cache_alloc() pages won't have PageSlab set, so ksize()
will never be called, and we will simply always return PAGE_SIZE from
kobjsize() for those objects, as they don't set __GFP_COMP either.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [RFC/PATCH 1/3] SLAB: Add PageSlab checking to ksize()
2008-05-22 4:43 ` Pekka Enberg
2008-05-22 4:55 ` Paul Mundt
@ 2008-05-22 15:01 ` Matt Mackall
2008-05-22 16:13 ` Pekka Enberg
1 sibling, 1 reply; 13+ messages in thread
From: Matt Mackall @ 2008-05-22 15:01 UTC (permalink / raw)
To: Pekka Enberg; +Cc: Paul Mundt, Christoph Lameter, linux-kernel, dhowells
On Thu, 2008-05-22 at 07:43 +0300, Pekka Enberg wrote:
> Hi Paul,
>
> Paul Mundt wrote:
> > Shouldn't SLOB's PageSlab usage should mimic that of SLUB in this case
> > instead? PG_slab doesn't buy us much if we can already sort out the size
> > through compound_order(), it's the kmem_cache_alloc() and <= PAGE_SIZE
> > kmalloc()'s where __GFP_COMP isn't true and where PG_slab should be set.
>
> Well, we should really be calling ksize() in the nommu case and although
> Matt and Christoph don't seem to agree with me here, I'd much rather
> have *all* allocators set PageSlab for all the pages they return (yes,
> including pass-through ones) to get us back where we were with SLAB. We
> currently don't have any means to see whether an arbitrary page is part
> of the slab or not and I'd argue that's PageSlab is an established API
> (that makes sense).
>
> Furthermore, if ksize() in SLOB doesn't work for kmem_cache_alloc()
> pages, I think it should be fixed as well.
As I've said several times, ksize() on kmem_cache_alloced objects
-cannot work- on SLOB. Calling ksize() on something returned by
kmem_cache_alloc is a categorical error.
--
Mathematics is the supreme nostalgia of our time.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [RFC/PATCH 1/3] SLAB: Add PageSlab checking to ksize()
2008-05-22 15:01 ` Matt Mackall
@ 2008-05-22 16:13 ` Pekka Enberg
2008-05-22 16:51 ` Christoph Lameter
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Pekka Enberg @ 2008-05-22 16:13 UTC (permalink / raw)
To: Matt Mackall; +Cc: Paul Mundt, Christoph Lameter, linux-kernel, dhowells
Hi Matt,
On Thu, May 22, 2008 at 6:01 PM, Matt Mackall <mpm@selenic.com> wrote:
> As I've said several times, ksize() on kmem_cache_alloced objects
> -cannot work- on SLOB. Calling ksize() on something returned by
> kmem_cache_alloc is a categorical error.
Well, it's a historical fact that ksize() worked for both kmalloc()
and kmem_cache_alloc() (see the kernedoc comment in mm/slab.c).
However, I think we should just look at getting rid of ksize()
altogether as it's only (ab)used by the nommu code and few call-sites
that open-code krealloc().
Pekka
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [RFC/PATCH 1/3] SLAB: Add PageSlab checking to ksize()
2008-05-22 16:13 ` Pekka Enberg
@ 2008-05-22 16:51 ` Christoph Lameter
2008-05-22 18:31 ` Matt Mackall
2008-05-23 14:23 ` Adrian Bunk
2 siblings, 0 replies; 13+ messages in thread
From: Christoph Lameter @ 2008-05-22 16:51 UTC (permalink / raw)
To: Pekka Enberg; +Cc: Matt Mackall, Paul Mundt, linux-kernel, dhowells
On Thu, 22 May 2008, Pekka Enberg wrote:
> Hi Matt,
>
> On Thu, May 22, 2008 at 6:01 PM, Matt Mackall <mpm@selenic.com> wrote:
> > As I've said several times, ksize() on kmem_cache_alloced objects
> > -cannot work- on SLOB. Calling ksize() on something returned by
> > kmem_cache_alloc is a categorical error.
>
> Well, it's a historical fact that ksize() worked for both kmalloc()
> and kmem_cache_alloc() (see the kernedoc comment in mm/slab.c).
> However, I think we should just look at getting rid of ksize()
> altogether as it's only (ab)used by the nommu code and few call-sites
> that open-code krealloc().
Good idea. if krealloc is an allocator internal function then it can
establish the size as needed and we do not have ksize available.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [RFC/PATCH 1/3] SLAB: Add PageSlab checking to ksize()
2008-05-22 16:13 ` Pekka Enberg
2008-05-22 16:51 ` Christoph Lameter
@ 2008-05-22 18:31 ` Matt Mackall
2008-05-23 14:23 ` Adrian Bunk
2 siblings, 0 replies; 13+ messages in thread
From: Matt Mackall @ 2008-05-22 18:31 UTC (permalink / raw)
To: Pekka Enberg; +Cc: Paul Mundt, Christoph Lameter, linux-kernel, dhowells
On Thu, 2008-05-22 at 19:13 +0300, Pekka Enberg wrote:
> Hi Matt,
>
> On Thu, May 22, 2008 at 6:01 PM, Matt Mackall <mpm@selenic.com> wrote:
> > As I've said several times, ksize() on kmem_cache_alloced objects
> > -cannot work- on SLOB. Calling ksize() on something returned by
> > kmem_cache_alloc is a categorical error.
>
> Well, it's a historical fact that ksize() worked for both kmalloc()
> and kmem_cache_alloc() (see the kernedoc comment in mm/slab.c).
Indeed. It looks like it was in fact introduced for nommu (back in
2.5.47). But much like kfree(kmem_cache_alloc()) is a bogus thing to do,
ksize(kmem_cache_alloc()) is assuming too much about the relationship
between kmalloc and kmem_cache_alloc.
Nommu's accounting code makes two misguided assumptions a) that we can
determine how/whether something was allocated just from a pointer b)
that the size of that object can be determined dynamically in any case
other than kmalloc. But it really shouldn't need to do either of these.
> However, I think we should just look at getting rid of ksize()
> altogether as it's only (ab)used by the nommu code and few call-sites
> that open-code krealloc().
Right.
--
Mathematics is the supreme nostalgia of our time.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [RFC/PATCH 1/3] SLAB: Add PageSlab checking to ksize()
2008-05-22 16:13 ` Pekka Enberg
2008-05-22 16:51 ` Christoph Lameter
2008-05-22 18:31 ` Matt Mackall
@ 2008-05-23 14:23 ` Adrian Bunk
2 siblings, 0 replies; 13+ messages in thread
From: Adrian Bunk @ 2008-05-23 14:23 UTC (permalink / raw)
To: Pekka Enberg
Cc: Matt Mackall, Paul Mundt, Christoph Lameter, linux-kernel,
dhowells
On Thu, May 22, 2008 at 07:13:56PM +0300, Pekka Enberg wrote:
>...
> However, I think we should just look at getting rid of ksize()
> altogether as it's only (ab)used by the nommu code and few call-sites
> that open-code krealloc().
As soon as your patch for the netfilter usage enters Linus' tree you can
unexport it which will at least make new abuses from modules impossible.
> Pekka
cu
Adrian
--
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2008-05-23 14:27 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-21 18:25 [RFC/PATCH 1/3] SLAB: Add PageSlab checking to ksize() Pekka J Enberg
2008-05-21 23:45 ` Paul Mundt
2008-05-22 4:13 ` Pekka Enberg
2008-05-22 4:17 ` Christoph Lameter
2008-05-22 4:21 ` Pekka Enberg
2008-05-22 4:34 ` Paul Mundt
2008-05-22 4:43 ` Pekka Enberg
2008-05-22 4:55 ` Paul Mundt
2008-05-22 15:01 ` Matt Mackall
2008-05-22 16:13 ` Pekka Enberg
2008-05-22 16:51 ` Christoph Lameter
2008-05-22 18:31 ` Matt Mackall
2008-05-23 14:23 ` Adrian Bunk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox