From 63b61817c5f63473b5a0f27a21d91a80be22552d Mon Sep 17 00:00:00 2001 From: Tudor Bosman Date: Thu, 9 May 2013 14:27:56 -0700 Subject: [PATCH] convert RecordIO to pwritev Summary: zero-copy Test Plan: record_io_test Reviewed By: lucian@fb.com FB internal diff: D806813 --- folly/io/RecordIO.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/folly/io/RecordIO.cpp b/folly/io/RecordIO.cpp index 5eba9bc7..69bea4de 100644 --- a/folly/io/RecordIO.cpp +++ b/folly/io/RecordIO.cpp @@ -50,17 +50,14 @@ void RecordIOWriter::write(std::unique_ptr buf) { return; // nothing to do } - // TODO(tudorb): Maybe use pwritev, but for now we're copying everything in - // one place. - buf->unshare(); - buf->coalesce(); - DCHECK_EQ(buf->length(), totalLength); + DCHECK_EQ(buf->computeChainDataLength(), totalLength); + auto iov = buf->getIov(); // We're going to write. Reserve space for ourselves. - off_t pos = filePos_.fetch_add(buf->length()); - ssize_t bytes = pwriteFull(file_.fd(), buf->data(), buf->length(), pos); + off_t pos = filePos_.fetch_add(totalLength); + ssize_t bytes = pwritevFull(file_.fd(), iov.data(), iov.size(), pos); checkUnixError(bytes, "pwrite() failed"); - DCHECK_EQ(bytes, buf->length()); + DCHECK_EQ(bytes, totalLength); } RecordIOReader::RecordIOReader(File file, uint32_t fileId) -- 2.34.1