Re: [RFC PATCH] type safe allocator

2007-08-02 Thread Christoph Lameter
On Thu, 2 Aug 2007, Miklos Szeredi wrote: > > If you define a new flag like GFP_ZERO_ATOMIC and GFP_ZERO_KERNEL you > > could do > > > > kalloc(struct, GFP_ZERO_KERNEL) > > > > instead of adding new variants? > > I don't really like this, introducing new gfp flags just makes > grepping

Re: [PATCH] type safe allocator

2007-08-02 Thread Miklos Szeredi
> > The linux kernel doesn't have a type safe object allocator a-la new() > > in C++ or g_new() in glib. > > > > Introduce two helpers for this purpose: > > > >alloc_struct(type, gfp_flags); > > > >zalloc_struct(type, gfp_flags); > > whimper. > > On a practical note, I'm still buried

Re: [PATCH] type safe allocator

2007-08-02 Thread Andrew Morton
On Thu, 02 Aug 2007 13:31:56 +0200 Miklos Szeredi <[EMAIL PROTECTED]> wrote: > The linux kernel doesn't have a type safe object allocator a-la new() > in C++ or g_new() in glib. > > Introduce two helpers for this purpose: > >alloc_struct(type, gfp_flags); > >zalloc_struct(type,

Re: [RFC PATCH] type safe allocator

2007-08-02 Thread Linus Torvalds
On Thu, 2 Aug 2007, Miklos Szeredi wrote: > > The number of variations can be reduced to just zeroing/nonzeroing, by > making the array length mandatory. That's what glib does in g_new(). Quite frankly, you don't need the zeroing. That's what __GFP_ZERO does in the flags. That said, I'm not

Re: [PATCH] type safe allocator

2007-08-02 Thread Jan Engelhardt
On Aug 2 2007 16:06, Bernd Petrovitsch wrote: >> thrice in some cases like alloc_struct(struct task_struct, GFP_KERNEL) > >Save the explicit "struct" and put it into the macro (and force people >to not use typedefs). > >#define alloc_struct(type, flags) ((type *)kmalloc(sizeof(struct type),

Re: [PATCH] type safe allocator

2007-08-02 Thread Bernd Petrovitsch
On Thu, 2007-08-02 at 15:47 +0200, Peter Zijlstra wrote: > On Thu, 2007-08-02 at 16:04 +0400, Alexey Dobriyan wrote: > > On 8/2/07, Miklos Szeredi <[EMAIL PROTECTED]> wrote: > > > The linux kernel doesn't have a type safe object allocator a-la new() > > > in C++ or g_new() in glib. > > > > > >

Re: [PATCH] type safe allocator

2007-08-02 Thread Miklos Szeredi
> >> On Aug 2 2007 16:04, Alexey Dobriyan wrote: > >> >On 8/2/07, Miklos Szeredi <[EMAIL PROTECTED]> wrote: > >> >> fooptr = kmalloc(sizeof(struct foo), ...); > >> > > >> >Key word is "traditional". Good traditional form which even half-competent > >> >C programmers immediately parse in retina.

Re: [PATCH] type safe allocator

2007-08-02 Thread Peter Zijlstra
On Thu, 2007-08-02 at 16:04 +0400, Alexey Dobriyan wrote: > On 8/2/07, Miklos Szeredi <[EMAIL PROTECTED]> wrote: > > The linux kernel doesn't have a type safe object allocator a-la new() > > in C++ or g_new() in glib. > > > > Introduce two helpers for this purpose: > > > >alloc_struct(type,

Re: [PATCH] type safe allocator

2007-08-02 Thread Jan Engelhardt
On Aug 2 2007 15:06, Miklos Szeredi wrote: >> On Aug 2 2007 16:04, Alexey Dobriyan wrote: >> >On 8/2/07, Miklos Szeredi <[EMAIL PROTECTED]> wrote: >> >> fooptr = kmalloc(sizeof(struct foo), ...); >> > >> >Key word is "traditional". Good traditional form which even half-competent >> >C

Re: [PATCH] type safe allocator

