From: Xinze Chi Date: Thu, 8 Oct 2015 01:51:39 +0000 (+0800) Subject: common: perf counter for bufferlist history total alloc X-Git-Tag: v10.0.2~163^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4014e319c4a40c331c93a4eba0f6fb36364bdc8c;p=ceph.git common: perf counter for bufferlist history total alloc this is useful for tracking how many bytes malloc at bufferlist Signed-off-by: Xinze Chi --- diff --git a/src/common/buffer.cc b/src/common/buffer.cc index a7ed8883f0e5..f7b328c50466 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -48,6 +48,8 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; #endif static atomic_t buffer_total_alloc; + static atomic64_t buffer_history_alloc_bytes; + static atomic64_t buffer_history_alloc_num; const bool buffer_track_alloc = get_env_bool("CEPH_BUFFER_TRACK"); void buffer::inc_total_alloc(unsigned len) { @@ -58,9 +60,21 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; if (buffer_track_alloc) buffer_total_alloc.sub(len); } + void buffer::inc_history_alloc(uint64_t len) { + if (buffer_track_alloc) { + buffer_history_alloc_bytes.add(len); + buffer_history_alloc_num.inc(); + } + } int buffer::get_total_alloc() { return buffer_total_alloc.read(); } + uint64_t buffer::get_history_alloc_bytes() { + return buffer_history_alloc_bytes.read(); + } + uint64_t buffer::get_history_alloc_num() { + return buffer_history_alloc_num.read(); + } static atomic_t buffer_cached_crc; static atomic_t buffer_cached_crc_adjusted; @@ -227,6 +241,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; data = 0; } inc_total_alloc(len); + inc_history_alloc(len); bdout << "raw_malloc " << this << " alloc " << (void *)data << " " << l << " " << buffer::get_total_alloc() << bendl; } raw_malloc(unsigned l, char *b) : raw(b, l) { @@ -251,6 +266,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; if (!data) throw bad_alloc(); inc_total_alloc(len); + inc_history_alloc(len); bdout << "raw_mmap " << this << " alloc " << (void *)data << " " << l << " " << buffer::get_total_alloc() << bendl; } ~raw_mmap_pages() { @@ -280,6 +296,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; if (!data) throw bad_alloc(); inc_total_alloc(len); + inc_history_alloc(len); bdout << "raw_posix_aligned " << this << " alloc " << (void *)data << " l=" << l << ", align=" << align << " total_alloc=" << buffer::get_total_alloc() << bendl; } ~raw_posix_aligned() { @@ -307,6 +324,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; else data = realdata; inc_total_alloc(len+align-1); + inc_history_alloc(len+align-1); //cout << "hack aligned " << (unsigned)data //<< " in raw " << (unsigned)realdata //<< " off " << off << std::endl; @@ -356,6 +374,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; } inc_total_alloc(len); + inc_history_alloc(len); bdout << "raw_pipe " << this << " alloc " << len << " " << buffer::get_total_alloc() << bendl; } @@ -510,6 +529,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; else data = 0; inc_total_alloc(len); + inc_history_alloc(len); bdout << "raw_char " << this << " alloc " << (void *)data << " " << l << " " << buffer::get_total_alloc() << bendl; } raw_char(unsigned l, char *b) : raw(b, l) { diff --git a/src/include/buffer.h b/src/include/buffer.h index 854a28635812..7170def20f1a 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -101,6 +101,12 @@ public: /// total bytes allocated static int get_total_alloc(); + /// history total bytes allocated + static uint64_t get_history_alloc_bytes(); + + /// total num allocated + static uint64_t get_history_alloc_num(); + /// enable/disable alloc tracking static void track_alloc(bool b); @@ -120,6 +126,7 @@ private: /* hack for memory utilization debugging. */ static void inc_total_alloc(unsigned len); + static void inc_history_alloc(uint64_t len); static void dec_total_alloc(unsigned len); /* diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 09e4c570d15a..0dd6d7079af6 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -2175,6 +2175,8 @@ void OSD::create_logger() osd_plb.add_u64(l_osd_loadavg, "loadavg", "CPU load"); osd_plb.add_u64(l_osd_buf, "buffer_bytes", "Total allocated buffer size"); // total ceph::buffer bytes + osd_plb.add_u64(l_osd_history_alloc_bytes, "history_alloc_Mbytes"); // total ceph::buffer bytes in history + osd_plb.add_u64(l_osd_history_alloc_num, "history_alloc_num"); // total ceph::buffer num in history osd_plb.add_u64(l_osd_pg, "numpg", "Placement groups"); // num pgs osd_plb.add_u64(l_osd_pg_primary, "numpg_primary", "Placement groups for which this osd is primary"); // num primary pgs @@ -3966,6 +3968,8 @@ void OSD::tick() dout(5) << "tick" << dendl; logger->set(l_osd_buf, buffer::get_total_alloc()); + logger->set(l_osd_history_alloc_bytes, SHIFT_ROUND_UP(buffer::get_history_alloc_bytes(), 20)); + logger->set(l_osd_history_alloc_num, buffer::get_history_alloc_num()); if (is_active() || is_waiting_for_healthy()) { map_lock.get_read(); @@ -5886,6 +5890,8 @@ void OSD::_dispatch(Message *m) dout(20) << "_dispatch " << m << " " << *m << dendl; logger->set(l_osd_buf, buffer::get_total_alloc()); + logger->set(l_osd_history_alloc_bytes, SHIFT_ROUND_UP(buffer::get_history_alloc_bytes(), 20)); + logger->set(l_osd_history_alloc_num, buffer::get_history_alloc_num()); switch (m->get_type()) { @@ -5938,6 +5944,8 @@ void OSD::_dispatch(Message *m) } logger->set(l_osd_buf, buffer::get_total_alloc()); + logger->set(l_osd_history_alloc_bytes, SHIFT_ROUND_UP(buffer::get_history_alloc_bytes(), 20)); + logger->set(l_osd_history_alloc_num, buffer::get_history_alloc_num()); } diff --git a/src/osd/OSD.h b/src/osd/OSD.h index 996e7777af2f..029203af2d63 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -105,6 +105,8 @@ enum { l_osd_loadavg, l_osd_buf, + l_osd_history_alloc_bytes, + l_osd_history_alloc_num, l_osd_pg, l_osd_pg_primary,