Re: small patch to buffer.c (2.0.x, stop wasting cycles).

Gordon Oliver (
Fri, 4 Apr 1997 15:58:40 -0400 (CST)

...Ingo Molnar says...:
> On Fri, 4 Apr 1997, Gordon Oliver wrote:
> > This little patch takes the cli()/restore_flags() out of the loop.
> > --- fs/buffer.c.original Tue Apr 1 21:15:32 1997
> > +++ fs/buffer.c Tue Apr 1 21:20:52 1997
> > @@ -1023,21 +1023,29 @@
> > * to be IRQ-safe here (but note that interrupts only _add_ to the
> > * reuse_list, never take away. So we don't need to worry about the
> > * reuse_list magically emptying).
> > + *
> > + * Changed the code to copy out the list at the beginning instead of
> > + * locking it for every entry. This could be made into a while loop, but
> > + * that doesn't seem to have much purpose, since this code is called
> > + * every time we want a buffer.
> is the buffer-head freelist modified from interrupt handlers? If yes the
> it's unsafe to call put_unused_buffer_head with irqs on. If no then no
> need to cli at all.

as far as I can tell put_unused_buffer head is never called from an
interrupt (I doubt it is, as the original code also had an unprotected
call, and the comments claim not). If it is, the patch doesn't fix the bug
in the original code...

Interrupts do, however, modify the reuse_list, thus the cli()/restore_flags()
to protect the access to reuse_list. (unlock_buffer is called from various
interrupts, and will add data to reuse_list)

hmm... food for thought... perhaps we should have an ASSERT macro that can
be compiled in as a panic, and everywhere that you can't _possibly_ be
called from an interrupt, add an ASSERT that says so... (yes, panics are
a bit painful, but less so than random corruption).