2007-08-02 Thread Miklos Szeredi
> On Aug 2 2007 16:04, Alexey Dobriyan wrote: > >On 8/2/07, Miklos Szeredi <[EMAIL PROTECTED]> wrote: > >> fooptr = kmalloc(sizeof(struct foo), ...); > > > >Key word is "traditional". Good traditional form which even half-competent > >C programmers immediately parse in retina. > > And being

Re: [RFC PATCH] type safe allocator

2007-08-02 Thread Miklos Szeredi
> Folks, this is serious. _We_ might be used to having in effect a C dialect > with extensions implemented by preprocessor. That's fine, but for a fresh > reader it becomes a problem; sure, they can dig in include/linux/*.h and > to some extent they clearly have to. However, it doesn't come for

Re: [PATCH] type safe allocator

2007-08-02 Thread Jan Engelhardt
On Aug 2 2007 16:04, Alexey Dobriyan wrote: >On 8/2/07, Miklos Szeredi <[EMAIL PROTECTED]> wrote: >> fooptr = kmalloc(sizeof(struct foo), ...); > >Key word is "traditional". Good traditional form which even half-competent >C programmers immediately parse in retina. And being aware of the

Re: [RFC PATCH] type safe allocator

2007-08-02 Thread Al Viro
On Thu, Aug 02, 2007 at 09:27:57AM +0200, Miklos Szeredi wrote: > > Quite frankly, I suspect you would be better off just instrumenting > > "sparse" instead, and matching up the size of the allocation with the type > > it gets assigned to. > > But that just can't be done, because kmalloc()

Re: [PATCH] type safe allocator

2007-08-02 Thread Alexey Dobriyan
On 8/2/07, Miklos Szeredi <[EMAIL PROTECTED]> wrote: > The linux kernel doesn't have a type safe object allocator a-la new() > in C++ or g_new() in glib. > > Introduce two helpers for this purpose: > >alloc_struct(type, gfp_flags); > >zalloc_struct(type, gfp_flags); ick. > These macros

[PATCH] type safe allocator

2007-08-02 Thread Miklos Szeredi
From: Miklos Szeredi <[EMAIL PROTECTED]> The linux kernel doesn't have a type safe object allocator a-la new() in C++ or g_new() in glib. Introduce two helpers for this purpose: alloc_struct(type, gfp_flags); zalloc_struct(type, gfp_flags); These macros take a type name (usually a

Re: [RFC PATCH] type safe allocator

2007-08-02 Thread Miklos Szeredi
> > > > +/** > > + * k_new - allocate given type object > > + * @type: the type of the object to allocate > > + * @flags: the type of memory to allocate. > > + */ > > +#define k_new(type, flags) ((type *) kmalloc(sizeof(type), flags)) > > What others already said, plus: > > kmalloc()'ing

Re: [RFC PATCH] type safe allocator

2007-08-02 Thread Miklos Szeredi
> > I wonder why we don't have type safe object allocators a-la new() in > > C++ or g_new() in glib? > > > > fooptr = k_new(struct foo, GFP_KERNEL); > > > > is nicer and more descriptive than > > > > fooptr = kmalloc(sizeof(*fooptr), GFP_KERNEL); > > > > and more safe than > > > >

Re: [RFC PATCH] type safe allocator

2007-08-02 Thread Miklos Szeredi
> > > > I wonder why we don't have type safe object allocators a-la new() in > > C++ or g_new() in glib? > > > > fooptr = k_new(struct foo, GFP_KERNEL); > > I would object to this if only because of the horrible name. > > C++ is not a good language to take ideas from, and "new()" was not it's

Re: [RFC PATCH] type safe allocator

2007-08-02 Thread Satyam Sharma
Hi Miklos, On Wed, 1 Aug 2007, Miklos Szeredi wrote: > I wonder why we don't have type safe object allocators a-la new() in > C++ or g_new() in glib? > > fooptr = k_new(struct foo, GFP_KERNEL); > > is nicer and more descriptive than > > fooptr = kmalloc(sizeof(*fooptr), GFP_KERNEL); > >

Re: [RFC PATCH] type safe allocator

