From cbfa540c68b7a0c61f208ee2d8c7bfe39ac53dae Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 3 Oct 2016 11:08:49 -0400 Subject: [PATCH 01/10] os/bluestore: fix cache tunables to be process-wide Divide by the shard count so that the user isn't totally confused. Signed-off-by: Sage Weil --- src/os/bluestore/BlueStore.cc | 43 ++++++++++++++--------------------- src/os/bluestore/BlueStore.h | 2 ++ 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 5fa3e178a00f8..49b0609cd3be0 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -2064,7 +2064,8 @@ BlueStore::Collection::Collection(BlueStore *ns, Cache *c, coll_t cid) exists(true), // size the shared blob hash table as a ratio of the onode cache size. shared_blob_set(MAX(16, - g_conf->bluestore_onode_cache_size * + g_conf->bluestore_onode_cache_size / + store->cache_shards.size() * g_conf->bluestore_shared_blob_hash_table_size_ratio)), onode_map(c) { @@ -2190,6 +2191,13 @@ BlueStore::OnodeRef BlueStore::Collection::get_onode( return onode_map.add(oid, o); } +void BlueStore::Collection::trim_cache() +{ + cache->trim( + g_conf->bluestore_onode_cache_size / store->cache_shards.size(), + g_conf->bluestore_buffer_cache_size / store->cache_shards.size()); +} + // ======================================================= @@ -4540,10 +4548,7 @@ bool BlueStore::exists(CollectionHandle &c_, const ghobject_t& oid) r = false; } - c->cache->trim( - g_conf->bluestore_onode_cache_size, - g_conf->bluestore_buffer_cache_size); - + c->trim_cache(); return r; } @@ -4581,9 +4586,7 @@ int BlueStore::stat( st->st_nlink = 1; } - c->cache->trim( - g_conf->bluestore_onode_cache_size, - g_conf->bluestore_buffer_cache_size); + c->trim_cache(); int r = 0; if (_debug_mdata_eio(oid)) { r = -EIO; @@ -4643,9 +4646,7 @@ int BlueStore::read( out: assert(allow_eio || r != -EIO); - c->cache->trim( - g_conf->bluestore_onode_cache_size, - g_conf->bluestore_buffer_cache_size); + c->trim_cache(); if (r == 0 && _debug_data_eio(oid)) { r = -EIO; derr << __func__ << " " << c->cid << " " << oid << " INJECT EIO" << dendl; @@ -5040,9 +5041,7 @@ int BlueStore::fiemap( } out: - c->cache->trim( - g_conf->bluestore_onode_cache_size, - g_conf->bluestore_buffer_cache_size); + c->trim_cache(); ::encode(m, bl); dout(20) << __func__ << " 0x" << std::hex << offset << "~" << length << " size = 0x(" << m << ")" << std::dec << dendl; @@ -5091,9 +5090,7 @@ int BlueStore::getattr( r = 0; } out: - c->cache->trim( - g_conf->bluestore_onode_cache_size, - g_conf->bluestore_buffer_cache_size); + c->trim_cache(); if (r == 0 && _debug_mdata_eio(oid)) { r = -EIO; derr << __func__ << " " << c->cid << " " << oid << " INJECT EIO" << dendl; @@ -5139,9 +5136,7 @@ int BlueStore::getattrs( } out: - c->cache->trim( - g_conf->bluestore_onode_cache_size, - g_conf->bluestore_buffer_cache_size); + c->trim_cache(); if (r == 0 && _debug_mdata_eio(oid)) { r = -EIO; derr << __func__ << " " << c->cid << " " << oid << " INJECT EIO" << dendl; @@ -5322,9 +5317,7 @@ int BlueStore::collection_list( } out: - c->cache->trim( - g_conf->bluestore_onode_cache_size, - g_conf->bluestore_buffer_cache_size); + c->trim_cache(); dout(10) << __func__ << " " << c->cid << " start " << start << " end " << end << " max " << max << " = " << r << ", ls.size() = " << ls->size() @@ -6172,9 +6165,7 @@ void BlueStore::_osr_reap_done(OpSequencer *osr) } if (c) { - c->cache->trim( - g_conf->bluestore_onode_cache_size, - g_conf->bluestore_buffer_cache_size); + c->trim_cache(); } } diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index cc2709c2fc9da..11953f5c34883 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -940,6 +940,8 @@ class BlueStore : public ObjectStore, return false; } + void trim_cache(); + Collection(BlueStore *ns, Cache *ca, coll_t c); }; typedef boost::intrusive_ptr CollectionRef; From 6098761000935076b3b15c889a3422e5126081d5 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 30 Sep 2016 18:35:10 -0400 Subject: [PATCH 02/10] os/bluestore: fix typo in write_penalty_read_ops perf counter Signed-off-by: Sage Weil --- src/os/bluestore/BlueStore.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 49b0609cd3be0..af36ac33ceb38 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -2422,7 +2422,7 @@ void BlueStore::_init_logger() "Sum for wal write op"); b.add_u64(l_bluestore_wal_write_bytes, "wal_write_bytes", "Sum for wal write bytes"); - b.add_u64(l_bluestore_write_penalty_read_ops, " write_penalty_read_ops", + b.add_u64(l_bluestore_write_penalty_read_ops, "write_penalty_read_ops", "Sum for write penalty read ops"); b.add_u64(l_bluestore_allocated, "bluestore_allocated", "Sum for allocated bytes"); From 33e26d021d6e00093123a898d5b58f71e20ca21a Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 3 Oct 2016 11:58:20 -0400 Subject: [PATCH 03/10] os/bluestore: add perf counters for cache size Onodes, buffers, buffer bytes. Signed-off-by: Sage Weil --- src/os/bluestore/BlueStore.cc | 21 +++++++++++++++++++++ src/os/bluestore/BlueStore.h | 23 +++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index af36ac33ceb38..2f680c012c2e5 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -2435,10 +2435,16 @@ void BlueStore::_init_logger() b.add_u64(l_bluestore_compressed_original, "bluestore_compressed_original", "Sum for original bytes that were compressed"); + b.add_u64(l_bluestore_onodes, "bluestore_onodes", + "Number of onodes in cache"); b.add_u64(l_bluestore_onode_hits, "bluestore_onode_hits", "Sum for onode-lookups hit in the cache"); b.add_u64(l_bluestore_onode_misses, "bluestore_onode_misses", "Sum for onode-lookups missed in the cache"); + b.add_u64(l_bluestore_buffers, "bluestore_buffers", + "Number of buffers in cache"); + b.add_u64(l_bluestore_buffer_bytes, "bluestore_buffer_bytes", + "Number of buffer bytes in cache"); b.add_u64(l_bluestore_buffer_hit_bytes, "bluestore_buffer_hit_bytes", "Sum for bytes of read hit in the cache"); b.add_u64(l_bluestore_buffer_miss_bytes, "bluestore_buffer_miss_bytes", @@ -4516,6 +4522,19 @@ void BlueStore::_reap_collections() } } +void BlueStore::_update_cache_logger() +{ + uint64_t num_onodes = 0; + uint64_t num_buffers = 0; + uint64_t num_buffer_bytes = 0; + for (auto c : cache_shards) { + c->add_stats(&num_onodes, &num_buffers, &num_buffer_bytes); + } + logger->set(l_bluestore_onodes, num_onodes); + logger->set(l_bluestore_buffers, num_buffers); + logger->set(l_bluestore_buffer_bytes, num_buffer_bytes); +} + // --------------- // read operations @@ -6348,6 +6367,8 @@ void BlueStore::_kv_sync_thread() // this is as good a place as any ... _reap_collections(); + _update_cache_logger(); + if (bluefs) { if (!bluefs_gift_extents.empty()) { _commit_bluefs_freespace(bluefs_gift_extents); diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 11953f5c34883..04c42b4cacdcf 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -72,8 +72,11 @@ enum { l_bluestore_compressed, l_bluestore_compressed_allocated, l_bluestore_compressed_original, + l_bluestore_onodes, l_bluestore_onode_hits, l_bluestore_onode_misses, + l_bluestore_buffers, + l_bluestore_buffer_bytes, l_bluestore_buffer_hit_bytes, l_bluestore_buffer_miss_bytes, l_bluestore_write_big, @@ -714,6 +717,9 @@ class BlueStore : public ObjectStore, virtual void trim(uint64_t onode_max, uint64_t buffer_max) = 0; + virtual void add_stats(uint64_t *onodes, uint64_t *buffers, + uint64_t *bytes) = 0; + #ifdef DEBUG_CACHE virtual void _audit(const char *s) = 0; #else @@ -785,6 +791,14 @@ class BlueStore : public ObjectStore, void trim(uint64_t onode_max, uint64_t buffer_max) override; + void add_stats(uint64_t *onodes, uint64_t *buffers, + uint64_t *bytes) override { + std::lock_guard l(lock); + *onodes += onode_lru.size(); + *buffers += buffer_lru.size(); + *bytes += buffer_size; + } + #ifdef DEBUG_CACHE void _audit(const char *s) override; #endif @@ -860,6 +874,14 @@ class BlueStore : public ObjectStore, void trim(uint64_t onode_max, uint64_t buffer_max) override; + void add_stats(uint64_t *onodes, uint64_t *buffers, + uint64_t *bytes) override { + std::lock_guard l(lock); + *onodes += onode_lru.size(); + *buffers += buffer_hot.size() + buffer_warm_in.size(); + *bytes += buffer_bytes; + } + #ifdef DEBUG_CACHE void _audit(const char *s) override; #endif @@ -1416,6 +1438,7 @@ class BlueStore : public ObjectStore, CollectionRef _get_collection(const coll_t& cid); void _queue_reap_collection(CollectionRef& c); void _reap_collections(); + void _update_cache_logger(); void _assign_nid(TransContext *txc, OnodeRef o); uint64_t _assign_blobid(TransContext *txc); From c8a06ce1ee4eff857cc9539ddedd503cd1712105 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 3 Oct 2016 14:52:38 -0400 Subject: [PATCH 04/10] do_cmake.sh: set .ceph_port to random port Signed-off-by: Sage Weil --- do_cmake.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/do_cmake.sh b/do_cmake.sh index 9d3c3c1ed4457..71340376695d2 100755 --- a/do_cmake.sh +++ b/do_cmake.sh @@ -8,9 +8,13 @@ mkdir build cd build cmake $@ .. +# minimal config to find plugins cat < ceph.conf plugin dir = lib erasure code dir = lib EOF +# give vstart a (hopefully) unique mon port to start with +echo $(( RANDOM % 1000 + 40000 )) > .ceph_port + echo done. From 8c4cabec0f6c126a1617bcc0c505321595ac50f8 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 3 Oct 2016 18:28:26 -0400 Subject: [PATCH 05/10] unittest_bluestore_types: attach blobs to cache Signed-off-by: Sage Weil --- src/test/objectstore/test_bluestore_types.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/objectstore/test_bluestore_types.cc b/src/test/objectstore/test_bluestore_types.cc index f230b7c0e038d..df4f78b9df5cd 100644 --- a/src/test/objectstore/test_bluestore_types.cc +++ b/src/test/objectstore/test_bluestore_types.cc @@ -669,8 +669,10 @@ TEST(Blob, put_ref) TEST(ExtentMap, find_lextent) { + BlueStore::LRUCache cache; BlueStore::ExtentMap em(nullptr); BlueStore::BlobRef br(new BlueStore::Blob); + br->shared_blob = new BlueStore::SharedBlob(-1, string(), &cache); ASSERT_EQ(em.extent_map.end(), em.find_lextent(0)); ASSERT_EQ(em.extent_map.end(), em.find_lextent(100)); @@ -713,8 +715,10 @@ TEST(ExtentMap, find_lextent) TEST(ExtentMap, seek_lextent) { + BlueStore::LRUCache cache; BlueStore::ExtentMap em(nullptr); BlueStore::BlobRef br(new BlueStore::Blob); + br->shared_blob = new BlueStore::SharedBlob(-1, string(), &cache); ASSERT_EQ(em.extent_map.end(), em.seek_lextent(0)); ASSERT_EQ(em.extent_map.end(), em.seek_lextent(100)); @@ -757,8 +761,10 @@ TEST(ExtentMap, seek_lextent) TEST(ExtentMap, has_any_lextents) { + BlueStore::LRUCache cache; BlueStore::ExtentMap em(nullptr); BlueStore::BlobRef b(new BlueStore::Blob); + b->shared_blob = new BlueStore::SharedBlob(-1, string(), &cache); ASSERT_FALSE(em.has_any_lextents(0, 0)); ASSERT_FALSE(em.has_any_lextents(0, 1000)); @@ -799,10 +805,14 @@ TEST(ExtentMap, has_any_lextents) TEST(ExtentMap, compress_extent_map) { + BlueStore::LRUCache cache; BlueStore::ExtentMap em(nullptr); BlueStore::BlobRef b1(new BlueStore::Blob); BlueStore::BlobRef b2(new BlueStore::Blob); BlueStore::BlobRef b3(new BlueStore::Blob); + b1->shared_blob = new BlueStore::SharedBlob(-1, string(), &cache); + b2->shared_blob = new BlueStore::SharedBlob(-1, string(), &cache); + b3->shared_blob = new BlueStore::SharedBlob(-1, string(), &cache); em.extent_map.insert(*new BlueStore::Extent(0, 0, 100, 1, b1)); em.extent_map.insert(*new BlueStore::Extent(100, 0, 100, 1, b2)); From a70690834048c96306a614c7ce683c8dd0ba56ef Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 3 Oct 2016 18:28:37 -0400 Subject: [PATCH 06/10] os/bluestore: instrument cache blob and extent counts Signed-off-by: Sage Weil --- src/os/bluestore/BlueStore.cc | 13 +++++-- src/os/bluestore/BlueStore.h | 64 +++++++++++++++++++++++++++++++---- 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 2f680c012c2e5..5d224de65e8dd 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -1695,7 +1695,7 @@ void BlueStore::ExtentMap::decode_some(bufferlist& bl) uint64_t prev_len = 0; unsigned n = 0; while (!p.end()) { - Extent *le = new Extent(); + Extent *le = new Extent(onode->c->cache); uint64_t blobid; small_decode_varint(blobid, p); if ((blobid & BLOBID_FLAG_CONTIGUOUS) == 0) { @@ -2441,6 +2441,10 @@ void BlueStore::_init_logger() "Sum for onode-lookups hit in the cache"); b.add_u64(l_bluestore_onode_misses, "bluestore_onode_misses", "Sum for onode-lookups missed in the cache"); + b.add_u64(l_bluestore_extents, "bluestore_extents", + "Number of extents in cache"); + b.add_u64(l_bluestore_blobs, "bluestore_blobs", + "Number of blobs in cache"); b.add_u64(l_bluestore_buffers, "bluestore_buffers", "Number of buffers in cache"); b.add_u64(l_bluestore_buffer_bytes, "bluestore_buffer_bytes", @@ -4525,12 +4529,17 @@ void BlueStore::_reap_collections() void BlueStore::_update_cache_logger() { uint64_t num_onodes = 0; + uint64_t num_extents = 0; + uint64_t num_blobs = 0; uint64_t num_buffers = 0; uint64_t num_buffer_bytes = 0; for (auto c : cache_shards) { - c->add_stats(&num_onodes, &num_buffers, &num_buffer_bytes); + c->add_stats(&num_onodes, &num_extents, &num_blobs, + &num_buffers, &num_buffer_bytes); } logger->set(l_bluestore_onodes, num_onodes); + logger->set(l_bluestore_extents, num_extents); + logger->set(l_bluestore_blobs, num_blobs); logger->set(l_bluestore_buffers, num_buffers); logger->set(l_bluestore_buffer_bytes, num_buffer_bytes); } diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 04c42b4cacdcf..744a43a6606e8 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -75,6 +75,8 @@ enum { l_bluestore_onodes, l_bluestore_onode_hits, l_bluestore_onode_misses, + l_bluestore_extents, + l_bluestore_blobs, l_bluestore_buffers, l_bluestore_buffer_bytes, l_bluestore_buffer_hit_bytes, @@ -207,10 +209,17 @@ class BlueStore : public ObjectStore, Cache *cache; map writing_map; - BufferSpace(Cache *c) : cache(c) {} + BufferSpace(Cache *c) : cache(c) { + if (cache) { + cache->add_blob(); + } + } ~BufferSpace() { assert(buffer_map.empty()); assert(writing_map.empty()); + if (cache) { + cache->rm_blob(); + } } void _add_buffer(Buffer *b, int level, Buffer *near) { @@ -512,10 +521,24 @@ class BlueStore : public ObjectStore, uint8_t blob_depth; /// blob overlapping count BlobRef blob; ///< the blob with our data - explicit Extent() {} - explicit Extent(uint32_t lo) : logical_offset(lo) {} + /// ctor for lookup only + explicit Extent(uint32_t lo) : logical_offset(lo) { } + /// ctor for delayed intitialization (see decode_some()) + explicit Extent(Cache *cache) { + cache->add_extent(); + } + /// ctor for general usage Extent(uint32_t lo, uint32_t o, uint32_t l, uint8_t bd, BlobRef& b) - : logical_offset(lo), blob_offset(o), length(l), blob_depth(bd), blob(b){} + : logical_offset(lo), blob_offset(o), length(l), blob_depth(bd), blob(b) { + if (blob) { + blob->shared_blob->bc.cache->add_extent(); + } + } + ~Extent() { + if (blob) { + blob->shared_blob->bc.cache->rm_extent(); + } + } // comparators for intrusive_set friend bool operator<(const Extent &a, const Extent &b) { @@ -702,6 +725,9 @@ class BlueStore : public ObjectStore, PerfCounters *logger; std::recursive_mutex lock; ///< protect lru and other structures + std::atomic num_extents = {0}; + std::atomic num_blobs = {0}; + static Cache *create(string type, PerfCounters *logger); virtual ~Cache() {} @@ -715,9 +741,25 @@ class BlueStore : public ObjectStore, virtual void _adjust_buffer_size(Buffer *b, int64_t delta) = 0; virtual void _touch_buffer(Buffer *b) = 0; + void add_extent() { + ++num_extents; + } + void rm_extent() { + --num_extents; + } + + void add_blob() { + ++num_blobs; + } + void rm_blob() { + --num_blobs; + } + virtual void trim(uint64_t onode_max, uint64_t buffer_max) = 0; - virtual void add_stats(uint64_t *onodes, uint64_t *buffers, + virtual void add_stats(uint64_t *onodes, uint64_t *extents, + uint64_t *blobs, + uint64_t *buffers, uint64_t *bytes) = 0; #ifdef DEBUG_CACHE @@ -791,10 +833,14 @@ class BlueStore : public ObjectStore, void trim(uint64_t onode_max, uint64_t buffer_max) override; - void add_stats(uint64_t *onodes, uint64_t *buffers, + void add_stats(uint64_t *onodes, uint64_t *extents, + uint64_t *blobs, + uint64_t *buffers, uint64_t *bytes) override { std::lock_guard l(lock); *onodes += onode_lru.size(); + *extents += num_extents; + *blobs += num_blobs; *buffers += buffer_lru.size(); *bytes += buffer_size; } @@ -874,10 +920,14 @@ class BlueStore : public ObjectStore, void trim(uint64_t onode_max, uint64_t buffer_max) override; - void add_stats(uint64_t *onodes, uint64_t *buffers, + void add_stats(uint64_t *onodes, uint64_t *extents, + uint64_t *blobs, + uint64_t *buffers, uint64_t *bytes) override { std::lock_guard l(lock); *onodes += onode_lru.size(); + *extents += num_extents; + *blobs += num_blobs; *buffers += buffer_hot.size() + buffer_warm_in.size(); *bytes += buffer_bytes; } From 05bb253c94e92573325e8c86c4745246459f614c Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 3 Oct 2016 18:30:15 -0400 Subject: [PATCH 07/10] os/bluestore: drop unnecessary assert Signed-off-by: Sage Weil --- src/os/bluestore/BlueStore.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 5d224de65e8dd..6d73af922d56c 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -1172,7 +1172,6 @@ ostream& operator<<(ostream& out, const BlueStore::SharedBlob& sb) out << "SharedBlob(" << &sb; if (sb.sbid) { out << " sbid 0x" << std::hex << sb.sbid << std::dec; - assert(sb.parent_set); } if (sb.loaded) { out << " loaded " << sb.shared_blob; From 0118293a4e332d749075872d22733f4b15df5b28 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 3 Oct 2016 18:34:02 -0400 Subject: [PATCH 08/10] os/bluestore: turn bluestore_onode_cache_size 16k -> 4k Signed-off-by: Sage Weil --- src/common/config_opts.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/config_opts.h b/src/common/config_opts.h index a96b8b30044e0..8e45b4b310321 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -990,7 +990,7 @@ OPTION(bluestore_extent_map_shard_min_size, OPT_U32, 150) OPTION(bluestore_extent_map_shard_target_size_slop, OPT_DOUBLE, .2) OPTION(bluestore_extent_map_inline_shard_prealloc_size, OPT_U32, 256) OPTION(bluestore_cache_type, OPT_STR, "2q") // lru, 2q -OPTION(bluestore_onode_cache_size, OPT_U32, 16*1024) +OPTION(bluestore_onode_cache_size, OPT_U32, 4*1024) OPTION(bluestore_buffer_cache_size, OPT_U32, 512*1024*1024) OPTION(bluestore_shared_blob_hash_table_size_ratio, OPT_FLOAT, 2) // multiple of onode_cache_size OPTION(bluestore_kvbackend, OPT_STR, "rocksdb") From 304a3b1bf8c2c557b5cb99d3ed58d8c6775297f4 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 4 Oct 2016 10:59:15 -0400 Subject: [PATCH 09/10] os/bluestore: use Extent::assign_blob More explicit, less error-prone. Signed-off-by: Sage Weil --- src/os/bluestore/BlueStore.cc | 8 ++++---- src/os/bluestore/BlueStore.h | 15 +++++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 6d73af922d56c..7c48cdc5d8f00 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -1694,7 +1694,7 @@ void BlueStore::ExtentMap::decode_some(bufferlist& bl) uint64_t prev_len = 0; unsigned n = 0; while (!p.end()) { - Extent *le = new Extent(onode->c->cache); + Extent *le = new Extent(); uint64_t blobid; small_decode_varint(blobid, p); if ((blobid & BLOBID_FLAG_CONTIGUOUS) == 0) { @@ -1719,14 +1719,14 @@ void BlueStore::ExtentMap::decode_some(bufferlist& bl) le->blob_depth = 1; } if (blobid & BLOBID_FLAG_SPANNING) { - le->blob = get_spanning_blob(blobid >> BLOBID_SHIFT_BITS); + le->assign_blob(get_spanning_blob(blobid >> BLOBID_SHIFT_BITS)); } else { blobid >>= BLOBID_SHIFT_BITS; if (blobid) { - le->blob = blobs[blobid - 1]; + le->assign_blob(blobs[blobid - 1]); assert(le->blob); } else { - le->blob = new Blob(); + le->assign_blob(new Blob()); le->blob->decode(p); blobs[n] = le->blob; onode->c->open_shared_blob(le->blob); diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 744a43a6606e8..7266dc423fbd8 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -524,15 +524,12 @@ class BlueStore : public ObjectStore, /// ctor for lookup only explicit Extent(uint32_t lo) : logical_offset(lo) { } /// ctor for delayed intitialization (see decode_some()) - explicit Extent(Cache *cache) { - cache->add_extent(); + explicit Extent() { } /// ctor for general usage Extent(uint32_t lo, uint32_t o, uint32_t l, uint8_t bd, BlobRef& b) - : logical_offset(lo), blob_offset(o), length(l), blob_depth(bd), blob(b) { - if (blob) { - blob->shared_blob->bc.cache->add_extent(); - } + : logical_offset(lo), blob_offset(o), length(l), blob_depth(bd) { + assign_blob(b); } ~Extent() { if (blob) { @@ -540,6 +537,12 @@ class BlueStore : public ObjectStore, } } + void assign_blob(const BlobRef& b) { + assert(!blob); + blob = b; + blob->shared_blob->bc.cache->add_extent(); + } + // comparators for intrusive_set friend bool operator<(const Extent &a, const Extent &b) { return a.logical_offset < b.logical_offset; From b16bd7781a4c8c9758e0163f07d56c9c509ea599 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 4 Oct 2016 11:14:08 -0400 Subject: [PATCH 10/10] unittest_bluestore_types: show sizeof for key types Signed-off-by: Sage Weil --- src/test/objectstore/test_bluestore_types.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/objectstore/test_bluestore_types.cc b/src/test/objectstore/test_bluestore_types.cc index df4f78b9df5cd..a4085155bebf9 100644 --- a/src/test/objectstore/test_bluestore_types.cc +++ b/src/test/objectstore/test_bluestore_types.cc @@ -13,6 +13,19 @@ #include +#define _STR(x) #x +#define STRINGIFY(x) _STR(x) + +TEST(bluestore, sizeof) { +#define P(t) cout << STRINGIFY(t) << "\t" << sizeof(t) << std::endl + P(BlueStore::Onode); + P(BlueStore::Extent); + P(BlueStore::Blob); + P(BlueStore::SharedBlob); + P(bluestore_extent_ref_map_t); + P(bluestore_extent_ref_map_t::record_t); +} + TEST(bluestore_extent_ref_map_t, add) { bluestore_extent_ref_map_t m;