From: Haomai Wang Date: Mon, 1 Feb 2016 05:55:52 +0000 (+0800) Subject: misc: using move construct to avoid extra atomic inc/dec X-Git-Tag: v10.0.4~61^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0305ceef5294c5c723650b237ab8218834e523d2;p=ceph.git misc: using move construct to avoid extra atomic inc/dec Signed-off-by: Haomai Wang --- diff --git a/src/common/SloppyCRCMap.h b/src/common/SloppyCRCMap.h index c07b4d9bb9d4..34642a325394 100644 --- a/src/common/SloppyCRCMap.h +++ b/src/common/SloppyCRCMap.h @@ -34,9 +34,7 @@ public: //zero_crc = ceph_crc32c(0xffffffff, NULL, block_size); if (b) { bufferlist bl; - bufferptr bp(block_size); - bp.zero(); - bl.append(bp); + bl.append_zero(block_size); zero_crc = bl.crc32c(crc_iv); } else { zero_crc = crc_iv; diff --git a/src/erasure-code/ErasureCode.cc b/src/erasure-code/ErasureCode.cc index 6d83d44385fe..eaacb246932c 100644 --- a/src/erasure-code/ErasureCode.cc +++ b/src/erasure-code/ErasureCode.cc @@ -93,12 +93,12 @@ int ErasureCode::encode_prepare(const bufferlist &raw, raw.copy((k - padded_chunks) * blocksize, remainder, buf.c_str()); buf.zero(remainder, blocksize - remainder); - encoded[chunk_index(k-padded_chunks)].push_back(buf); + encoded[chunk_index(k-padded_chunks)].push_back(std::move(buf)); for (unsigned int i = k - padded_chunks + 1; i < k; i++) { bufferptr buf(buffer::create_aligned(blocksize, SIMD_ALIGN)); buf.zero(); - encoded[chunk_index(i)].push_back(buf); + encoded[chunk_index(i)].push_back(std::move(buf)); } } for (unsigned int i = k; i < k + m; i++) { diff --git a/src/librbd/librbd.cc b/src/librbd/librbd.cc index 0b76ebae0524..4a47ab25760a 100644 --- a/src/librbd/librbd.cc +++ b/src/librbd/librbd.cc @@ -968,7 +968,7 @@ namespace librbd { ImageCtx *ictx = (ImageCtx *)ctx; tracepoint(librbd, read_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, ofs, len); bufferptr ptr(len); - bl.push_back(ptr); + bl.push_back(std::move(ptr)); int r = ictx->aio_work_queue->read(ofs, len, bl.c_str(), 0); tracepoint(librbd, read_exit, r); return r; @@ -980,7 +980,7 @@ namespace librbd { tracepoint(librbd, read2_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, ofs, len, op_flags); bufferptr ptr(len); - bl.push_back(ptr); + bl.push_back(std::move(ptr)); int r = ictx->aio_work_queue->read(ofs, len, bl.c_str(), op_flags); tracepoint(librbd, read_exit, r); return r; diff --git a/src/msg/async/AsyncConnection.cc b/src/msg/async/AsyncConnection.cc index 89caaa23a7e9..654467a3aa07 100644 --- a/src/msg/async/AsyncConnection.cc +++ b/src/msg/async/AsyncConnection.cc @@ -161,19 +161,16 @@ static void alloc_aligned_buffer(bufferlist& data, unsigned len, unsigned off) // head unsigned head = 0; head = MIN(CEPH_PAGE_SIZE - (off & ~CEPH_PAGE_MASK), left); - bufferptr bp = buffer::create(head); - data.push_back(bp); + data.push_back(buffer::create(head)); left -= head; } unsigned middle = left & CEPH_PAGE_MASK; if (middle > 0) { - bufferptr bp = buffer::create_page_aligned(middle); - data.push_back(bp); + data.push_back(buffer::create_page_aligned(middle)); left -= middle; } if (left) { - bufferptr bp = buffer::create(left); - data.push_back(bp); + data.push_back(buffer::create(left)); } } @@ -727,10 +724,9 @@ void AsyncConnection::process() // read front unsigned front_len = current_header.front_len; if (front_len) { - if (!front.length()) { - bufferptr ptr = buffer::create(front_len); - front.push_back(ptr); - } + if (!front.length()) + front.push_back(buffer::create(front_len)); + r = read_until(front_len, front.c_str()); if (r < 0) { ldout(async_msgr->cct, 1) << __func__ << " read message front failed" << dendl; @@ -750,10 +746,9 @@ void AsyncConnection::process() // read middle unsigned middle_len = current_header.middle_len; if (middle_len) { - if (!middle.length()) { - bufferptr ptr = buffer::create(middle_len); - middle.push_back(ptr); - } + if (!middle.length()) + middle.push_back(buffer::create(middle_len)); + r = read_until(middle_len, middle.c_str()); if (r < 0) { ldout(async_msgr->cct, 1) << __func__ << " read message middle failed" << dendl; diff --git a/src/msg/simple/Pipe.cc b/src/msg/simple/Pipe.cc index 89c8b8f24cd2..9fc3431588f6 100644 --- a/src/msg/simple/Pipe.cc +++ b/src/msg/simple/Pipe.cc @@ -333,7 +333,7 @@ int Pipe::accept() } { bufferptr tp(sizeof(peer_addr)); - addrbl.push_back(tp); + addrbl.push_back(std::move(tp)); } if (tcp_read(addrbl.c_str(), addrbl.length()) < 0) { ldout(msgr->cct,10) << "accept couldn't read peer_addr" << dendl; @@ -371,7 +371,7 @@ int Pipe::accept() ldout(msgr->cct,10) << "accept couldn't read connect authorizer" << dendl; goto fail_unlocked; } - authorizer.push_back(bp); + authorizer.push_back(std::move(bp)); authorizer_reply.clear(); } @@ -948,7 +948,7 @@ int Pipe::connect() int wirelen = sizeof(__u32) * 2 + sizeof(ceph_sockaddr_storage); bufferptr p(wirelen * 2); #endif - addrbl.push_back(p); + addrbl.push_back(std::move(p)); } if (tcp_read(addrbl.c_str(), addrbl.length()) < 0) { ldout(msgr->cct,2) << "connect couldn't read peer addrs, " << cpp_strerror(errno) << dendl; @@ -1875,19 +1875,16 @@ static void alloc_aligned_buffer(bufferlist& data, unsigned len, unsigned off) // head unsigned head = 0; head = MIN(CEPH_PAGE_SIZE - (off & ~CEPH_PAGE_MASK), left); - bufferptr bp = buffer::create(head); - data.push_back(bp); + data.push_back(buffer::create(head)); left -= head; } unsigned middle = left & CEPH_PAGE_MASK; if (middle > 0) { - bufferptr bp = buffer::create_page_aligned(middle); - data.push_back(bp); + data.push_back(buffer::create_page_aligned(middle)); left -= middle; } if (left) { - bufferptr bp = buffer::create(left); - data.push_back(bp); + data.push_back(buffer::create(left)); } } @@ -1975,7 +1972,7 @@ int Pipe::read_message(Message **pm, AuthSessionHandler* auth_handler) bufferptr bp = buffer::create(front_len); if (tcp_read(bp.c_str(), front_len) < 0) goto out_dethrottle; - front.push_back(bp); + front.push_back(std::move(bp)); ldout(msgr->cct,20) << "reader got front " << front.length() << dendl; } @@ -1985,7 +1982,7 @@ int Pipe::read_message(Message **pm, AuthSessionHandler* auth_handler) bufferptr bp = buffer::create(middle_len); if (tcp_read(bp.c_str(), middle_len) < 0) goto out_dethrottle; - middle.push_back(bp); + middle.push_back(std::move(bp)); ldout(msgr->cct,20) << "reader got middle " << middle.length() << dendl; } diff --git a/src/os/FuseStore.cc b/src/os/FuseStore.cc index 86c028f043ab..0849865af69a 100644 --- a/src/os/FuseStore.cc +++ b/src/os/FuseStore.cc @@ -809,9 +809,7 @@ static int os_write(const char *path, const char *buf, size_t size, } else { final.claim_append(*pbl); size_t zlen = offset - final.length(); - bufferptr z(zlen); - z.zero(); - final.append(z); + final.append_zero(zlen); } } final.append(buf, size); diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index dbee7c809ce4..3c0b13cdabc3 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -304,9 +304,7 @@ int BlueFS::_write_super() uint32_t crc = bl.crc32c(-1); ::encode(crc, bl); assert(bl.length() <= get_super_length()); - bufferptr z(get_super_length() - bl.length()); - z.zero(); - bl.append(z); + bl.append_zero(get_super_length() - bl.length()); bl.rebuild(); IOContext ioc(NULL); @@ -889,12 +887,8 @@ void BlueFS::_pad_bl(bufferlist& bl) { uint64_t partial = bl.length() % super.block_size; if (partial) { - bufferptr z(super.block_size - partial); - dout(10) << __func__ << " padding with " << z.length() << " zeros" << dendl; - z.zero(); - bufferlist zbl; - zbl.append(z); - bl.append(z); + dout(10) << __func__ << " padding with " << super.block_size - partial << " zeros" << dendl; + bl.append_zero(super.block_size - partial); } } @@ -1038,9 +1032,7 @@ int BlueFS::_flush_range(FileWriter *h, uint64_t offset, uint64_t length) dout(20) << __func__ << " caching tail of " << tail << " and padding block with zeros" << dendl; h->tail_block.substr_of(bl, bl.length() - tail, tail); - bufferptr z(super.block_size - tail); - z.zero(); - t.append(z); + t.append_zero(super.block_size - tail); } bdev[p->bdev]->aio_write(p->offset + x_off, t, h->iocv[p->bdev], true); bloff += x_len; diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index d0a1451ae68a..7ff14ff8fc8f 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -860,7 +860,7 @@ int BlueStore::_write_bdev_label(string path, bluestore_bdev_label_t label) assert(bl.length() <= BDEV_LABEL_BLOCK_SIZE); bufferptr z(BDEV_LABEL_BLOCK_SIZE - bl.length()); z.zero(); - bl.append(z); + bl.append(std::move(z)); int fd = ::open(path.c_str(), O_WRONLY); if (fd < 0) { @@ -2597,9 +2597,7 @@ int BlueStore::_do_read( // unwritten (zero) extent dout(30) << __func__ << " data " << bp->first << ": " << bp->second << ", use " << x_len << " zeros" << dendl; - bufferptr bp(x_len); - bp.zero(); - bl.push_back(bp); + bl.append_zero(x_len); } offset += x_len; length -= x_len; @@ -2616,9 +2614,7 @@ int BlueStore::_do_read( // zero. dout(30) << __func__ << " zero " << offset << "~" << x_len << dendl; - bufferptr bp(x_len); - bp.zero(); - bl.push_back(bp); + bl.append_zero(x_len); offset += x_len; length -= x_len; continue; @@ -5529,10 +5525,8 @@ int BlueStore::_do_write_zero( uint64_t offset, uint64_t length) { - bufferptr z(length); - z.zero(); bufferlist zl; - zl.push_back(z); + zl.append_zero(length); return _do_write(txc, c, o, offset, length, zl, 0); } diff --git a/src/os/bluestore/KernelDevice.cc b/src/os/bluestore/KernelDevice.cc index 9dfa820b148e..7f262d72c28b 100644 --- a/src/os/bluestore/KernelDevice.cc +++ b/src/os/bluestore/KernelDevice.cc @@ -461,7 +461,7 @@ int KernelDevice::read(uint64_t off, uint64_t len, bufferlist *pbl, goto out; } pbl->clear(); - pbl->push_back(p); + pbl->push_back(std::move(p)); dout(40) << "data: "; pbl->hexdump(*_dout); diff --git a/src/os/bluestore/NVMEDevice.cc b/src/os/bluestore/NVMEDevice.cc index 9d0eb63a6038..bd2639b1b999 100644 --- a/src/os/bluestore/NVMEDevice.cc +++ b/src/os/bluestore/NVMEDevice.cc @@ -829,7 +829,7 @@ int NVMEDevice::read(uint64_t off, uint64_t len, bufferlist *pbl, dout(10) << __func__ << " read from buffer " << copied << dendl; } pbl->clear(); - pbl->push_back(p); + pbl->push_back(std::move(p)); r = t->return_code; rte_free(t->buf); diff --git a/src/os/filestore/FileJournal.cc b/src/os/filestore/FileJournal.cc index 2b41cf440d19..7763c6f95f4d 100644 --- a/src/os/filestore/FileJournal.cc +++ b/src/os/filestore/FileJournal.cc @@ -766,7 +766,7 @@ int FileJournal::read_header(header_t *hdr) const memset(bpdata, 0, bp.length() - r); } - bl.push_back(bp); + bl.push_back(std::move(bp)); try { bufferlist::iterator p = bl.begin(); @@ -1885,7 +1885,7 @@ void FileJournal::wrap_read_bl( << r << dendl; ceph_abort(); } - bl->push_back(bp); + bl->push_back(std::move(bp)); pos += len; olen -= len; } diff --git a/src/os/filestore/FileStore.cc b/src/os/filestore/FileStore.cc index f7f7f5757fd1..1390b02633ec 100644 --- a/src/os/filestore/FileStore.cc +++ b/src/os/filestore/FileStore.cc @@ -1164,7 +1164,7 @@ int FileStore::read_superblock() } bufferlist bl; - bl.push_back(bp); + bl.push_back(std::move(bp)); bufferlist::iterator i = bl.begin(); ::decode(superblock, i); return 0; @@ -1186,7 +1186,7 @@ int FileStore::version_stamp_is_valid(uint32_t *version) return ret; } bufferlist bl; - bl.push_back(bp); + bl.push_back(std::move(bp)); bufferlist::iterator i = bl.begin(); ::decode(*version, i); dout(10) << __func__ << " was " << *version << " vs target " @@ -2969,7 +2969,7 @@ int FileStore::read( return got; } bptr.set_length(got); // properly size the buffer - bl.push_back(bptr); // put it in the target bufferlist + bl.push_back(std::move(bptr)); // put it in the target bufferlist #ifdef HAVE_POSIX_FADVISE if (op_flags & CEPH_OSD_OP_FLAG_FADVISE_DONTNEED) @@ -3278,10 +3278,8 @@ int FileStore::_zero(const coll_t& cid, const ghobject_t& oid, uint64_t offset, // write zeros.. yuck! dout(20) << "zero FALLOC_FL_PUNCH_HOLE not supported, falling back to writing zeros" << dendl; { - bufferptr bp(len); - bp.zero(); bufferlist bl; - bl.push_back(bp); + bl.append_zero(len); ret = _write(cid, oid, offset, len, bl); } @@ -4421,7 +4419,7 @@ int FileStore::collection_getattr(const coll_t& c, const char *name, bufferlist& goto out; } r = _fgetattr(fd, n, bp); - bl.push_back(bp); + bl.push_back(std::move(bp)); VOID_TEMP_FAILURE_RETRY(::close(fd)); out: dout(10) << "collection_getattr " << fn << " '" << name << "' = " << r << dendl; diff --git a/src/os/filestore/GenericFileStoreBackend.cc b/src/os/filestore/GenericFileStoreBackend.cc index d62d6221b3f0..d4c2a52ea5ed 100644 --- a/src/os/filestore/GenericFileStoreBackend.cc +++ b/src/os/filestore/GenericFileStoreBackend.cc @@ -344,7 +344,7 @@ int GenericFileStoreBackend::_crc_load_or_init(int fd, SloppyCRCMap *cm) } } bufferlist bl; - bl.append(bp); + bl.append(std::move(bp)); bufferlist::iterator p = bl.begin(); try { ::decode(*cm, p); diff --git a/src/os/fs/FS.cc b/src/os/fs/FS.cc index b7c7987997cf..187217087a3e 100644 --- a/src/os/fs/FS.cc +++ b/src/os/fs/FS.cc @@ -170,9 +170,7 @@ int FS::zero(int fd, uint64_t offset, uint64_t length) { // fall back to writing zeros bufferlist bl; - bufferptr bp(length); - bp.zero(); - bl.append(bp); + bl.append_zero(length); r = ::lseek64(fd, offset, SEEK_SET); if (r < 0) { r = -errno; diff --git a/src/os/fs/FS.h b/src/os/fs/FS.h index 4b09bcecd70f..63cd05f0b6b7 100644 --- a/src/os/fs/FS.h +++ b/src/os/fs/FS.h @@ -76,8 +76,8 @@ public: offset = _offset; length = len; bufferptr p = buffer::create_page_aligned(length); - bl.append(p); io_prep_pread(&iocb, fd, p.c_str(), length, offset); + bl.append(std::move(p)); } int get_return_value() { diff --git a/src/os/kstore/KStore.cc b/src/os/kstore/KStore.cc index d3d9b92b2570..0b63ed31c318 100644 --- a/src/os/kstore/KStore.cc +++ b/src/os/kstore/KStore.cc @@ -1541,9 +1541,7 @@ int KStore::_do_read( length = o->onode.size - offset; } if (stripe_size == 0) { - bufferptr z(length); - z.zero(); - bl.append(z); + bl.append_zero(length); r = length; goto out; } @@ -1571,17 +1569,13 @@ int KStore::_do_read( dout(30) << __func__ << " taking " << stripe_off << "~" << l << dendl; } if (l < swant) { - bufferptr z(swant - l); - z.zero(); - bl.append(z); - dout(30) << __func__ << " adding " << z.length() << " zeros" << dendl; + bl.append_zero(swant - l); + dout(30) << __func__ << " adding " << swant - l << " zeros" << dendl; } } } else { dout(30) << __func__ << " generating " << swant << " zeros" << dendl; - bufferptr z(swant); - z.zero(); - bl.append(z); + bl.append_zero(swant); } offset += swant; length -= swant; @@ -2945,10 +2939,8 @@ int KStore::_do_write(TransContext *txc, bl.substr_of(prev, 0, p); } if (p < offset_rem) { - bufferptr z(offset_rem - p); - dout(20) << __func__ << " add leading " << z.length() << " zeros" << dendl; - z.zero(); - bl.append(z); + dout(20) << __func__ << " add leading " << offset_rem - p << " zeros" << dendl; + bl.append_zero(offset_rem - p); } } unsigned use = stripe_size - offset_rem; @@ -3039,10 +3031,9 @@ int KStore::_zero(TransContext *txc, dout(20) << __func__ << " truncated stripe " << pos - stripe_off << " to " << bl.length() << dendl; } else { - bufferptr z(end - (pos - stripe_off + bl.length())); - z.zero(); - bl.append(z); - dout(20) << __func__ << " adding " << z.length() << " of zeros" << dendl; + auto len = end - (pos - stripe_off + bl.length()); + bl.append_zero(len); + dout(20) << __func__ << " adding " << len << " of zeros" << dendl; if (stripe.length() > bl.length()) { unsigned l = stripe.length() - bl.length(); bufferlist t; diff --git a/src/os/memstore/MemStore.cc b/src/os/memstore/MemStore.cc index 30694c4a3b55..cd0cd3610e87 100644 --- a/src/os/memstore/MemStore.cc +++ b/src/os/memstore/MemStore.cc @@ -1030,10 +1030,8 @@ int MemStore::_zero(const coll_t& cid, const ghobject_t& oid, { dout(10) << __func__ << " " << cid << " " << oid << " " << offset << "~" << len << dendl; - bufferptr bp(len); - bp.zero(); bufferlist bl; - bl.push_back(bp); + bl.append_zero(len); return _write(cid, oid, offset, len, bl); } @@ -1422,9 +1420,7 @@ int MemStore::BufferlistObject::write(uint64_t offset, const bufferlist &src) newdata.substr_of(data, 0, offset); } else { newdata.substr_of(data, 0, get_size()); - bufferptr bp(offset - get_size()); - bp.zero(); - newdata.append(bp); + newdata.append(offset - get_size()); } newdata.append(src); @@ -1469,9 +1465,7 @@ int MemStore::BufferlistObject::truncate(uint64_t size) } else if (get_size() == size) { // do nothing } else { - bufferptr bp(size - get_size()); - bp.zero(); - data.append(bp); + data.append_zero(size - get_size()); } return 0; } @@ -1532,7 +1526,7 @@ int MemStore::PageSetObject::read(uint64_t offset, uint64_t len, bufferlist& bl) tls_pages.clear(); // drop page refs - bl.append(buf); + bl.append(std::move(buf)); return len; } diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 7fb5b6fbb1b5..9b2f0dcb4e80 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -5304,7 +5304,7 @@ void OSD::do_command(Connection *con, ceph_tid_t tid, vector& cmd, buffe bufferlist bl; bufferptr bp(osize); bp.zero(); - bl.push_back(bp); + bl.push_back(std::move(bp)); bl.rebuild_page_aligned(); for (int i=0; i& cmd, buffe bufferlist bl; bufferptr bp(bsize); bp.zero(); - bl.push_back(bp); + bl.push_back(std::move(bp)); bl.rebuild_page_aligned(); { diff --git a/src/osd/PGBackend.cc b/src/osd/PGBackend.cc index 13515d70b673..85bd78b708bd 100644 --- a/src/osd/PGBackend.cc +++ b/src/osd/PGBackend.cc @@ -186,7 +186,7 @@ int PGBackend::objects_get_attr( bp); if (r >= 0 && out) { out->clear(); - out->push_back(bp); + out->push_back(std::move(bp)); } return r; } diff --git a/src/osdc/ObjectCacher.cc b/src/osdc/ObjectCacher.cc index acf6004e446d..f7ae589c3611 100644 --- a/src/osdc/ObjectCacher.cc +++ b/src/osdc/ObjectCacher.cc @@ -724,12 +724,10 @@ void ObjectCacher::bh_read_finish(int64_t poolid, sobject_t oid, << dendl; if (r >= 0 && bl.length() < length) { - bufferptr bp(length - bl.length()); - bp.zero(); ldout(cct, 7) << "bh_read_finish " << oid << " padding " << start << "~" - << length << " with " << bp.length() << " bytes of zeroes" + << length << " with " << length - bl.length() << " bytes of zeroes" << dendl; - bl.push_back(bp); + bl.append_zero(length - bl.length()); } list ls; @@ -1459,9 +1457,7 @@ int ObjectCacher::_readx(OSDRead *rd, ObjectSet *oset, Context *onfinish, // put substr here first, since substr_of clobbers, and we // may get multiple bh's at this stripe_map position if (bh->is_zero()) { - bufferptr bp(len); - bp.zero(); - stripe_map[f_it->first].push_back(bp); + stripe_map[f_it->first].append_zero(len); } else { bit.substr_of(bh->bl, opos - bh->start(), diff --git a/src/osdc/Striper.cc b/src/osdc/Striper.cc index 9a35ffe82653..4395106eceef 100644 --- a/src/osdc/Striper.cc +++ b/src/osdc/Striper.cc @@ -369,9 +369,7 @@ void Striper::StripedReadResult::assemble_result(CephContext *cct, size_t len = p->second.first.length(); if (len < p->second.second) { if (zero_tail || bl.length()) { - bufferptr bp(p->second.second - len); - bp.zero(); - bl.push_front(bp); + bl.append_zero(p->second.second - len); bl.claim_prepend(p->second.first); } else { bl.claim_prepend(p->second.first);