[lkml]   [2005]   [Apr]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: RFC: turn kmalloc+memset(,0,) into kcalloc
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

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.



"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

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-04-07 23:53    [W:0.073 / U:0.652 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site