From 63279896a0c3fcdbf9a2e168f6f3656583926a0b Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 31 May 2016 12:40:16 -0400 Subject: [PATCH] os/bluestore: use bufferptr for csum_data encode/decode of vector is not optimized. Bufferptr is a more natural type here anyway. Signed-off-by: Sage Weil --- src/common/Checksummer.h | 10 +++++----- src/os/bluestore/BlueStore.cc | 4 ++-- src/os/bluestore/bluestore_types.cc | 2 +- src/os/bluestore/bluestore_types.h | 15 ++++++++------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/common/Checksummer.h b/src/common/Checksummer.h index 17ece379e41ab..2e062e075d4b5 100644 --- a/src/common/Checksummer.h +++ b/src/common/Checksummer.h @@ -90,7 +90,7 @@ public: size_t offset, size_t length, const bufferlist &bl, - vector* csum_data + bufferptr* csum_data ) { assert(length % csum_block_size == 0); size_t blocks = length / csum_block_size; @@ -100,11 +100,11 @@ public: typename Alg::state_t state; Alg::init(&state); - assert(csum_data->size() >= (offset + length) / csum_block_size * + assert(csum_data->length() >= (offset + length) / csum_block_size * sizeof(typename Alg::value_t)); typename Alg::value_t *pv = - reinterpret_cast(&(*csum_data)[0]); + reinterpret_cast(csum_data->c_str()); pv += offset / csum_block_size; while (blocks--) { *pv = Alg::calc(state, csum_block_size, p); @@ -120,7 +120,7 @@ public: size_t offset, size_t length, const bufferlist &bl, - const vector& csum_data + const bufferptr& csum_data ) { assert(length % csum_block_size == 0); bufferlist::const_iterator p = bl.begin(); @@ -130,7 +130,7 @@ public: Alg::init(&state); const typename Alg::value_t *pv = - reinterpret_cast(&csum_data[0]); + reinterpret_cast(csum_data.c_str()); pv += offset / csum_block_size; size_t pos = offset; while (length > 0) { diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 01bd9c55f7444..9d94406f049cf 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -5177,7 +5177,7 @@ void BlueStore::_dump_onode(OnodeRef o, int log_level) for (auto& b : o->onode.blob_map) { dout(log_level) << __func__ << " " << b.first << ": " << b.second << dendl; - if (b.second.csum_data.size()) { + if (b.second.has_csum_data()) { vector v; unsigned n = b.second.get_csum_count(); for (unsigned i = 0; i < n; ++i) @@ -5221,7 +5221,7 @@ void BlueStore::_dump_bnode(BnodeRef b, int log_level) dout(log_level) << __func__ << " " << std::hex << b->hash << std::dec << dendl; for (auto &p : b->blob_map) { dout(log_level) << __func__ << " " << p.first << ": " << p.second << dendl; - if (p.second.csum_data.size()) { + if (p.second.has_csum_data()) { vector v; unsigned n = p.second.get_csum_count(); for (unsigned i = 0; i < n; ++i) diff --git a/src/os/bluestore/bluestore_types.cc b/src/os/bluestore/bluestore_types.cc index 4ff5c6b51c65f..41239d8b1fc19 100644 --- a/src/os/bluestore/bluestore_types.cc +++ b/src/os/bluestore/bluestore_types.cc @@ -513,7 +513,7 @@ void bluestore_blob_t::generate_test_instances(list& ls) ls.push_back(new bluestore_blob_t(4096, bluestore_pextent_t(111, 222), 12)); ls.back()->csum_type = CSUM_XXHASH32; ls.back()->csum_block_order = 16; - ls.back()->csum_data = vector{1, 2, 3, 4}; // one uint32_t + ls.back()->csum_data = buffer::claim_malloc(4, strdup("abcd")); ls.back()->ref_map.get(3, 5); ls.back()->add_unused(0, 3); ls.back()->add_unused(8, 8); diff --git a/src/os/bluestore/bluestore_types.h b/src/os/bluestore/bluestore_types.h index efc971cb1f243..336e03507c9b6 100644 --- a/src/os/bluestore/bluestore_types.h +++ b/src/os/bluestore/bluestore_types.h @@ -260,7 +260,7 @@ struct bluestore_blob_t { bluestore_extent_ref_map_t ref_map; ///< references (empty when in onode) interval_set unused; ///< portion that has never been written to - vector csum_data; ///< opaque vector of csum data + bufferptr csum_data; ///< opaque vector of csum data bluestore_blob_t(uint32_t l = 0, uint32_t f = 0) : length(l), @@ -422,7 +422,7 @@ struct bluestore_blob_t { } bool has_csum_data() const { - return csum_data.size() > 0; + return csum_data.length() > 0; } uint32_t get_csum_block_size() const { @@ -443,11 +443,11 @@ struct bluestore_blob_t { size_t vs = get_csum_value_size(); if (!vs) return 0; - return csum_data.size() / vs; + return csum_data.length() / vs; } uint64_t get_csum_item(unsigned i) const { size_t cs = get_csum_value_size(); - const char *p = &csum_data[cs * i]; + const char *p = csum_data.c_str(); switch (cs) { case 0: assert(0 == "no csum data, bad index"); @@ -463,17 +463,18 @@ struct bluestore_blob_t { } const char *get_csum_item_ptr(unsigned i) const { size_t cs = get_csum_value_size(); - return &csum_data[cs * i]; + return csum_data.c_str() + (cs * i); } char *get_csum_item_ptr(unsigned i) { size_t cs = get_csum_value_size(); - return &csum_data[cs * i]; + return csum_data.c_str() + (cs * i); } void init_csum(unsigned type, unsigned order, unsigned len) { csum_type = type; csum_block_order = order; - csum_data.resize(get_csum_value_size() * len / get_csum_block_size()); + csum_data = buffer::create(get_csum_value_size() * len / get_csum_block_size()); + csum_data.zero(); } /// calculate csum for the buffer at the given b_off -- 2.39.5