Re: oom() _still_ killing init

Horst von Brand (vonbrand@sleipnir.valparaiso.cl)
Sat, 19 Jun 1999 09:35:43 -0400


Chuck Lever <cel@monkey.org> said:

[...]

> i've found that when using egcs or gcc with -O2, a "goto" will generate
> the same assembly as the same logic expressed with structured programming,
> *in* *the* *general* *case*. something like find_buffer() looks like a
> complete mess, but it does generate better assembly than using idiomatic C
> programming style. but simple cases like this:
>
> int function(int a)
> {
> if (a > 3)
> goto out;
>
> a = a + 7
> do_work;
> out:
> return a;
> }
>
> will generate exactly the same assembly as this:
>
> int function(int a)
> {
> if (a <= 3) {
> a = a + 7;
> do_work;
> }
> return a;
> }
>
> if compiled with -O2. building the kernel with -O2 means we can probably
> lose many "gotos" without losing any fast path performance. if the kernel
> were compiled without optimization, the gotos would definitely win.

This case is trivial, and both do exactly the same thing if you look at how
your if must be translated into assembly. What the kernel mostly does is:

int f()
{
err = 0;
do_something_hairy;

if(err = broken())
goto out_broken;

maybe_this_works;
if(it worked) {
err = whatever;
goto done;
}

some_more_hair;
if(strange_stuff) {
handle_it;
if(err = won_do())
goto out_broken;
do_more_stuff;
}
try_something_else;

broken:
do_cleanup;
done:
return err;
}

> another case where goto is superfluous is this:

Also obviously the same even for naive code generation.

> the C compiler is smart enough to convert the first "return an error"
> into a branch to the end of function.

egcs is certainly a lot smarter than gcc-2.7.2, but
a) Rewriting all that code means it has to be retested too. Lots of work
for _very_ little gain.
b) Linus won't go for egcs, so the kernel has to be written with gcc-2.7.2
as principle target

-- 
Horst von Brand                             vonbrand@sleipnir.valparaiso.cl
Casilla 9G, Viņa del Mar, Chile                               +56 32 672616

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