Reply to post: Re: Goto Jail, go directly to jail.

'Disappearing' data under ZFS on Linux sparks small swift tweak

Lee D Silver badge

Re: Goto Jail, go directly to jail.

If you think that goto is problematic, never look at the kernel source code.

Goto on its on isn't dangerous, it's ill-considered use of it that is. Though in theory, everything in a nice loop looks pretty, it has a performance hit that goto doesn't. Underneath the hood, goto is literally just a jmp instruction. But a loop has all kinds of setups, stack motions and side-effects.

Especially in any kind of error handler, you don't want to be rolling around inside a loop that's already served it's purpose, you want to get the hell out of dodge.

And if we're talking performance-critical filesystem code that will impact upon everything from logging to every process on the system to potential complete kernel failure in the case of a mistake, a goto might well be the best way to handle the practicalities. Don't forget, that error-handling code might be operating under very extreme circumstances, with critical data, with minimal resources to attempt to recover or at least record what happened without damaging the stack, etc. In that case, you really don't want to be faffing about when goto is the answer.

At last count, there were over 10,000 goto's inside the Linux kernel. To replace them all with further-indented, re-ordered code without hitting the same kinds of non-damaging "emergency" performance? That's just silly, because the people that put them there aren't exactly idiots.

People who state absolutes, however, are - without exception - idiots...

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon

Biting the hand that feeds IT © 1998–2019