Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Christoph Lameter
On Wed, 21 Feb 2007, Pekka Enberg wrote: > Well, as a reference, the user-space equivalent is defined in SUSv3 as: > > "The realloc() function shall change the size of the memory object > pointed to by ptr to the size specified by size." The realloc functions intent is to leave the object in

Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Pekka Enberg
On 2/21/07, Christoph Lameter <[EMAIL PROTECTED]> wrote: Why not? Its a realloc call and these are the classic semantics of realloc. Otherwise realloc will always move the memory. Well, as a reference, the user-space equivalent is defined in SUSv3 as: "The realloc() function shall change the

Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Christoph Lameter
On Wed, 21 Feb 2007, Pekka Enberg wrote: > Christoph Lameter wrote: > > 2. Check if the size specified is larger than the next smallest general > > cache and only copy if we would really would allocate from a different > > cache. > > Yeah, I was thinking about this too but decided against it

Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Pekka Enberg
Hi Christoph, Christoph Lameter wrote: 1. Just do not allow shrinking via realloc. Probably no big loss and best performance. Not a big loss if you can afford the wasted memory. But, I don't think we should do this, there's no way for the caller to know that we will hold on to the memory

Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Christoph Lameter
On Wed, 21 Feb 2007, Pekka Enberg wrote: > Christoph Lameter wrote: > > Well could you check ksize for the old object first and if ksize <= new size > > then just skip the copy? I think this may allow you to get rid of the ksize > > callers. > > And not reallocate at all, right? I thought about

Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Pekka Enberg
Christoph Lameter wrote: Well could you check ksize for the old object first and if ksize <= new size then just skip the copy? I think this may allow you to get rid of the ksize callers. And not reallocate at all, right? I thought about that but then you wouldn't be able to use realloc() to

Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Christoph Lameter
On Wed, 21 Feb 2007, Pekka J Enberg wrote: > +void *krealloc(const void *p, size_t new_size, gfp_t flags) > +{ > + void *ret; > + > + if (unlikely(!p)) > + return kmalloc_track_caller(new_size, flags); > + > + if (unlikely(!new_size)) { > + kfree(p); > +

Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Christoph Lameter
On Wed, 21 Feb 2007, Pekka Enberg wrote: > On 2/21/07, Arjan van de Ven <[EMAIL PROTECTED]> wrote: > > please mark this one __must_check.. not storing realloc() return values > > is one of the more nasty types of bugs... but gcc can help us greatly > > here ;) > > So I guess we want the same

Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Arjan van de Ven
On Wed, 2007-02-21 at 11:33 +0200, Pekka Enberg wrote: > On 2/21/07, Arjan van de Ven <[EMAIL PROTECTED]> wrote: > > please mark this one __must_check.. not storing realloc() return values > > is one of the more nasty types of bugs... but gcc can help us greatly > > here ;) > > So I guess we want

Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Pekka Enberg
On 2/21/07, Arjan van de Ven <[EMAIL PROTECTED]> wrote: please mark this one __must_check.. not storing realloc() return values is one of the more nasty types of bugs... but gcc can help us greatly here ;) So I guess we want the same thing for the other allocator functions (__kmalloc et al) as

Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Arjan van de Ven
On Wed, 2007-02-21 at 10:06 +0200, Pekka J Enberg wrote: > From: Pekka Enberg <[EMAIL PROTECTED]> > > Introduce krealloc() for reallocating memory while preserving contents. please mark this one __must_check.. not storing realloc() return values is one of the more nasty types of bugs... but gcc

[PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Pekka J Enberg
From: Pekka Enberg <[EMAIL PROTECTED]> Introduce krealloc() for reallocating memory while preserving contents. Cc: Christoph Lameter <[EMAIL PROTECTED]> Signed-off-by: Pekka Enberg <[EMAIL PROTECTED]> --- include/linux/slab.h |1 + mm/util.c| 34

[PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Pekka J Enberg
From: Pekka Enberg [EMAIL PROTECTED] Introduce krealloc() for reallocating memory while preserving contents. Cc: Christoph Lameter [EMAIL PROTECTED] Signed-off-by: Pekka Enberg [EMAIL PROTECTED] --- include/linux/slab.h |1 + mm/util.c| 34 ++ 2

Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Arjan van de Ven
On Wed, 2007-02-21 at 10:06 +0200, Pekka J Enberg wrote: From: Pekka Enberg [EMAIL PROTECTED] Introduce krealloc() for reallocating memory while preserving contents. please mark this one __must_check.. not storing realloc() return values is one of the more nasty types of bugs... but gcc can

Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Pekka Enberg
On 2/21/07, Arjan van de Ven [EMAIL PROTECTED] wrote: please mark this one __must_check.. not storing realloc() return values is one of the more nasty types of bugs... but gcc can help us greatly here ;) So I guess we want the same thing for the other allocator functions (__kmalloc et al) as

Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Arjan van de Ven
On Wed, 2007-02-21 at 11:33 +0200, Pekka Enberg wrote: On 2/21/07, Arjan van de Ven [EMAIL PROTECTED] wrote: please mark this one __must_check.. not storing realloc() return values is one of the more nasty types of bugs... but gcc can help us greatly here ;) So I guess we want the same

Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Christoph Lameter
On Wed, 21 Feb 2007, Pekka Enberg wrote: On 2/21/07, Arjan van de Ven [EMAIL PROTECTED] wrote: please mark this one __must_check.. not storing realloc() return values is one of the more nasty types of bugs... but gcc can help us greatly here ;) So I guess we want the same thing for the

Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Christoph Lameter
On Wed, 21 Feb 2007, Pekka J Enberg wrote: +void *krealloc(const void *p, size_t new_size, gfp_t flags) +{ + void *ret; + + if (unlikely(!p)) + return kmalloc_track_caller(new_size, flags); + + if (unlikely(!new_size)) { + kfree(p); +

Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Pekka Enberg
Christoph Lameter wrote: Well could you check ksize for the old object first and if ksize = new size then just skip the copy? I think this may allow you to get rid of the ksize callers. And not reallocate at all, right? I thought about that but then you wouldn't be able to use realloc() to

Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Christoph Lameter
On Wed, 21 Feb 2007, Pekka Enberg wrote: Christoph Lameter wrote: Well could you check ksize for the old object first and if ksize = new size then just skip the copy? I think this may allow you to get rid of the ksize callers. And not reallocate at all, right? I thought about that but

Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Pekka Enberg
Hi Christoph, Christoph Lameter wrote: 1. Just do not allow shrinking via realloc. Probably no big loss and best performance. Not a big loss if you can afford the wasted memory. But, I don't think we should do this, there's no way for the caller to know that we will hold on to the memory

Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Christoph Lameter
On Wed, 21 Feb 2007, Pekka Enberg wrote: Christoph Lameter wrote: 2. Check if the size specified is larger than the next smallest general cache and only copy if we would really would allocate from a different cache. Yeah, I was thinking about this too but decided against it (for now) as

Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Pekka Enberg
On 2/21/07, Christoph Lameter [EMAIL PROTECTED] wrote: Why not? Its a realloc call and these are the classic semantics of realloc. Otherwise realloc will always move the memory. Well, as a reference, the user-space equivalent is defined in SUSv3 as: The realloc() function shall change the

Re: [PATCH 1/3] slab: introduce krealloc

2007-02-21 Thread Christoph Lameter
On Wed, 21 Feb 2007, Pekka Enberg wrote: Well, as a reference, the user-space equivalent is defined in SUSv3 as: The realloc() function shall change the size of the memory object pointed to by ptr to the size specified by size. The realloc functions intent is to leave the object in place if