]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
kv: avoid memcpy in OMAP iterator of KeyValueDB
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Sat, 12 Oct 2024 09:15:22 +0000 (09:15 +0000)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Tue, 14 Jan 2025 12:50:36 +0000 (12:50 +0000)
```
                     - 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 <rzarzyns@redhat.com>
(cherry picked from commit f348ea3cf5328684398795990cc87b91c906609b)

src/kv/KeyValueDB.h
src/kv/RocksDBStore.cc
src/kv/RocksDBStore.h
src/os/DBObjectMap.cc
src/os/DBObjectMap.h
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h
src/os/kstore/KStore.cc
src/os/kstore/KStore.h
src/os/memstore/MemStore.cc
src/test/ObjectMap/KeyValueDBMemory.cc

index 9cfb4482706c967190e9539afc4369b30c184dfe..ba3686fe4c815b0d7a1bb437410822b1213044f0 100644 (file)
@@ -9,6 +9,7 @@
 #include <map>
 #include <optional>
 #include <string>
+#include <string_view>
 #include <boost/scoped_ptr.hpp>
 #include "include/encoding.h"
 #include "common/Formatter.h"
@@ -205,6 +206,7 @@ public:
       return "";
     }
     virtual ceph::buffer::list value() = 0;
+    virtual std::string_view value_as_sv() = 0;
     virtual int status() = 0;
     virtual ~SimplestIteratorImpl() {}
   };
@@ -252,6 +254,7 @@ public:
         return ceph::buffer::ptr();
       }
     }
+    virtual std::string_view value_as_sv() = 0;
     virtual int status() = 0;
     virtual size_t key_size() {
       return 0;
@@ -318,6 +321,9 @@ private:
     ceph::buffer::ptr value_as_ptr() override {
       return generic_iter->value_as_ptr();
     }
+    std::string_view value_as_sv() override {
+      return generic_iter->value_as_sv();
+    }
     int status() override {
       return generic_iter->status();
     }
index a653fa6398c29b182bb1a8d7f034014cc6d43ad9..e553e199c877bd6a5e977aefdd406cf50eb2ecae 100644 (file)
@@ -2249,6 +2249,12 @@ bufferptr RocksDBStore::RocksDBWholeSpaceIteratorImpl::value_as_ptr()
   return bufferptr(val.data(), val.size());
 }
 
+std::string_view RocksDBStore::RocksDBWholeSpaceIteratorImpl::value_as_sv()
+{
+  rocksdb::Slice val = dbiter->value();
+  return std::string_view{val.data(), val.size()};
+}
+
 int RocksDBStore::RocksDBWholeSpaceIteratorImpl::status()
 {
   return dbiter->status().ok() ? 0 : -1;
@@ -2340,6 +2346,10 @@ public:
     rocksdb::Slice val = dbiter->value();
     return bufferptr(val.data(), val.size());
   }
+  std::string_view value_as_sv() override {
+    rocksdb::Slice val = dbiter->value();
+    return std::string_view{val.data(), val.size()};
+  }
   int status() override {
     return dbiter->status().ok() ? 0 : -1;
   }
@@ -2677,6 +2687,15 @@ public:
     }
   }
 
+  std::string_view value_as_sv() override
+  {
+    if (smaller == on_main) {
+      return main->value_as_sv();
+    } else {
+      return current_shard->second->value_as_sv();
+    }
+  }
+
   int status() override
   {
     //because we already had to inspect key, it must be ok
@@ -3009,6 +3028,10 @@ public:
     rocksdb::Slice val = iters[0]->value();
     return bufferptr(val.data(), val.size());
   }
+  std::string_view value_as_sv() override {
+    rocksdb::Slice val = iters[0]->value();
+    return std::string_view{val.data(), val.size()};
+  }
   int status() override {
     return iters[0]->status().ok() ? 0 : -1;
   }
index a8468a25d4d4bc345cde3074864f9015589679e4..24330a1c78d836a0331e39a4bd259addacfc9bd8 100644 (file)
@@ -384,6 +384,7 @@ public:
     bool raw_key_is_prefixed(const std::string &prefix) override;
     ceph::bufferlist value() override;
     ceph::bufferptr value_as_ptr() override;
+    std::string_view value_as_sv() override;
     int status() override;
     size_t key_size() override;
     size_t value_size() override;
index 7da9a67be6251b4bc57b791ed2963f3079896727..65627b5f8187c2b6814e88d460db523dcbbf1e19 100644 (file)
@@ -519,6 +519,11 @@ bufferlist DBObjectMap::DBObjectMapIteratorImpl::value()
   return cur_iter->value();
 }
 
+std::string_view DBObjectMap::DBObjectMapIteratorImpl::value_as_sv()
+{
+  return cur_iter->value_as_sv();
+}
+
 int DBObjectMap::DBObjectMapIteratorImpl::status()
 {
   return r;
index 444f21eb81579f635c502a2eb766c9130078f6f6..1e1452010e78909ba8eecde2161e16b17bdce074 100644 (file)
@@ -393,6 +393,7 @@ private:
     int next() override { ceph_abort(); return 0; }
     std::string key() override { ceph_abort(); return ""; }
     ceph::buffer::list value() override { ceph_abort(); return ceph::buffer::list(); }
+    std::string_view value_as_sv() override { ceph_abort(); return std::string_view(); }
     int status() override { return 0; }
   };
 
@@ -431,6 +432,7 @@ private:
     int next() override;
     std::string key() override;
     ceph::buffer::list value() override;
+    std::string_view value_as_sv() override;
     int status() override;
 
     bool on_parent() {
index 4597b132b5c8874a2024df52aecbb873c00b9745..7c263397153d36319d69c01d10366680e7dfe1af 100644 (file)
@@ -5612,6 +5612,13 @@ bufferlist BlueStore::OmapIteratorImpl::value()
   return it->value();
 }
 
+std::string_view BlueStore::OmapIteratorImpl::value_as_sv()
+{
+  std::shared_lock l(c->lock);
+  ceph_assert(it->valid());
+  return it->value_as_sv();
+}
+
 
 // =====================================
 
index cf8222f53e0bd0608137edb662183365abd3bbba..06dc691b7f144764db4af3222c6137b1a728e9da 100644 (file)
@@ -1710,6 +1710,7 @@ private:
     int next() override;
     std::string key() override;
     ceph::buffer::list value() override;
+    std::string_view value_as_sv() override;
     std::string tail_key() override {
       return tail;
     }
index 7158486ca388527189c1fa4429c76dbaea3b3eb9..9cd1268023f9a7819a05c2c50e76f37886aec9e3 100644 (file)
@@ -1651,6 +1651,13 @@ bufferlist KStore::OmapIteratorImpl::value()
   return it->value();
 }
 
+std::string_view KStore::OmapIteratorImpl::value_as_sv()
+{
+  std::shared_lock l{c->lock};
+  ceph_assert(it->valid());
+  return it->value_as_sv();
+}
+
 int KStore::omap_get(
   CollectionHandle& ch,                ///< [in] Collection containing oid
   const ghobject_t &oid,   ///< [in] Object containing omap
index 9a9d413c66a82ca20967307908994ba898566d2f..4cef5b1039aca20903a84b2c8f21e572feaea9b7 100644 (file)
@@ -180,6 +180,7 @@ public:
     int next() override;
     std::string key() override;
     ceph::buffer::list value() override;
+    std::string_view value_as_sv() override;
     int status() override {
       return 0;
     }
index 89cb09361cf271c9f924f1a6587b5e04f9c56188..db8969b82c781e8d198dced273815a3379cf8cef 100644 (file)
@@ -622,6 +622,10 @@ public:
     std::lock_guard lock{o->omap_mutex};
     return it->second;
   }
+  std::string_view value_as_sv() override {
+    std::lock_guard lock{o->omap_mutex};
+    return std::string_view{it->second.c_str(), it->second.length()};
+  }
   int status() override {
     return 0;
   }
index 234e963397e31ea92c0748685d45f0995b00fecb..1dd9070d028769ea6415d894826e5d92285a2dd4 100644 (file)
@@ -150,6 +150,13 @@ public:
       return bufferlist();
   }
 
+  std::string_view value_as_sv() override {
+    if (valid())
+      return std::string_view{it->second.c_str(), it->second.length()};
+    else
+      return std::string_view();
+  }
+
   int status() override {
     return 0;
   }