From 8ba504dee834e2b486228ac51cab2b933a10271d Mon Sep 17 00:00:00 2001 From: Jianpeng Ma Date: Fri, 24 Oct 2014 16:11:15 +0800 Subject: [PATCH] buffer: Add _memcopy_count to track total count of memcopy by rebuild/rebuild_page_aligned/c_str. Using thie filed, we know the payload of rebuild/rebuild_page_aligned/c_str and tune performance accroding. Signed-off-by: Jianpeng Ma Reviewed-by: Sage Weil --- src/common/buffer.cc | 3 +++ src/include/buffer.h | 11 ++++++----- src/os/FileJournal.cc | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/common/buffer.cc b/src/common/buffer.cc index cd434417098..f50d103e479 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -955,6 +955,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; void buffer::list::swap(list& other) { std::swap(_len, other._len); + std::swap(_memcopy_count, other._memcopy_count); _buffers.swap(other._buffers); append_buffer.swap(other.append_buffer); //last_p.swap(other.last_p); @@ -1111,6 +1112,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; nb.copy_in(pos, it->length(), it->c_str()); pos += it->length(); } + _memcopy_count += pos; _buffers.clear(); _buffers.push_back(nb); } @@ -1150,6 +1152,7 @@ void buffer::list::rebuild_aligned(unsigned align) if (!(unaligned.is_contiguous() && unaligned._buffers.front().is_aligned(align))) { ptr nb(buffer::create_aligned(unaligned._len, align)); unaligned.rebuild(nb); + _memcopy_count += unaligned._len; } _buffers.insert(p, unaligned._buffers.front()); } diff --git a/src/include/buffer.h b/src/include/buffer.h index 7f23f8db440..0c917302f6b 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -241,7 +241,7 @@ public: // my private bits std::list _buffers; unsigned _len; - + unsigned _memcopy_count; //the total of memcopy using rebuild(). ptr append_buffer; // where i put small appends. public: @@ -317,14 +317,14 @@ public: public: // cons/des - list() : _len(0), last_p(this) {} - list(unsigned prealloc) : _len(0), last_p(this) { + list() : _len(0), _memcopy_count(0), last_p(this) {} + list(unsigned prealloc) : _len(0), _memcopy_count(0), last_p(this) { append_buffer = buffer::create(prealloc); append_buffer.set_length(0); // unused, so far. } ~list() {} - list(const list& other) : _buffers(other._buffers), _len(other._len), last_p(this) { } + list(const list& other) : _buffers(other._buffers), _len(other._len), _memcopy_count(other._memcopy_count),last_p(this) { } list& operator= (const list& other) { if (this != &other) { _buffers = other._buffers; @@ -333,8 +333,8 @@ public: return *this; } + unsigned get_memcopy_count() const {return _memcopy_count; } const std::list& buffers() const { return _buffers; } - void swap(list& other); unsigned length() const { #if 0 @@ -363,6 +363,7 @@ public: void clear() { _buffers.clear(); _len = 0; + _memcopy_count = 0; last_p = begin(); } void push_front(ptr& bp) { diff --git a/src/os/FileJournal.cc b/src/os/FileJournal.cc index f8f898d5bdd..f97b06b7a81 100644 --- a/src/os/FileJournal.cc +++ b/src/os/FileJournal.cc @@ -927,6 +927,7 @@ void FileJournal::align_bl(off64_t pos, bufferlist& bl) if (directio && (!bl.is_page_aligned() || !bl.is_n_page_sized())) { bl.rebuild_page_aligned(); + dout(10) << __func__ << " total memcopy: " << bl.get_memcopy_count() << dendl; if ((bl.length() & ~CEPH_PAGE_MASK) != 0 || (pos & ~CEPH_PAGE_MASK) != 0) dout(0) << "rebuild_page_aligned failed, " << bl << dendl;