From: Miklos Szeredi <miklos@szeredi.hu>
To: torvalds@linux-foundation.org
Cc: miklos@szeredi.hu, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, akpm@linux-foundation.org
Subject: Re: [RFC PATCH] type safe allocator
Date: Thu, 02 Aug 2007 09:27:57 +0200 [thread overview]
Message-ID: <E1IGV6D-0000rM-00@dorka.pomaz.szeredi.hu> (raw)
In-Reply-To: <alpine.LFD.0.999.0708012051100.3582@woody.linux-foundation.org> (message from Linus Torvalds on Wed, 1 Aug 2007 20:56:13 -0700 (PDT))
> >
> > 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 to begin with. "k_new()" is just disgusting.
>
> I'd call it something like "alloc_struct()" instead, which tells you
> exactly what it's all about. Especially since we try to avoid typedefs in
> the kernel, and as a result, it's basically almost always a struct thing.
Yeah, I'm not strongly attached to the "new" name, although I got used
to it in glib. The glib API is broken in lots of ways, but g_new()
and friends are nice and useful.
> That said, I'm not at all sure it's worth it. Especially not with all the
> various variations on a theme (zeroed, arrays, etc etc).
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, 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 us the
_intent_ of the allocation. The allocation could be for an array, or
for a struct with a variable length string at the end, or it could be
multiple structs concatenated. We have all sorts of weird stuff in
there that sparse would not be able to handle.
That's why alloc_struct() is better: it describes the intention exacly
"allocate the given object and return an appropriately typed pointer".
While kmalloc() just says "allocate a given sized memory chunk and
return an untyped pointer".
Miklos
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2007-08-02 7:27 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-01 9:06 Miklos Szeredi
2007-08-01 9:29 ` Adrian Bunk
2007-08-01 9:41 ` Miklos Szeredi
2007-08-01 10:44 ` Andi Kleen
2007-08-01 9:57 ` Miklos Szeredi
2007-08-01 11:34 ` Andi Kleen
2007-08-01 10:45 ` Miklos Szeredi
2007-08-01 11:44 ` Jan Engelhardt
2007-08-01 11:56 ` Miklos Szeredi
2007-08-02 3:56 ` Linus Torvalds
2007-08-02 7:27 ` Miklos Szeredi [this message]
2007-08-02 12:05 ` Al Viro
2007-08-02 13:05 ` Miklos Szeredi
2007-08-02 17:23 ` Linus Torvalds
2007-08-02 5:33 ` Christoph Lameter
2007-08-02 7:38 ` Miklos Szeredi
2007-08-02 19:16 ` Christoph Lameter
2007-08-02 7:37 ` Satyam Sharma
2007-08-02 7:40 ` Miklos Szeredi
2007-08-02 11:31 ` [PATCH] " Miklos Szeredi, Miklos Szeredi
2007-08-02 12:04 ` Alexey Dobriyan
2007-08-02 12:24 ` Jan Engelhardt
2007-08-02 13:06 ` Miklos Szeredi
2007-08-02 13:35 ` Jan Engelhardt
2007-08-02 13:49 ` Miklos Szeredi
2007-08-02 13:47 ` Peter Zijlstra
2007-08-02 14:06 ` Bernd Petrovitsch
2007-08-02 14:08 ` Jan Engelhardt
2007-08-02 18:36 ` Andrew Morton
2007-08-02 18:48 ` Miklos Szeredi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1IGV6D-0000rM-00@dorka.pomaz.szeredi.hu \
--to=miklos@szeredi.hu \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox