From: Piotr Dałek Date: Thu, 16 Jul 2015 09:04:34 +0000 (+0200) Subject: buffer.cc: add possibility to omit crc cache invalidation X-Git-Tag: v9.1.0~333^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d34e0415d76f646018e2a19f6c6227eb0c2ec5c3;p=ceph.git buffer.cc: add possibility to omit crc cache invalidation In some cases, it might be worthwile to either not invalidate crc cache at all, or postpone it until we're done with other tasks (for example, after doing a lot of copy_in into single bufferptr instead of invalid after each of copy_in). This reduces bufferptr lock usage and in turn, decreases cpu utilization. This change adds the optional crc_reset arg (which defaults to true) so only new/aware code will use this feature. Signed-off-by: Piotr Dałek --- diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 2bf68934e03d..dba06ee05d1e 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -941,28 +941,30 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; return _len + _off; } - void buffer::ptr::copy_in(unsigned o, unsigned l, const char *src) + void buffer::ptr::copy_in(unsigned o, unsigned l, const char *src, bool crc_reset) { assert(_raw); assert(o <= _len); assert(o+l <= _len); - _raw->invalidate_crc(); + if (crc_reset) + _raw->invalidate_crc(); memcpy(c_str()+o, src, l); } - void buffer::ptr::zero() + void buffer::ptr::zero(bool crc_reset) { - _raw->invalidate_crc(); + if (crc_reset) + _raw->invalidate_crc(); memset(c_str(), 0, _len); } - void buffer::ptr::zero(unsigned o, unsigned l) + void buffer::ptr::zero(unsigned o, unsigned l, bool crc_reset) { assert(o+l <= _len); - _raw->invalidate_crc(); + if (crc_reset) + _raw->invalidate_crc(); memset(c_str()+o, 0, l); } - bool buffer::ptr::can_zero_copy() const { return _raw->can_zero_copy(); @@ -1138,7 +1140,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; // copy data in - void buffer::list::iterator::copy_in(unsigned len, const char *src) + void buffer::list::iterator::copy_in(unsigned len, const char *src, bool crc_reset) { // copy if (p == ls->end()) @@ -1150,7 +1152,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; unsigned howmuch = p->length() - p_off; if (len < howmuch) howmuch = len; - p->copy_in(p_off, howmuch, src); + p->copy_in(p_off, howmuch, src, crc_reset); src += howmuch; len -= howmuch; @@ -1462,14 +1464,14 @@ void buffer::list::rebuild_page_aligned() return last_p.copy(len, dest); } - void buffer::list::copy_in(unsigned off, unsigned len, const char *src) + void buffer::list::copy_in(unsigned off, unsigned len, const char *src, bool crc_reset) { if (off + len > length()) throw end_of_buffer(); if (last_p.get_off() != off) last_p.seek(off); - last_p.copy_in(len, src); + last_p.copy_in(len, src, crc_reset); } void buffer::list::copy_in(unsigned off, unsigned len, const list& src) diff --git a/src/include/buffer.h b/src/include/buffer.h index ad72d6a11ba6..90a1716ea049 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -241,9 +241,9 @@ public: unsigned append(char c); unsigned append(const char *p, unsigned l); - void copy_in(unsigned o, unsigned l, const char *src); - void zero(); - void zero(unsigned o, unsigned l); + void copy_in(unsigned o, unsigned l, const char *src, bool crc_reset = true); + void zero(bool crc_reset = true); + void zero(unsigned o, unsigned l, bool crc_reset = true); }; @@ -307,7 +307,7 @@ public: void copy_all(list &dest); // copy data in - void copy_in(unsigned len, const char *src); + void copy_in(unsigned len, const char *src, bool crc_reset = true); void copy_in(unsigned len, const list& otherl); }; @@ -442,7 +442,7 @@ public: void copy(unsigned off, unsigned len, char *dest) const; void copy(unsigned off, unsigned len, list &dest) const; void copy(unsigned off, unsigned len, std::string& dest) const; - void copy_in(unsigned off, unsigned len, const char *src); + void copy_in(unsigned off, unsigned len, const char *src, bool crc_reset = true); void copy_in(unsigned off, unsigned len, const list& src); void append(char c);