From 2cb286f99362f30bcd138e71e4799cdf7ba975e6 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 18 Nov 2009 12:18:17 -0800 Subject: [PATCH] filejournal: use single shared zeroed buffer for alignment padding Avoids lots of mallocs and memsets (one for every journal event). --- src/os/FileJournal.cc | 7 +++++-- src/os/FileJournal.h | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/os/FileJournal.cc b/src/os/FileJournal.cc index 623d60280a391..9b6c50c74a140 100644 --- a/src/os/FileJournal.cc +++ b/src/os/FileJournal.cc @@ -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; diff --git a/src/os/FileJournal.h b/src/os/FileJournal.h index ab64eeac4707f..171bb914d0d5d 100644 --- a/src/os/FileJournal.h +++ b/src/os/FileJournal.h @@ -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); -- 2.39.5