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: Fri, 8 Apr 2005 15:00:08 +0200 [thread overview]
Message-ID: <20050408130008.GA6653@stusta.de> (raw)
In-Reply-To: <42567B3E.8010403@grupopie.com>
On Fri, Apr 08, 2005 at 01:38:22PM +0100, Paulo Marques wrote:
> Adrian Bunk wrote:
> >On Tue, Apr 05, 2005 at 05:26:31PM +0100, Paulo Marques wrote:
>
> Hi Adrian,
Hi Paolo,
> >>[...]
> >>pros:
> >> - smaller kernel image size
> >> - smaller (and more readable) source code
> >
> >Which is better readable depends on what you are used to.
>
> That's true to some degree, but look at code like this (in
> drivers/usb/input/hid-core.c):
>
> > if (!(field = kmalloc(sizeof(struct hid_field) + usages *
> > sizeof(struct hid_usage)
> > + values * sizeof(unsigned), GFP_KERNEL))) return NULL;
> >
> > memset(field, 0, sizeof(struct hid_field) + usages * sizeof(struct
> > hid_usage)
> > + values * sizeof(unsigned));
>
> and compare to this:
>
> > field = kzalloc(sizeof(struct hid_field) + usages * sizeof(struct
> > hid_usage)
> > + values * sizeof(unsigned), GFP_KERNEL);
> > if (!field)
> > return NULL;
>
> In the first case you have to read carefully to make sure that the size
> argument in both the kmalloc and the memset are the same. Even more, if
> the size needs to be updated to include something more, a mistake can be
> made by inserting the extra size just in the kmalloc call. Also, you are
> assuming that the compiler is smart enough to notice that the two
> expressions are the same and cache the result, but this is probably true
> for gcc, anyway.
>
> I think most will agree that the second piece of code is more "readable".
In this case yes (but it could still use the normal kcalloc).
>...
> >There are tasks of higher value that can be done.
>
> I couldn't agree more :)
>
> >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.
>
> I've read that thread, but it seems that it is at a dead end right now,
> since we don't have a good tool to find out which functions are abusing
> the stack with unit-at-a-time.
>
> Is there some way to even limit the search, like using a stack usage log
> from a compilation without unit-at-a-time, and going over the hotspots
> to check for problems?
>
> If we can get a list, even if it contains a lot of false positives, I
> would more than happy to help out...
Joerg's list of recursions should be valid independent of the kernel
version. Fixing any real stack problems [1] that might be in this list
is a valuable task.
And "make checkstack" in a kernel compiled with unit-at-a-time lists
several possible problems at the top.
> Paulo Marques
cu
Adrian
[1] there are cases in this list that aren't a problem e.g. because of
an obviously limited recursion
--
"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-08 13:10 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
2005-04-08 12:38 ` Paulo Marques
2005-04-08 13:00 ` Adrian Bunk [this message]
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=20050408130008.GA6653@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