Skip to content

Commit f348ea3

Browse files
committed
kv: avoid memcpy in OMAP iterator of KeyValueDB
``` - 63.07% _ZN12PrimaryLogPG19prepare_transactionEPNS_9OpContextE ▒ - 63.06% _ZN12PrimaryLogPG10do_osd_opsEPNS_9OpContextERSt6vectorI5OSDOpSaIS3_EE ▒ - 20.19% _ZN9BlueStore16OmapIteratorImpl4nextEv ▒ - 12.21% _ZN14CFIteratorImpl4nextEv ▒ + 10.56% _ZN7rocksdb6DBIter4NextEv ▒ 1.02% _ZN7rocksdb18ArenaWrappedDBIter4NextEv ▒ + 3.11% clock_gettime@@GLIBC_2.17 ▒ + 2.44% _ZN9BlueStore11log_latencyEPKciRKNSt6chrono8durationImSt5ratioILl1ELl1000000000EEEEdS1_i ▒ 0.78% pthread_rwlock_rdlock@plt ▒ 0.69% pthread_rwlock_unlock@plt ▒ - 14.28% _ZN9BlueStore16OmapIteratorImpl5valueEv ▒ - 11.60% _ZN14CFIteratorImpl5valueEv ▒ - 11.41% _ZL13to_bufferlistN7rocksdb5SliceE ▒ - 10.50% _ZN4ceph6buffer7v15_2_03ptrC1EPKcj ▒ - _ZN4ceph6buffer7v15_2_04copyEPKcj ▒ - 10.01% _ZN4ceph6buffer7v15_2_014create_alignedEjj ▒ - _ZN4ceph6buffer7v15_2_025create_aligned_in_mempoolEjji ▒ 5.27% _ZN7mempool6pool_t12adjust_countEll ▒ + 3.72% tc_posix_memalign ▒ 0.54% _ZN4ceph6buffer7v15_2_04list6appendEONS1_3ptrE ▒ 1.25% pthread_rwlock_rdlock@plt ▒ 0.90% pthread_rwlock_unlock@plt ``` Signed-off-by: Radoslaw Zarzynski <[email protected]>
1 parent c740754 commit f348ea3

File tree

11 files changed

+64
-0
lines changed

11 files changed

+64
-0
lines changed

