[patch-2.3.40-pre6] kzalloc() (ala kmem_zalloc() of SVR4)

Ingo Molnar mingo en chiara.csoma.elte.hu
Sab Ene 22 00:09:28 CST 2000


On Thu, 20 Jan 2000, Tigran Aivazian wrote:

> a common code sequence of calling kmalloc() and then memset(p,0,size) can
> be optimized into a single exported interface called kzalloc() like it is
> done on other systems (kmem_zalloc()). This is a simple and harmless
> optimization - please consider it:

i'd suggest to make it an inline function, because affected code often (in
most cases) goes like this:

	x = kmalloc(size);
	memset(x,0,size);
	x->a = 1;
	x->b = 2;
	x->c = 3;

which then again is (free to be) optimized by GCC to skip the zeroing for
all initialized variables. Or something like:

	if (size > TRESHOLD)
		__kzalloc(size);
	else {
		x = kmalloc(size);
		memset(size);
	}

because smaller structures are more likely to be initialized right after
allocation. One of the branches is always optimized away at compile time.

-- mingo


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo en vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



Más información sobre la lista de distribución Ayuda