2007-08-02 Thread Satyam Sharma
Hi Miklos, On Wed, 1 Aug 2007, Miklos Szeredi wrote: I wonder why we don't have type safe object allocators a-la new() in C++ or g_new() in glib? fooptr = k_new(struct foo, GFP_KERNEL); is nicer and more descriptive than fooptr = kmalloc(sizeof(*fooptr), GFP_KERNEL); and more

Re: [RFC PATCH] type safe allocator

2007-08-02 Thread Miklos Szeredi
I wonder why we don't have type safe object allocators a-la new() in C++ or g_new() in glib? fooptr = k_new(struct foo, GFP_KERNEL); I would object to this if only because of the horrible name. C++ is not a good language to take ideas from, and new() was not it's best feature

Re: [RFC PATCH] type safe allocator

2007-08-02 Thread Miklos Szeredi
I wonder why we don't have type safe object allocators a-la new() in C++ or g_new() in glib? fooptr = k_new(struct foo, GFP_KERNEL); is nicer and more descriptive than fooptr = kmalloc(sizeof(*fooptr), GFP_KERNEL); and more safe than fooptr =

Re: [RFC PATCH] type safe allocator

2007-08-02 Thread Miklos Szeredi
+/** + * k_new - allocate given type object + * @type: the type of the object to allocate + * @flags: the type of memory to allocate. + */ +#define k_new(type, flags) ((type *) kmalloc(sizeof(type), flags)) What others already said, plus: kmalloc()'ing sizeof(struct foo) is

[PATCH] type safe allocator

2007-08-02 Thread Miklos Szeredi
From: Miklos Szeredi [EMAIL PROTECTED] The linux kernel doesn't have a type safe object allocator a-la new() in C++ or g_new() in glib. Introduce two helpers for this purpose: alloc_struct(type, gfp_flags); zalloc_struct(type, gfp_flags); These macros take a type name (usually a 'struct

Re: [PATCH] type safe allocator

2007-08-02 Thread Alexey Dobriyan
On 8/2/07, Miklos Szeredi [EMAIL PROTECTED] wrote: The linux kernel doesn't have a type safe object allocator a-la new() in C++ or g_new() in glib. Introduce two helpers for this purpose: alloc_struct(type, gfp_flags); zalloc_struct(type, gfp_flags); ick. These macros take a type

Re: [PATCH] type safe allocator

2007-08-02 Thread Jan Engelhardt
On Aug 2 2007 16:04, Alexey Dobriyan wrote: On 8/2/07, Miklos Szeredi [EMAIL PROTECTED] wrote: fooptr = kmalloc(sizeof(struct foo), ...); Key word is traditional. Good traditional form which even half-competent C programmers immediately parse in retina. And being aware of the potential

Re: [RFC PATCH] type safe allocator

2007-08-02 Thread Al Viro
On Thu, Aug 02, 2007 at 09:27:57AM +0200, Miklos Szeredi wrote: Quite frankly, I suspect you would be better off just instrumenting sparse instead, and matching up the size of the allocation with the type it gets assigned to. But that just can't be done, because kmalloc() doesn't tell

Re: [PATCH] type safe allocator

2007-08-02 Thread Miklos Szeredi
On Aug 2 2007 16:04, Alexey Dobriyan wrote: On 8/2/07, Miklos Szeredi [EMAIL PROTECTED] wrote: fooptr = kmalloc(sizeof(struct foo), ...); Key word is traditional. Good traditional form which even half-competent C programmers immediately parse in retina. And being aware of the

Re: [PATCH] type safe allocator

2007-08-02 Thread Jan Engelhardt
On Aug 2 2007 15:06, Miklos Szeredi wrote: On Aug 2 2007 16:04, Alexey Dobriyan wrote: On 8/2/07, Miklos Szeredi [EMAIL PROTECTED] wrote: fooptr = kmalloc(sizeof(struct foo), ...); Key word is traditional. Good traditional form which even half-competent C programmers immediately parse

Re: [RFC PATCH] type safe allocator

2007-08-02 Thread Miklos Szeredi
Folks, this is serious. _We_ might be used to having in effect a C dialect with extensions implemented by preprocessor. That's fine, but for a fresh reader it becomes a problem; sure, they can dig in include/linux/*.h and to some extent they clearly have to. However, it doesn't come for

