]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
filejournal: use single shared zeroed buffer for alignment padding
authorSage Weil <sage@newdream.net>
Wed, 18 Nov 2009 20:18:17 +0000 (12:18 -0800)
committerSage Weil <sage@newdream.net>
Thu, 19 Nov 2009 00:25:35 +0000 (16:25 -0800)
Avoids lots of mallocs and memsets (one for every journal event).

src/os/FileJournal.cc
src/os/FileJournal.h

index 623d60280a3918648ac32d32d6a2251a59d3e49f..9b6c50c74a140a118f4ad321a6e515ecd6f5df30 100644 (file)
@@ -83,6 +83,10 @@ int FileJournal::_open(bool forwrite, bool create)
 #endif
   }
 
+  // static zeroed buffer for alignment padding
+  zero_buf = new char[header.alignment];
+  memset(zero_buf, 0, header.alignment);
+
   dout(2) << "_open " << fn << " fd " << fd 
          << ": " << max_size << " bytes, block size " << block_size << dendl;
 
@@ -397,8 +401,7 @@ void FileJournal::prepare_multi_write(bufferlist& bl)
     // pad...
     if (queue_pos % header.alignment) {
       int pad = header.alignment - (queue_pos % header.alignment);
-      bufferptr bp(pad);
-      bp.zero();
+      bufferptr bp = buffer::create_static(pad, zero_buf);
       bl.push_back(bp);
       queue_pos += pad;
       //dout(20) << "   padding with " << pad << " bytes, queue_pos now " << queue_pos << dendl;
index ab64eeac4707fad085e3d9f474e372656b77e173..171bb914d0d5d017656cb83c1351cfd956a0a2e2 100644 (file)
@@ -65,6 +65,8 @@ public:
 private:
   string fn;
 
+  char *zero_buf;
+
   off64_t max_size;
   size_t block_size;
   bool directio;
@@ -134,6 +136,7 @@ private:
  public:
   FileJournal(__u64 fsid, Finisher *fin, Cond *sync_cond, const char *f, bool dio=false) : 
     Journal(fsid, fin, sync_cond), fn(f),
+    zero_buf(NULL),
     max_size(0), block_size(0),
     directio(dio),
     writing(false), must_write_header(false),
@@ -143,7 +146,9 @@ private:
     fd(-1),
     write_lock("FileJournal::write_lock"),
     write_stop(false), write_thread(this) { }
-  ~FileJournal() {}
+  ~FileJournal() {
+    delete zero_buf;
+  }
 
   int create();
   int open(__u64 last_seq);