From bb85f1078148586732975fd2ca84a26363489ca4 Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Sat, 3 Sep 2016 09:06:43 +0800 Subject: [PATCH] os/bluestore: replace store with logger in Cache As what we really want is to log cache-related statistics. Signed-off-by: xie xingguo --- src/os/bluestore/BlueStore.cc | 27 ++++++++++++++++----------- src/os/bluestore/BlueStore.h | 6 ++---- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index dbdec0b75cfec..fd4b343d741f4 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -480,13 +480,19 @@ ostream& operator<<(ostream& out, const BlueStore::Buffer& b) // Cache -BlueStore::Cache *BlueStore::Cache::create(string type) +BlueStore::Cache *BlueStore::Cache::create(string type, PerfCounters *logger) { + Cache *c = nullptr; + if (type == "lru") - return new LRUCache; - if (type == "2q") - return new TwoQCache; - assert(0 == "unrecognized cache type"); + c = new LRUCache; + else if (type == "2q") + c = new TwoQCache; + else + assert(0 == "unrecognized cache type"); + + c->logger = logger; + return c; } // LRUCache @@ -1026,8 +1032,8 @@ void BlueStore::BufferSpace::read( uint64_t hit_bytes = res_intervals.size(); assert(hit_bytes <= want_bytes); uint64_t miss_bytes = want_bytes - hit_bytes; - cache->store->logger->inc(l_bluestore_buffer_hit_bytes, hit_bytes); - cache->store->logger->inc(l_bluestore_buffer_miss_bytes, miss_bytes); + cache->logger->inc(l_bluestore_buffer_hit_bytes, hit_bytes); + cache->logger->inc(l_bluestore_buffer_miss_bytes, miss_bytes); } void BlueStore::BufferSpace::finish_write(uint64_t seq) @@ -1083,12 +1089,12 @@ BlueStore::OnodeRef BlueStore::OnodeSpace::lookup(const ghobject_t& oid) ceph::unordered_map::iterator p = onode_map.find(oid); if (p == onode_map.end()) { dout(30) << __func__ << " " << oid << " miss" << dendl; - cache->store->logger->inc(l_bluestore_onode_misses); + cache->logger->inc(l_bluestore_onode_misses); return OnodeRef(); } dout(30) << __func__ << " " << oid << " hit " << p->second << dendl; cache->_touch_onode(p->second); - cache->store->logger->inc(l_bluestore_onode_hits); + cache->logger->inc(l_bluestore_onode_hits); return p->second; } @@ -2816,8 +2822,7 @@ void BlueStore::set_cache_shards(unsigned num) assert(num >= old); cache_shards.resize(num); for (unsigned i = old; i < num; ++i) { - cache_shards[i] = Cache::create(g_conf->bluestore_cache_type); - cache_shards[i]->set_store(this); + cache_shards[i] = Cache::create(g_conf->bluestore_cache_type, logger); } } diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 874cd5aff4e9b..4dae5eb977f4e 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -573,12 +573,10 @@ public: /// a cache (shard) of onodes and buffers struct Cache { - BlueStore *store; + PerfCounters *logger; std::mutex lock; ///< protect lru and other structures - static Cache *create(string type); - - void set_store(BlueStore *bs) { store = bs; } + static Cache *create(string type, PerfCounters *logger); virtual ~Cache() {} -- 2.39.5