3 simple steps to make booting/shutdown faster...

Arjan van de Ven arjan at infradead.org
Mon Feb 18 05:33:43 UTC 2008


On Sun, 17 Feb 2008 20:12:26 -0500
Behdad Esfahbod <behdad at behdad.org> wrote:

> On Sun, 2008-02-17 at 16:40 -0800, Andrew Farris wrote:
> > Behdad Esfahbod wrote:
> > >> On Sun, 17 Feb 2008 08:15:20 -0800, Arjan van de Ven wrote
> > >>
> > >>>> This should really be fixed in bash to short-circuit.
> > >>> well......... not sure it can be done in the bash language.
> > >>> (it may well guarantee that both get executed)
> > > 
> > > There's nothing to execute there.  All the expansions happen
> > > first, so if you have things like [ -n "$something" -a "`id`" =
> > > 0 ], the `id` call is made before passing control to "test".  The
> > > short-circuit would just happen in the evaluation in test.
> > > There's no user-visible difference there.
> > 
> > If thats the case shouldn't a statement like that always be nested
> > so that `id` is not called if it is not necessary, possibly saving
> > many disk accesses?  It would seem that using the more complex
> > constructs could be much slower if all the cases are evaluated
> > before testing any of them.
> 
> I believe that's correct.  The initial case that Arjan brought up
> though was [ -f somefile -a -f anotherfile ].  That doesn't have this
> problem.
> 
> /me is surprised that this kind of micro-optimizing has such drastic
> effects that Arjan has measured.

well looking to see if a file (that doesn't exist) exist is an expensive operation.
Sure, the kernel caches files that don't exist *after the first time you ask for them*.
Without that the kernel has to walk the entire directory on disk.

so an extra -f is.. not cheap.

> 


-- 
If you want to reach me at my work email, use arjan at linux.intel.com
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org




More information about the devel mailing list