From: Adrian Bunk <bunk@stusta.de>
To: Paulo Marques <pmarques@grupopie.com>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: RFC: turn kmalloc+memset(,0,) into kcalloc
Date: Thu, 7 Apr 2005 23:47:47 +0200 [thread overview]
Message-ID: <20050407214747.GD4325@stusta.de> (raw)
In-Reply-To: <4252BC37.8030306@grupopie.com>
On Tue, Apr 05, 2005 at 05:26:31PM +0100, Paulo Marques wrote:
>
> Hi,
Hi Paulo,
> I noticed there are a number of places in the kernel that do:
>
> ptr = kmalloc(n * size, ...)
> if (!ptr)
> goto out;
> memset(ptr, 0, n * size);
>
> It seems that these could be replaced by:
>
> ptr = kcalloc(n, size, ...)
> if (!ptr)
> goto out;
>
> saving a few bytes.
>...
> A quick (and lame) grep through the tree shows about 1200 of these
>cases. This means that about one quarter of all the kmallocs in the
>kernel are actually zeroed right after allocation.
>...
> pros:
> - smaller kernel image size
> - smaller (and more readable) source code
>...
Which is better readable depends on what you are used to.
> cons:
> - the NULL test is done twice
> - memset will not be optimized for constant sizes
>...
> Would this be a good thing to clean up, or isn't it worth the effort at all?
>...
You do plan to patch 1200 places in the kernel for this
micro-optimization?
This sounds like a really big overhead for a pretty small gain.
There are tasks of higher value that can be done.
E.g. read my "Stack usage tasks" email. The benefits would only be
present for people using GNU gcc 3.4 or SuSE gcc 3.3 on i386, but this
is a reasonable subset of the kernel users - and it brings them a
2% kernel size improvement.
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
next prev parent reply other threads:[~2005-04-07 21:49 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-05 16:26 RFC: turn kmalloc+memset(,0,) into kcalloc Paulo Marques
2005-04-05 18:00 ` Jörn Engel
2005-04-06 12:09 ` Denis Vlasenko
2005-04-05 18:54 ` Jesper Juhl
2005-04-05 19:20 ` Roland Dreier
2005-04-05 20:01 ` Jesper Juhl
2005-04-06 11:28 ` Jörn Engel
2005-04-06 12:15 ` Paulo Marques
2005-04-06 13:10 ` Pekka Enberg
2005-04-06 15:50 ` Paulo Marques
2005-04-07 23:54 ` Kyle Moffett
2005-04-09 2:11 ` Jesper Juhl
2005-04-07 21:47 ` Adrian Bunk [this message]
2005-04-08 12:38 ` Paulo Marques
2005-04-08 13:00 ` Adrian Bunk
2005-04-08 13:20 ` Jörn Engel
2005-04-08 13:29 ` Adrian Bunk
2005-04-08 16:24 ` Paulo Marques
2005-04-08 19:43 ` Adrian Bunk
2005-04-08 19:49 ` Randy.Dunlap
2005-04-08 13:00 ` stack checking (was: Re: RFC: turn kmalloc+memset(,0,) into kcalloc) Jörn Engel
2005-04-09 14:19 ` RFC: turn kmalloc+memset(,0,) into kcalloc Paul Jackson
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=20050407214747.GD4325@stusta.de \
--to=bunk@stusta.de \
--cc=linux-kernel@vger.kernel.org \
--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