From: Jun Su Date: Sun, 16 Feb 2020 14:26:44 +0000 (+0800) Subject: osd/bluestore: Avoid allocate Task on Heap X-Git-Tag: v15.1.1~396^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F33358%2Fhead;p=ceph.git osd/bluestore: Avoid allocate Task on Heap When the I/O is synced, we can allocate the task object on stack to avoid malloc calls. Signed-off-by: Jun Su --- diff --git a/src/os/bluestore/NVMEDevice.cc b/src/os/bluestore/NVMEDevice.cc index 39446ff7a71..2c3987f474f 100644 --- a/src/os/bluestore/NVMEDevice.cc +++ b/src/os/bluestore/NVMEDevice.cc @@ -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)