]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/bluestore: Avoid allocate Task on Heap 33358/head
authorJun Su <howard0su@gmail.com>
Sun, 16 Feb 2020 14:26:44 +0000 (22:26 +0800)
committerJun Su <howard0su@gmail.com>
Mon, 17 Feb 2020 00:57:27 +0000 (08:57 +0800)
When the I/O is synced, we can allocate the task object
on stack to avoid malloc calls.

Signed-off-by: Jun Su <howard0su@gmail.com>
src/os/bluestore/NVMEDevice.cc

index 39446ff7a717fbd25bc836adbb130d525884df00..2c3987f474f85bd64f453e9e6fba9470bfce1088 100644 (file)
@@ -928,22 +928,19 @@ int NVMEDevice::read(uint64_t off, uint64_t len, bufferlist *pbl,
   dout(5) << __func__ << " " << off << "~" << len << " ioc " << ioc << dendl;
   ceph_assert(is_valid_io(off, len));
 
-  Task *t = new Task(this, IOCommand::READ_COMMAND, off, len, 1);
+  Task t(this, IOCommand::READ_COMMAND, off, len, 1);
   bufferptr p = buffer::create_small_page_aligned(len);
-  int r = 0;
   char *buf = p.c_str();
 
   ceph_assert(ioc->nvme_task_first == nullptr);
   ceph_assert(ioc->nvme_task_last == nullptr);
-  make_read_tasks(this, off, ioc, buf, len, t, off, len);
+  make_read_tasks(this, off, ioc, buf, len, &t, off, len);
   dout(5) << __func__ << " " << off << "~" << len << dendl;
   aio_submit(ioc);
   ioc->aio_wait();
 
   pbl->push_back(std::move(p));
-  r = t->return_code;
-  delete t;
-  return r;
+  return t.return_code;
 }
 
 int NVMEDevice::aio_read(
@@ -974,16 +971,13 @@ int NVMEDevice::read_random(uint64_t off, uint64_t len, char *buf, bool buffered
   dout(5) << __func__ << " " << off << "~" << len
           << " aligned " << aligned_off << "~" << aligned_len << dendl;
   IOContext ioc(g_ceph_context, nullptr);
-  Task *t = new Task(this, IOCommand::READ_COMMAND, aligned_off, aligned_len, 1);
-  int r = 0;
+  Task t(this, IOCommand::READ_COMMAND, aligned_off, aligned_len, 1);
 
-  make_read_tasks(this, aligned_off, &ioc, buf, aligned_len, t, off, len);
+  make_read_tasks(this, aligned_off, &ioc, buf, aligned_len, &t, off, len);
   aio_submit(&ioc);
   ioc.aio_wait();
 
-  r = t->return_code;
-  delete t;
-  return r;
+  return t.return_code;
 }
 
 int NVMEDevice::invalidate_cache(uint64_t off, uint64_t len)