From 4489a9bae66da4fd6c56bce1daef41b948638892 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Mon, 14 Aug 2017 10:13:32 +0100 Subject: [PATCH] [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. --- block-cache/block_cache.cc | 11 +++++++++-- block-cache/block_cache.h | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/block-cache/block_cache.cc b/block-cache/block_cache.cc index 5f76dec..7f603c2 100644 --- a/block-cache/block_cache.cc +++ b/block-cache/block_cache.cc @@ -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); } diff --git a/block-cache/block_cache.h b/block-cache/block_cache.h index 89f8d09..d6cd1c9 100644 --- a/block-cache/block_cache.h +++ b/block-cache/block_cache.h @@ -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