From: Piotr Dałek Date: Mon, 23 Apr 2018 14:34:30 +0000 (+0200) Subject: buffer: rework list::append_zero X-Git-Tag: v14.0.1~1223^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=01134da2f18d8b5819c4c80b10255ca08708b6c1;p=ceph.git buffer: rework list::append_zero Instead of blindly adding new bufferptrs, try to memset the remaining space in append_buffer and try appending that part to the list, possibly reducing number of needed bufferptrs in blocksize aligned bufferlists. If that won't be enough, have the additional bufferptrs page aligned. Additionally, don't create extra bufferptrs if there's no remaining zeros to append. Signed-off-by: Piotr Dałek --- diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 99f6ec9aaac..4fa201c17dc 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -1080,6 +1080,16 @@ public: return _len + _off; } + unsigned buffer::ptr::append_zeros(unsigned l) + { + assert(_raw); + assert(l <= unused_tail_length()); + char* c = _raw->data + _off + _len; + memset(c, 0, l); + _len += l; + return _len + _off; + } + void buffer::ptr::copy_in(unsigned o, unsigned l, const char *src) { copy_in(o, l, src, true); @@ -1994,9 +2004,17 @@ public: void buffer::list::append_zero(unsigned len) { - ptr bp(len); - bp.zero(false); - append(std::move(bp)); + unsigned need = std::min(append_buffer.unused_tail_length(), len); + if (need) { + append_buffer.append_zeros(need); + append(append_buffer, append_buffer.length() - need, need); + len -= need; + } + if (len) { + ptr bp = buffer::create_page_aligned(len); + bp.zero(false); + append(std::move(bp)); + } } diff --git a/src/include/buffer.h b/src/include/buffer.h index e110b74b2c0..38e86592fb7 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -349,6 +349,7 @@ namespace buffer CEPH_BUFFER_API { void zero(bool crc_reset); void zero(unsigned o, unsigned l); void zero(unsigned o, unsigned l, bool crc_reset); + unsigned append_zeros(unsigned l); };