Re: [PATCH] type safe allocator

2007-08-02 Thread Miklos Szeredi
On Aug 2 2007 16:04, Alexey Dobriyan wrote: On 8/2/07, Miklos Szeredi [EMAIL PROTECTED] wrote: fooptr = kmalloc(sizeof(struct foo), ...); Key word is traditional. Good traditional form which even half-competent C programmers immediately parse in retina. And being aware of the

Re: [PATCH] type safe allocator

2007-08-02 Thread Peter Zijlstra
On Thu, 2007-08-02 at 16:04 +0400, Alexey Dobriyan wrote: On 8/2/07, Miklos Szeredi [EMAIL PROTECTED] wrote: The linux kernel doesn't have a type safe object allocator a-la new() in C++ or g_new() in glib. Introduce two helpers for this purpose: alloc_struct(type, gfp_flags);

Re: [PATCH] type safe allocator

2007-08-02 Thread Jan Engelhardt
On Aug 2 2007 16:06, Bernd Petrovitsch wrote: thrice in some cases like alloc_struct(struct task_struct, GFP_KERNEL) Save the explicit struct and put it into the macro (and force people to not use typedefs). #define alloc_struct(type, flags) ((type *)kmalloc(sizeof(struct type), (flags)))

Re: [PATCH] type safe allocator

2007-08-02 Thread Bernd Petrovitsch
On Thu, 2007-08-02 at 15:47 +0200, Peter Zijlstra wrote: On Thu, 2007-08-02 at 16:04 +0400, Alexey Dobriyan wrote: On 8/2/07, Miklos Szeredi [EMAIL PROTECTED] wrote: The linux kernel doesn't have a type safe object allocator a-la new() in C++ or g_new() in glib. Introduce two

Re: [RFC PATCH] type safe allocator

2007-08-02 Thread Linus Torvalds
On Thu, 2 Aug 2007, Miklos Szeredi wrote: The number of variations can be reduced to just zeroing/nonzeroing, by making the array length mandatory. That's what glib does in g_new(). Quite frankly, you don't need the zeroing. That's what __GFP_ZERO does in the flags. That said, I'm not at

Re: [PATCH] type safe allocator

2007-08-02 Thread Andrew Morton
On Thu, 02 Aug 2007 13:31:56 +0200 Miklos Szeredi [EMAIL PROTECTED] wrote: The linux kernel doesn't have a type safe object allocator a-la new() in C++ or g_new() in glib. Introduce two helpers for this purpose: alloc_struct(type, gfp_flags); zalloc_struct(type, gfp_flags);

Re: [PATCH] type safe allocator

2007-08-02 Thread Miklos Szeredi
The linux kernel doesn't have a type safe object allocator a-la new() in C++ or g_new() in glib. Introduce two helpers for this purpose: alloc_struct(type, gfp_flags); zalloc_struct(type, gfp_flags); whimper. On a practical note, I'm still buried in

Re: [RFC PATCH] type safe allocator

2007-08-02 Thread Christoph Lameter
On Thu, 2 Aug 2007, Miklos Szeredi wrote: If you define a new flag like GFP_ZERO_ATOMIC and GFP_ZERO_KERNEL you could do kalloc(struct, GFP_ZERO_KERNEL) instead of adding new variants? I don't really like this, introducing new gfp flags just makes grepping harder. The

Re: [RFC PATCH] type safe allocator

2007-08-01 Thread Christoph Lameter
On Wed, 1 Aug 2007, Miklos Szeredi wrote: > I wonder why we don't have type safe object allocators a-la new() in > C++ or g_new() in glib? > > fooptr = k_new(struct foo, GFP_KERNEL); > > is nicer and more descriptive than > > fooptr = kmalloc(sizeof(*fooptr), GFP_KERNEL); > > and more

Re: [RFC PATCH] type safe allocator

2007-08-01 Thread Linus Torvalds
On Wed, 1 Aug 2007, Miklos Szeredi wrote: > > I wonder why we don't have type safe object allocators a-la new() in > C++ or g_new() in glib? > > fooptr = k_new(struct foo, GFP_KERNEL); I would object to this if only because of the horrible name. C++ is not a good language to take ideas

