]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
FileJournal: reduce time wasted by bufferptr::zero 5114/head
authorPiotr Dałek <piotr.dalek@ts.fujitsu.com>
Wed, 1 Jul 2015 12:18:30 +0000 (14:18 +0200)
committerPiotr Dałek <piotr.dalek@ts.fujitsu.com>
Tue, 4 Aug 2015 07:26:43 +0000 (09:26 +0200)
bufferptr::zero(), apart from actual memset() call, also invalidates its
internal CRC cache, which is empty at the time, so no point to lock its
mutex, clear CRC cache, unlock mutex and memset() entire bufferptr. Also,
not entire bufferptr needs to be zeroed, so clear out just unused parts
of it.

Signed-off-by: Piotr Dałek <piotr.dalek@ts.fujitsu.com>
src/os/FileJournal.cc

index cf26e5d4f8e71bc3becab38de4fd52fd04ae2b0d..b4162f85dd26eb97bf1de2f9d3f26ceef5c42427 100644 (file)
@@ -746,8 +746,8 @@ int FileJournal::read_header(header_t *hdr) const
   bufferlist bl;
 
   buffer::ptr bp = buffer::create_page_aligned(block_size);
-  bp.zero();
-  int r = ::pread(fd, bp.c_str(), bp.length(), 0);
+  char* bpdata = bp.c_str();
+  int r = ::pread(fd, bpdata, bp.length(), 0);
 
   if (r < 0) {
     int err = errno;
@@ -755,6 +755,14 @@ int FileJournal::read_header(header_t *hdr) const
     return -err;
   }
 
+  // don't use bp.zero() here, because it also invalidates
+  // crc cache (which is not yet populated anyway)
+  if (bp.length() != (size_t)r) {
+      // r will be always less or equal than bp.length
+      bpdata += r;
+      memset(bpdata, 0, bp.length() - r);
+  }
+
   bl.push_back(bp);
 
   try {
@@ -793,8 +801,12 @@ bufferptr FileJournal::prepare_header()
   }
   ::encode(header, bl);
   bufferptr bp = buffer::create_page_aligned(get_top());
-  bp.zero();
-  memcpy(bp.c_str(), bl.c_str(), bl.length());
+  // don't use bp.zero() here, because it also invalidates
+  // crc cache (which is not yet populated anyway)
+  char* data = bp.c_str();
+  memcpy(data, bl.c_str(), bl.length());
+  data += bl.length();
+  memset(data, 0, bp.length()-bl.length());
   return bp;
 }