Skip to contentSkip to conversation

Full buffer cache not working as expected

DISCUSSION Thanos Makatos 1 participant 1 message Jul 12, 2007

lore
Share & tools
lore
#0 lore raw

I run several times the following test and what I've seen is that when the buffer cache becomes full, unneeded dirty buffer heads are not evicted and no other memory allocation can happen (including reading a block from the disk to the buffer cache). Should this happen?
Here's the code that reproduces this issue:

for(i = 0; i < get_capacity(bdev->bd_disk)/8; i++) {
       bh = __bread(bdev, i, PAGE_SIZE);
       lock_buffer(bh);
       memset(bh->b_data, 0, PAGE_SIZE);
       set_buffer_dirty(bh);
       unlock_buffer(bh);
       __brelse(bh);
}

I added some printks printing the buffer head's reference counter: after the '__bread' ref count is 2, after '__brelse' ref count is 1. Shouldn't these
numbers be 1 and 0 respectively? I added an extra 'put_bh' before (or after) the '__brelse' but I get a BUG().