]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
buffer: rework list::append_zero
authorPiotr Dałek <piotr.dalek@corp.ovh.com>
Mon, 23 Apr 2018 14:34:30 +0000 (16:34 +0200)
committerPiotr Dałek <piotr.dalek@corp.ovh.com>
Wed, 25 Apr 2018 08:20:17 +0000 (10:20 +0200)
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 <piotr.dalek@corp.ovh.com>
src/common/buffer.cc
src/include/buffer.h

index 99f6ec9aaacad7a2c48d90c24823d3d25491d52e..4fa201c17dc37cc06b3a404443053cad3acb35e1 100644 (file)
@@ -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));
+    }
   }
 
   
index e110b74b2c0c09d30e075059ac57b01d3edb1d21..38e86592fb75c35c86672d544d0da36a311e783f 100644 (file)
@@ -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);
 
   };