From: Piotr Dałek Date: Mon, 13 Nov 2017 13:49:07 +0000 (+0100) Subject: common/buffer: switch crc cache to single pair instead of map X-Git-Tag: v13.0.2~556^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0c2f2dc3b47049655e4f8b581bb7a189ffd78918;p=ceph.git common/buffer: switch crc cache to single pair instead of map 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 --- diff --git a/src/common/buffer.cc b/src/common/buffer.cc index dc891e017460..48208bf38bef 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -173,8 +173,10 @@ using namespace ceph; std::atomic nref { 0 }; int mempool; + std::pair last_crc_offset {std::numeric_limits::max(), std::numeric_limits::max()}; + std::pair last_crc_val; + mutable ceph::spinlock crc_spinlock; - map, pair > 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 &fromto, pair *crc) const { std::lock_guard lg(crc_spinlock); - map, pair >::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 &fromto, const pair &crc) { std::lock_guard lg(crc_spinlock); - crc_map[fromto] = crc; + last_crc_offset = fromto; + last_crc_val = crc; } void invalidate_crc() { std::lock_guard lg(crc_spinlock); - if (crc_map.size() != 0) { - crc_map.clear(); - } + last_crc_offset.first = std::numeric_limits::max(); + last_crc_offset.second = std::numeric_limits::max(); } };