Skip to content

Commit

Permalink
misc: using move construct to avoid extra atomic inc/dec
Browse files Browse the repository at this point in the history
Signed-off-by: Haomai Wang <haomai@xsky.com>
  • Loading branch information
yuyuyu101 committed Feb 1, 2016
1 parent 436b16f commit bc14cc2
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 110 deletions.
4 changes: 1 addition & 3 deletions src/common/SloppyCRCMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ class SloppyCRCMap {
//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;
Expand Down
4 changes: 2 additions & 2 deletions src/erasure-code/ErasureCode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
4 changes: 2 additions & 2 deletions src/librbd/librbd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
23 changes: 9 additions & 14 deletions src/msg/async/AsyncConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
19 changes: 8 additions & 11 deletions src/msg/simple/Pipe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1876,19 +1876,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));
}
}

Expand Down Expand Up @@ -1976,7 +1973,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;
}

Expand All @@ -1986,7 +1983,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;
}

Expand Down
4 changes: 1 addition & 3 deletions src/os/FuseStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 4 additions & 12 deletions src/os/bluestore/BlueFS.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand Down
14 changes: 4 additions & 10 deletions src/os/bluestore/BlueStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,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) {
Expand Down Expand Up @@ -2552,9 +2552,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;
Expand All @@ -2571,9 +2569,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;
Expand Down Expand Up @@ -5473,10 +5469,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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/os/filestore/FileJournal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 5 additions & 7 deletions src/os/filestore/FileStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 "
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/os/filestore/GenericFileStoreBackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions src/os/fs/FS.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/os/fs/FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ class FS {
void pread(uint64_t _offset, uint64_t len) {
offset = _offset;
length = len;
bufferptr p = buffer::create_page_aligned(length);
bl.append(p);
bl.append(buffer::create_page_aligned(length));
io_prep_pread(&iocb, fd, p.c_str(), length, offset);
}

Expand Down

0 comments on commit bc14cc2

Please sign in to comment.