performance improvement in fs/buffer.c (2.0.x) patch

Gordon Oliver (gordo@lazos.cl)
Tue, 1 Apr 1997 22:26:05 -0400 (CST)


The code in buffer.c has an ugly use of cli/restore_flags that gets fixed
here. Instead of clearing interrupts to take each element out of a list,
I made it swap the list into private space, and then empty the now private
list without protection.

It is running now under 2.0.0 on my computer, but the relevent code is
unchanged in 2.0.27, so the patch should apply cleanly. In a wildly
inacurate test of a heavily write-dependent application, the system
time improved by an apparent 5-10%.

comments are appreciated.

--- 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.
*/
static inline void recover_reusable_buffer_heads(void)
{
if (reuse_list) {
+ struct buffer_head *head;
struct buffer_head *bh;
unsigned long flags;

save_flags(flags);
- do {
- cli();
- bh = reuse_list;
- reuse_list = bh->b_next_free;
- restore_flags(flags);
+ cli();
+ head = reuse_list;
+ reuse_list = NULL;
+ restore_flags(flags);
+ while (head) {
+ bh = head;
+ head = bh->b_next_free;
put_unused_buffer_head(bh);
- } while (reuse_list);
+ }
}
}