Re: [RFC PATCH] type safe allocator

2007-08-01 Thread Miklos Szeredi
> >> > > >> > #define k_new(type, flags) ((type *) kmalloc(sizeof(type), flags)) > >> > >> The cast doesn't make it more safe in any way > > > >I does, since a warning will be issued, if the type of the assigned > >pointer doesn't match the requested allocation. > > > >And yes, warnings are

Re: [RFC PATCH] type safe allocator

2007-08-01 Thread Jan Engelhardt
On Aug 1 2007 12:45, Miklos Szeredi wrote: >> > >> > #define k_new(type, flags) ((type *) kmalloc(sizeof(type), flags)) >> >> The cast doesn't make it more safe in any way > >I does, since a warning will be issued, if the type of the assigned >pointer doesn't match the requested allocation. >

Re: [RFC PATCH] type safe allocator

2007-08-01 Thread Miklos Szeredi
> > > > #define k_new(type, flags) ((type *) kmalloc(sizeof(type), flags)) > > The cast doesn't make it more safe in any way I does, since a warning will be issued, if the type of the assigned pointer doesn't match the requested allocation. And yes, warnings are _very_ useful in C for

Re: [RFC PATCH] type safe allocator

2007-08-01 Thread Andi Kleen
Miklos Szeredi <[EMAIL PROTECTED]> writes: > > #define k_new(type, flags) ((type *) kmalloc(sizeof(type), flags)) The cast doesn't make it more safe in any way (at least as long as you don't care about portability to C++; the kernel doesn't) -Andi - To unsubscribe from this list: send the line

Re: [RFC PATCH] type safe allocator

2007-08-01 Thread Miklos Szeredi
> > I wonder why we don't have type safe object allocators a-la new() in > > C++ or g_new() in glib? > > > > fooptr = k_new(struct foo, GFP_KERNEL); > > > > is nicer and more descriptive than > > > > fooptr = kmalloc(sizeof(*fooptr), GFP_KERNEL); > > > > and more safe than > > > >

Re: [RFC PATCH] type safe allocator

2007-08-01 Thread Andi Kleen
Miklos Szeredi <[EMAIL PROTECTED]> writes: > I wonder why we don't have type safe object allocators a-la new() in > C++ or g_new() in glib? > > fooptr = k_new(struct foo, GFP_KERNEL); > > is nicer and more descriptive than > > fooptr = kmalloc(sizeof(*fooptr), GFP_KERNEL); > > and more

Re: [RFC PATCH] type safe allocator

2007-08-01 Thread Miklos Szeredi
> > I wonder why we don't have type safe object allocators a-la new() in > > C++ or g_new() in glib? > > > > fooptr = k_new(struct foo, GFP_KERNEL); > > > > is nicer and more descriptive than > > > > fooptr = kmalloc(sizeof(*fooptr), GFP_KERNEL); > >... > > But it's much more likely to

Re: [RFC PATCH] type safe allocator

2007-08-01 Thread Adrian Bunk
On Wed, Aug 01, 2007 at 11:06:46AM +0200, Miklos Szeredi wrote: > I wonder why we don't have type safe object allocators a-la new() in > C++ or g_new() in glib? > > fooptr = k_new(struct foo, GFP_KERNEL); > > is nicer and more descriptive than > > fooptr = kmalloc(sizeof(*fooptr),

[RFC PATCH] type safe allocator

2007-08-01 Thread Miklos Szeredi
I wonder why we don't have type safe object allocators a-la new() in C++ or g_new() in glib? fooptr = k_new(struct foo, GFP_KERNEL); is nicer and more descriptive than fooptr = kmalloc(sizeof(*fooptr), GFP_KERNEL); and more safe than fooptr = kmalloc(sizeof(struct foo), GFP_KERNEL);

Re: [RFC PATCH] type safe allocator

2007-08-01 Thread Andi Kleen
Miklos Szeredi [EMAIL PROTECTED] writes: I wonder why we don't have type safe object allocators a-la new() in C++ or g_new() in glib? fooptr = k_new(struct foo, GFP_KERNEL); is nicer and more descriptive than fooptr = kmalloc(sizeof(*fooptr), GFP_KERNEL); and more safe than

