]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/buffer: switch crc cache to single pair instead of map 18906/head
authorPiotr Dałek <piotr.dalek@corp.ovh.com>
Mon, 13 Nov 2017 13:49:07 +0000 (14:49 +0100)
committerPiotr Dałek <piotr.dalek@corp.ovh.com>
Mon, 13 Nov 2017 14:30:11 +0000 (15:30 +0100)
Most bufferptrs have just one entry in their caches, so it makes
perfect sense to store just that. As population and destruction of
std::map isn't free, it yields noticeable perf increase, around 12%
in case of bufferptrs containing just 4k of data, with more as the
bufferptrs get smaller.

Signed-off-by: Piotr Dałek <piotr.dalek@corp.ovh.com>
src/common/buffer.cc

index dc891e017460f07af197e97331390138b0a56ac4..48208bf38befc73e2d57a51a091b194aa03bf6bd 100644 (file)
@@ -173,8 +173,10 @@ using namespace ceph;
     std::atomic<unsigned> nref { 0 };
     int mempool;
 
+    std::pair<size_t, size_t> last_crc_offset {std::numeric_limits<size_t>::max(), std::numeric_limits<size_t>::max()};
+    std::pair<uint32_t, uint32_t> last_crc_val;
+
     mutable ceph::spinlock crc_spinlock;
-    map<pair<size_t, size_t>, pair<uint32_t, uint32_t> > crc_map;
 
     explicit raw(unsigned l, int mempool=mempool::mempool_buffer_anon)
       : data(NULL), len(l), nref(0), mempool(mempool) {
@@ -248,24 +250,22 @@ public:
     bool get_crc(const pair<size_t, size_t> &fromto,
          pair<uint32_t, uint32_t> *crc) const {
       std::lock_guard<decltype(crc_spinlock)> lg(crc_spinlock);
-      map<pair<size_t, size_t>, pair<uint32_t, uint32_t> >::const_iterator i =
-      crc_map.find(fromto);
-      if (i == crc_map.end()) {
-          return false;
+      if (last_crc_offset == fromto) {
+        *crc = last_crc_val;
+        return true;
       }
-      *crc = i->second;
-      return true;
+      return false;
     }
     void set_crc(const pair<size_t, size_t> &fromto,
          const pair<uint32_t, uint32_t> &crc) {
       std::lock_guard<decltype(crc_spinlock)> lg(crc_spinlock);
-      crc_map[fromto] = crc;
+      last_crc_offset = fromto;
+      last_crc_val = crc;
     }
     void invalidate_crc() {
       std::lock_guard<decltype(crc_spinlock)> lg(crc_spinlock);
-      if (crc_map.size() != 0) {
-        crc_map.clear();
-      }
+      last_crc_offset.first = std::numeric_limits<size_t>::max();
+      last_crc_offset.second = std::numeric_limits<size_t>::max();
     }
   };