Re: no need to check for NULL before calling kfree() -fs/ext2/

From: Pekka J Enberg
Date: Tue Mar 29 2005 - 03:18:22 EST


Hi,

Jan Engelhardt writes:
"[...]In general, you should prefer to use actual profile feedback for this (`-fprofile-arcs'), as programmers are NOTORIOUSLY BAD AT PREDICTING how their programs actually perform." --gcc info pages.

Indeed.

I wrote:
> The optimization does not help if you are releasing actual memory.

Jan Engelhardt writes:
It does not turn the real case (releasing memory) worse, but just improves the unreal case (releasing NULL).

You don't know that until you profile! Please note that it _can_ turn the real case worse as the generated code will be bigger (assuming we inline kfree() to optimize the special case). To summarize:

(1) The optimization only helps when the passed pointer is NULL.
(2) Most of the time, kfree() _should_ be given a real pointer.
Anything else but sounds quite broken.
(3) We don't know if inlining kfree() hurts the common case.
(4) The cleanups Jesper and others are doing are to remove the
_redundant_ NULL checks (i.e. it is now checked twice).

Therefore please keep merging the cleanup patches and don't inline kfree() unless someone can show a _globally visible_ performance regression (i.e. p% slowdown in XYZ benchmark).

Pekka

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