Re: [RFC PATCH] type safe allocator

2007-08-01 Thread Miklos Szeredi
I wonder why we don't have type safe object allocators a-la new() in C++ or g_new() in glib? fooptr = k_new(struct foo, GFP_KERNEL); is nicer and more descriptive than fooptr = kmalloc(sizeof(*fooptr), GFP_KERNEL); ... But it's much more likely to break when someone

[RFC PATCH] type safe allocator

2007-08-01 Thread Miklos Szeredi
I wonder why we don't have type safe object allocators a-la new() in C++ or g_new() in glib? fooptr = k_new(struct foo, GFP_KERNEL); is nicer and more descriptive than fooptr = kmalloc(sizeof(*fooptr), GFP_KERNEL); and more safe than fooptr = kmalloc(sizeof(struct foo), GFP_KERNEL);

Re: [RFC PATCH] type safe allocator

2007-08-01 Thread Adrian Bunk
On Wed, Aug 01, 2007 at 11:06:46AM +0200, Miklos Szeredi wrote: I wonder why we don't have type safe object allocators a-la new() in C++ or g_new() in glib? fooptr = k_new(struct foo, GFP_KERNEL); is nicer and more descriptive than fooptr = kmalloc(sizeof(*fooptr), GFP_KERNEL); ...

Re: [RFC PATCH] type safe allocator

2007-08-01 Thread Miklos Szeredi
I wonder why we don't have type safe object allocators a-la new() in C++ or g_new() in glib? fooptr = k_new(struct foo, GFP_KERNEL); is nicer and more descriptive than fooptr = kmalloc(sizeof(*fooptr), GFP_KERNEL); and more safe than fooptr =

Re: [RFC PATCH] type safe allocator

2007-08-01 Thread Miklos Szeredi
#define k_new(type, flags) ((type *) kmalloc(sizeof(type), flags)) The cast doesn't make it more safe in any way I does, since a warning will be issued, if the type of the assigned pointer doesn't match the requested allocation. And yes, warnings are _very_ useful in C for enforcing type

Re: [RFC PATCH] type safe allocator

2007-08-01 Thread Andi Kleen
Miklos Szeredi [EMAIL PROTECTED] writes: #define k_new(type, flags) ((type *) kmalloc(sizeof(type), flags)) The cast doesn't make it more safe in any way (at least as long as you don't care about portability to C++; the kernel doesn't) -Andi - To unsubscribe from this list: send the line

Re: [RFC PATCH] type safe allocator

2007-08-01 Thread Jan Engelhardt
On Aug 1 2007 12:45, Miklos Szeredi wrote: #define k_new(type, flags) ((type *) kmalloc(sizeof(type), flags)) The cast doesn't make it more safe in any way I does, since a warning will be issued, if the type of the assigned pointer doesn't match the requested allocation. And yes,

Re: [RFC PATCH] type safe allocator

2007-08-01 Thread Miklos Szeredi
#define k_new(type, flags) ((type *) kmalloc(sizeof(type), flags)) The cast doesn't make it more safe in any way I does, since a warning will be issued, if the type of the assigned pointer doesn't match the requested allocation. And yes, warnings are _very_ useful in C for

Re: [RFC PATCH] type safe allocator

2007-08-01 Thread Linus Torvalds
On Wed, 1 Aug 2007, Miklos Szeredi wrote: I wonder why we don't have type safe object allocators a-la new() in C++ or g_new() in glib? fooptr = k_new(struct foo, GFP_KERNEL); I would object to this if only because of the horrible name. C++ is not a good language to take ideas from, and

Re: [RFC PATCH] type safe allocator

2007-08-01 Thread Christoph Lameter
On Wed, 1 Aug 2007, Miklos Szeredi wrote: I wonder why we don't have type safe object allocators a-la new() in C++ or g_new() in glib? fooptr = k_new(struct foo, GFP_KERNEL); is nicer and more descriptive than fooptr = kmalloc(sizeof(*fooptr), GFP_KERNEL); and more safe than