]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
msg/async/AsyncConnection: combine multi alloc into one
authorHaomai Wang <haomai@xsky.com>
Thu, 9 Nov 2017 05:28:23 +0000 (13:28 +0800)
committerHaomai Wang <haomai@xsky.com>
Thu, 16 Nov 2017 04:38:49 +0000 (12:38 +0800)
Signed-off-by: Haomai Wang <haomai@xsky.com>
src/msg/async/AsyncConnection.cc

index a2abbce56297eb2e41ba1ea03f5b0ba7811b6de0..6a26bc096765006ef7aba3a787ef963980936a72 100644 (file)
@@ -101,22 +101,20 @@ class C_tick_wakeup : public EventCallback {
 static void alloc_aligned_buffer(bufferlist& data, unsigned len, unsigned off)
 {
   // create a buffer to read into that matches the data alignment
+  unsigned alloc_len = 0;
   unsigned left = len;
+  unsigned head = 0;
   if (off & ~CEPH_PAGE_MASK) {
     // head
-    unsigned head = 0;
+    alloc_len += CEPH_PAGE_SIZE;
     head = MIN(CEPH_PAGE_SIZE - (off & ~CEPH_PAGE_MASK), left);
-    data.push_back(buffer::create(head));
     left -= head;
   }
-  unsigned middle = left & CEPH_PAGE_MASK;
-  if (middle > 0) {
-    data.push_back(buffer::create_page_aligned(middle));
-    left -= middle;
-  }
-  if (left) {
-    data.push_back(buffer::create(left));
-  }
+  alloc_len += left;
+  bufferptr ptr(buffer::create_page_aligned(alloc_len));
+  if (head)
+    ptr.set_offset(CEPH_PAGE_SIZE - head);
+  data.push_back(std::move(ptr));
 }
 
 AsyncConnection::AsyncConnection(CephContext *cct, AsyncMessenger *m, DispatchQueue *q,