From: Takashi Iwai <tiwai@suse.de>
To: Adrian Bunk <bunk@stusta.de>
Cc: Pekka J Enberg <penberg@cs.Helsinki.FI>,
Andrew Morton <akpm@osdl.org>,
linux-kernel@vger.kernel.org, pmarques@grupopie.com
Subject: Re: [PATCH] kernel: use kcalloc instead kmalloc/memset
Date: Mon, 08 Aug 2005 12:11:21 +0200 [thread overview]
Message-ID: <s5hacjs68mu.wl%tiwai@suse.de> (raw)
In-Reply-To: <20050806150940.GT4029@stusta.de>
At Sat, 6 Aug 2005 17:09:40 +0200,
Adrian Bunk wrote:
>
> On Fri, Aug 05, 2005 at 09:52:32AM +0300, Pekka J Enberg wrote:
> >...
> > --- 2.6.orig/mm/slab.c
> > +++ 2.6/mm/slab.c
> > @@ -2555,6 +2555,20 @@ void kmem_cache_free(kmem_cache_t *cache
> > EXPORT_SYMBOL(kmem_cache_free);
> >
> > /**
> > + * kzalloc - allocate memory. The memory is set to zero.
> > + * @size: how many bytes of memory are required.
> > + * @flags: the type of memory to allocate.
> > + */
> > +void *kzalloc(size_t size, unsigned int __nocast flags)
> > +{
> > + void *ret = kmalloc(size, flags);
> > + if (ret)
> > + memset(ret, 0, size);
> > + return ret;
> > +}
> > +EXPORT_SYMBOL(kzalloc);
> > +
> > +/**
> > * kcalloc - allocate memory for an array. The memory is set to zero.
> > * @n: number of elements.
> > * @size: element size.
> > @@ -2567,10 +2581,7 @@ void *kcalloc(size_t n, size_t size, uns
> > if (n != 0 && size > INT_MAX / n)
> > return ret;
> >
> > - ret = kmalloc(n * size, flags);
> > - if (ret)
> > - memset(ret, 0, n * size);
> > - return ret;
> > + return kzalloc(n * size, flags);
> > }
> > EXPORT_SYMBOL(kcalloc);
>
>
> Looking at how few is left from kcalloc, can't we make it a
> "static inline" function in slab.h?
>
> This would optimize nicely for all of the users where the first or even
> the first two parameters are constant at compile-time and shouldn't do
> much harm for the other users.
>
> As a side effect, the difference between kcalloc(1, ...) and kzalloc()
> would become a coding style question without any effect on the generated
> code.
How about to use __builtin_constant_p() like kmalloc?
The code readability would be worsen, though...
Takashi
next prev parent reply other threads:[~2005-08-08 10:11 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-05 5:29 [PATCH] kernel: use kcalloc instead kmalloc/memset Pekka Enberg
2005-08-05 5:38 ` Andrew Morton
2005-08-05 6:30 ` Pekka J Enberg
2005-08-05 6:36 ` Andrew Morton
2005-08-05 6:52 ` Pekka J Enberg
2005-08-06 15:09 ` Adrian Bunk
2005-08-08 10:11 ` Takashi Iwai [this message]
2005-08-08 21:05 ` Adrian Bunk
2005-08-09 10:09 ` Takashi Iwai
2005-08-05 9:37 ` Roman Zippel
2005-08-05 9:46 ` Arjan van de Ven
2005-08-05 9:59 ` Pekka J Enberg
2005-08-05 10:07 ` [PATCH] " Roman Zippel
2005-08-05 10:13 ` Arjan van de Ven
2005-08-05 10:32 ` Roman Zippel
2005-08-05 10:38 ` Arjan van de Ven
2005-08-05 10:56 ` Roman Zippel
2005-08-05 11:12 ` Arjan van de Ven
2005-08-06 0:40 ` Roman Zippel
2005-08-06 13:09 ` Pekka Enberg
2005-08-08 6:25 ` Jan Engelhardt
2005-08-05 17:49 ` Stephen Pollei
2005-08-05 18:16 ` Christoph Lameter
2005-08-05 18:39 ` Stephen Pollei
2005-08-05 10:15 ` Pekka J Enberg
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=s5hacjs68mu.wl%tiwai@suse.de \
--to=tiwai@suse.de \
--cc=akpm@osdl.org \
--cc=bunk@stusta.de \
--cc=linux-kernel@vger.kernel.org \
--cc=penberg@cs.Helsinki.FI \
--cc=pmarques@grupopie.com \
/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