[block-cache] reverse earlier patch which took out manual counts for

nr_dirty etc.

The block list type doesn't have a constant time size() method.
This commit is contained in:
Joe Thornber 2017-08-14 10:13:32 +01:00
parent 2f355f64ff
commit 4489a9bae6
2 changed files with 11 additions and 2 deletions

View File

@ -105,14 +105,17 @@ block_cache::complete_io(block &b, int result)
{
b.error_ = result;
b.clear_flags(BF_IO_PENDING);
nr_io_pending_--;
if (b.error_) {
b.unlink();
errored_.push_back(b);
} else {
if (b.test_flags(BF_DIRTY))
if (b.test_flags(BF_DIRTY)) {
b.clear_flags(BF_DIRTY | BF_PREVIOUSLY_DIRTY);
nr_dirty_--;
}
b.unlink();
clean_.push_back(b);
@ -132,6 +135,7 @@ block_cache::issue_low_level(block &b, enum io_iocb_cmd opcode, const char *desc
assert(!b.test_flags(BF_IO_PENDING));
b.set_flags(BF_IO_PENDING);
nr_io_pending_++;
b.unlink();
io_pending_.push_back(b);
@ -370,6 +374,8 @@ block_cache::calc_nr_buckets(unsigned nr_blocks)
block_cache::block_cache(int fd, sector_t block_size, uint64_t on_disk_blocks, size_t mem)
: nr_locked_(0),
nr_dirty_(0),
nr_io_pending_(0),
read_hits_(0),
read_misses_(0),
write_zeroes_(0),
@ -549,7 +555,7 @@ block_cache::get(block_address index, unsigned flags, validator::ptr v)
void
block_cache::preemptive_writeback()
{
unsigned nr_available = nr_cache_blocks_ - (dirty_.size() - io_pending_.size());
unsigned nr_available = nr_cache_blocks_ - (nr_dirty_ - nr_io_pending_);
if (nr_available < (WRITEBACK_LOW_THRESHOLD_PERCENT * nr_cache_blocks_ / 100))
writeback((WRITEBACK_HIGH_THRESHOLD_PERCENT * nr_cache_blocks_ / 100) - nr_available);
@ -569,6 +575,7 @@ block_cache::release(block_cache::block &b)
if (!b.test_flags(BF_PREVIOUSLY_DIRTY)) {
b.unlink();
dirty_.push_back(b);
nr_dirty_++;
b.set_flags(BF_PREVIOUSLY_DIRTY);
}

View File

@ -267,7 +267,9 @@ namespace bcache {
block_list clean_;
unsigned nr_locked_;
unsigned nr_dirty_;
unsigned nr_io_pending_;
block_list io_pending_;
typedef bi::member_hook<block,