src/kv/KeyValueDB.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <map>
1010
#include <optional>
1111
#include <string>
12+
#include <string_view>
1213
#include <boost/scoped_ptr.hpp>
1314
#include "include/encoding.h"
1415
#include "common/Formatter.h"
@@ -205,6 +206,7 @@ class KeyValueDB {
205206
return "";
206207
}
207208
virtual ceph::buffer::list value() = 0;
209+
virtual std::string_view value_as_sv() = 0;
208210
virtual int status() = 0;
209211
virtual ~SimplestIteratorImpl() {}
210212
};
@@ -252,6 +254,7 @@ class KeyValueDB {
252254
return ceph::buffer::ptr();
253255
}
254256
}
257+
virtual std::string_view value_as_sv() = 0;
255258
virtual int status() = 0;
256259
virtual size_t key_size() {
257260
return 0;
@@ -318,6 +321,9 @@ class KeyValueDB {
318321
ceph::buffer::ptr value_as_ptr() override {
319322
return generic_iter->value_as_ptr();
320323
}
324+
std::string_view value_as_sv() override {
325+
return generic_iter->value_as_sv();
326+
}
321327
int status() override {
322328
return generic_iter->status();
323329
}

src/kv/RocksDBStore.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,6 +2267,12 @@ bufferptr RocksDBStore::RocksDBWholeSpaceIteratorImpl::value_as_ptr()
22672267
return bufferptr(val.data(), val.size());
22682268
}
22692269

2270+
std::string_view RocksDBStore::RocksDBWholeSpaceIteratorImpl::value_as_sv()
2271+
{
2272+
rocksdb::Slice val = dbiter->value();
2273+
return std::string_view{val.data(), val.size()};
2274+
}
2275+
22702276
int RocksDBStore::RocksDBWholeSpaceIteratorImpl::status()
22712277
{
22722278
return dbiter->status().ok() ? 0 : -1;
@@ -2358,6 +2364,10 @@ class CFIteratorImpl : public KeyValueDB::IteratorImpl {
23582364
rocksdb::Slice val = dbiter->value();
23592365
return bufferptr(val.data(), val.size());
23602366
}
2367+
std::string_view value_as_sv() override {
2368+
rocksdb::Slice val = dbiter->value();
2369+
return std::string_view{val.data(), val.size()};
2370+
}
23612371
int status() override {
23622372
return dbiter->status().ok() ? 0 : -1;
23632373
}
@@ -2695,6 +2705,15 @@ class WholeMergeIteratorImpl : public KeyValueDB::WholeSpaceIteratorImpl {
26952705
}
26962706
}
26972707

2708+
std::string_view value_as_sv() override
2709+
{
2710+
if (smaller == on_main) {
2711+
return main->value_as_sv();
2712+
} else {
2713+
return current_shard->second->value_as_sv();
2714+
}
2715+
}
2716+
26982717
int status() override
26992718
{
27002719
//because we already had to inspect key, it must be ok
@@ -3027,6 +3046,10 @@ class ShardMergeIteratorImpl : public KeyValueDB::IteratorImpl {
30273046
rocksdb::Slice val = iters[0]->value();
30283047
return bufferptr(val.data(), val.size());
30293048
}
3049+
std::string_view value_as_sv() override {
3050+
rocksdb::Slice val = iters[0]->value();
3051+
return std::string_view{val.data(), val.size()};
3052+
}
30303053
int status() override {
30313054
return iters[0]->status().ok() ? 0 : -1;
30323055
}

src/kv/RocksDBStore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ class RocksDBStore : public KeyValueDB {
384384
bool raw_key_is_prefixed(const std::string &prefix) override;
385385
ceph::bufferlist value() override;
386386
ceph::bufferptr value_as_ptr() override;
387+
std::string_view value_as_sv() override;
387388
int status() override;
388389
size_t key_size() override;
389390
size_t value_size() override;

src/os/DBObjectMap.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,11 @@ bufferlist DBObjectMap::DBObjectMapIteratorImpl::value()
519519
return cur_iter->value();
520520
}
521521

522+
std::string_view DBObjectMap::DBObjectMapIteratorImpl::value_as_sv()
523+
{
524+
return cur_iter->value_as_sv();
525+
}
526+
522527
int DBObjectMap::DBObjectMapIteratorImpl::status()
523528
{
524529
return r;

src/os/DBObjectMap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ class DBObjectMap : public ObjectMap {
393393
int next() override { ceph_abort(); return 0; }
394394
std::string key() override { ceph_abort(); return ""; }
395395
ceph::buffer::list value() override { ceph_abort(); return ceph::buffer::list(); }
396+
std::string_view value_as_sv() override { ceph_abort(); return std::string_view(); }
396397
int status() override { return 0; }
397398
};
398399

@@ -431,6 +432,7 @@ class DBObjectMap : public ObjectMap {
431432
int next() override;
432433
std::string key() override;
433434
ceph::buffer::list value() override;
435+
std::string_view value_as_sv() override;
434436
int status() override;
435437

436438
bool on_parent() {

src/os/bluestore/BlueStore.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5654,6 +5654,13 @@ bufferlist BlueStore::OmapIteratorImpl::value()
56545654
return it->value();
56555655
}
56565656

5657+
std::string_view BlueStore::OmapIteratorImpl::value_as_sv()
5658+
{
5659+
std::shared_lock l(c->lock);
5660+
ceph_assert(it->valid());
5661+
return it->value_as_sv();
5662+
}
5663+
56575664

56585665
// =====================================
56595666

src/os/bluestore/BlueStore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,7 @@ class BlueStore : public ObjectStore,
17531753
int next() override;
17541754
std::string key() override;
17551755
ceph::buffer::list value() override;
1756+
std::string_view value_as_sv() override;
17561757
std::string tail_key() override {
17571758
return tail;
17581759
}

src/os/kstore/KStore.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,13 @@ bufferlist KStore::OmapIteratorImpl::value()
16511651
return it->value();
16521652
}
16531653

1654+
std::string_view KStore::OmapIteratorImpl::value_as_sv()
1655+
{
1656+
std::shared_lock l{c->lock};
1657+
ceph_assert(it->valid());
1658+
return it->value_as_sv();
1659+
}
1660+
16541661
int KStore::omap_get(
16551662
CollectionHandle& ch, ///< [in] Collection containing oid
16561663
const ghobject_t &oid, ///< [in] Object containing omap

src/os/kstore/KStore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ class KStore : public ObjectStore {
180180
int next() override;
181181
std::string key() override;
182182
ceph::buffer::list value() override;
183+
std::string_view value_as_sv() override;
183184
int status() override {
184185
return 0;
185186
}

src/os/memstore/MemStore.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,10 @@ class MemStore::OmapIteratorImpl : public ObjectMap::ObjectMapIteratorImpl {
622622
std::lock_guard lock{o->omap_mutex};
623623
return it->second;
624624
}
625+
std::string_view value_as_sv() override {
626+
std::lock_guard lock{o->omap_mutex};
627+
return std::string_view{it->second.c_str(), it->second.length()};
628+
}
625629
int status() override {
626630
return 0;
627631
}

0 commit comments

Comments
 (0)