Re: bh_lru_install
From: David S. Miller
Date: Tue Jul 27 2004 - 19:18:43 EST
On Tue, 27 Jul 2004 16:06:17 -0700
Andrew Morton <akpm@xxxxxxxx> wrote:
> > It shouldn't be too hard to make the code just work without
> > an on-stack copy, shuffling the lru->bh[] array entries
> > directly.
>
> Yup, that plus making it a ringbuffer maybe.
It seems implementable using two roving indexes, one for
reading and one for writing. So it's just like the existing
code sans the on-stack+memcpy stuff :-)
Do you see any logic errors in this new code below?
static void bh_lru_install(struct buffer_head *bh)
{
struct buffer_head *e = NULL;
struct bh_lru *lru;
check_irqs_on();
bh_lru_lock();
lru = &__get_cpu_var(bh_lrus);
if ((e = lru->bhs[0]) != bh) {
int rd_idx, wr_idx;
wr_idx = 0;
get_bh(bh);
lru->bhs[wr_idx++] = bh;
for (rd_idx = 1; rd_idx < BH_LRU_SIZE; rd_idx++) {
struct buffer_head *nxt = lru->bhs[rd_idx];
if (e != NULL)
lru->bhs[wr_idx++] = e;
e = nxt;
if (e == bh) {
__brelse(e);
e = NULL;
} else if (e == NULL)
break;
}
while (wr_idx < BH_LRU_SIZE)
lru->bhs[wr_idx++] = NULL;
}
bh_lru_unlock();
if (e)
__brelse(e);
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/