# define bendl std::endl; }
#endif
- static std::atomic<uint64_t> buffer_total_alloc { 0 };
- static std::atomic<uint64_t> buffer_history_alloc_bytes { 0 };
- static std::atomic<uint64_t> buffer_history_alloc_num { 0 };
-
- const bool buffer_track_alloc = get_env_bool("CEPH_BUFFER_TRACK");
-
- namespace {
- void inc_total_alloc(unsigned len) {
- if (buffer_track_alloc)
- buffer_total_alloc += len;
- }
-
- void dec_total_alloc(unsigned len) {
- if (buffer_track_alloc)
- buffer_total_alloc -= len;
- }
-
- void inc_history_alloc(uint64_t len) {
- if (buffer_track_alloc) {
- buffer_history_alloc_bytes += len;
- buffer_history_alloc_num++;
- }
- }
- } // namespace
-
- int buffer::get_total_alloc() {
- return buffer_total_alloc;
- }
- uint64_t buffer::get_history_alloc_bytes() {
- return buffer_history_alloc_bytes;
- }
- uint64_t buffer::get_history_alloc_num() {
- return buffer_history_alloc_num;
- }
-
static std::atomic<unsigned> buffer_cached_crc { 0 };
static std::atomic<unsigned> buffer_cached_crc_adjusted { 0 };
static std::atomic<unsigned> buffer_missed_crc { 0 };
int mempool)
: raw(dataptr, l, mempool),
alignment(align) {
- inc_total_alloc(len);
- inc_history_alloc(len);
- }
- ~raw_combined() override {
- dec_total_alloc(len);
}
raw* clone_empty() override {
return create(len, alignment);
} else {
data = 0;
}
- inc_total_alloc(len);
- inc_history_alloc(len);
- bdout << "raw_malloc " << this << " alloc " << (void *)data << " " << l << " " << buffer::get_total_alloc() << bendl;
+ bdout << "raw_malloc " << this << " alloc " << (void *)data << " " << l << bendl;
}
raw_malloc(unsigned l, char *b) : raw(b, l) {
- inc_total_alloc(len);
- bdout << "raw_malloc " << this << " alloc " << (void *)data << " " << l << " " << buffer::get_total_alloc() << bendl;
+ bdout << "raw_malloc " << this << " alloc " << (void *)data << " " << l << bendl;
}
~raw_malloc() override {
free(data);
- dec_total_alloc(len);
- bdout << "raw_malloc " << this << " free " << (void *)data << " " << buffer::get_total_alloc() << bendl;
+ bdout << "raw_malloc " << this << " free " << (void *)data << " " << bendl;
}
raw* clone_empty() override {
return new raw_malloc(len);
#endif /* DARWIN */
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;
+ bdout << "raw_posix_aligned " << this << " alloc " << (void *)data
+ << " l=" << l << ", align=" << align << bendl;
}
~raw_posix_aligned() override {
::free(data);
- dec_total_alloc(len);
- bdout << "raw_posix_aligned " << this << " free " << (void *)data << " " << buffer::get_total_alloc() << bendl;
+ bdout << "raw_posix_aligned " << this << " free " << (void *)data << bendl;
}
raw* clone_empty() override {
return new raw_posix_aligned(len, align);
data = realdata + align - off;
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;
}
~raw_hack_aligned() {
delete[] realdata;
- dec_total_alloc(len+align-1);
}
raw* clone_empty() {
return new raw_hack_aligned(len, align);
data = new char[len];
else
data = 0;
- inc_total_alloc(len);
- inc_history_alloc(len);
- bdout << "raw_char " << this << " alloc " << (void *)data << " " << l << " " << buffer::get_total_alloc() << bendl;
+ bdout << "raw_char " << this << " alloc " << (void *)data << " " << l << bendl;
}
raw_char(unsigned l, char *b) : raw(b, l) {
- inc_total_alloc(len);
- bdout << "raw_char " << this << " alloc " << (void *)data << " " << l << " " << buffer::get_total_alloc() << bendl;
+ bdout << "raw_char " << this << " alloc " << (void *)data << " " << l << bendl;
}
~raw_char() override {
delete[] data;
- dec_total_alloc(len);
- bdout << "raw_char " << this << " free " << (void *)data << " " << buffer::get_total_alloc() << bendl;
+ bdout << "raw_char " << this << " free " << (void *)data << bendl;
}
raw* clone_empty() override {
return new raw_char(len);
MEMPOOL_CLASS_HELPERS();
explicit raw_claimed_char(unsigned l, char *b) : raw(b, l) {
- inc_total_alloc(len);
bdout << "raw_claimed_char " << this << " alloc " << (void *)data
- << " " << l << " " << buffer::get_total_alloc() << bendl;
+ << " " << l << bendl;
}
~raw_claimed_char() override {
- dec_total_alloc(len);
bdout << "raw_claimed_char " << this << " free " << (void *)data
- << " " << buffer::get_total_alloc() << bendl;
+ << bendl;
}
raw* clone_empty() override {
return new raw_char(len);
};
- /// total bytes allocated
- int get_total_alloc();
-
- /// history total bytes allocated
- uint64_t get_history_alloc_bytes();
-
- /// total num allocated
- uint64_t get_history_alloc_num();
-
- /// enable/disable alloc tracking
- void track_alloc(bool b);
-
/// count of cached crc hits (matching input)
int get_cached_crc();
/// count of cached crc hits (mismatching input, required adjustment)
<< ", rss " << last.get_rss()
<< ", heap " << last.get_heap()
<< ", baseline " << baseline.get_heap()
- << ", buffers " << (buffer::get_total_alloc() >> 10)
<< ", " << num_inodes_with_caps << " / " << CInode::count() << " inodes have caps"
<< ", " << Capability::count() << " caps, " << caps_per_inode << " caps per inode"
<< dendl;
mlogger->set(l_mdm_dns, CDentry::decrements());
mlogger->set(l_mdm_capa, Capability::increments());
mlogger->set(l_mdm_caps, Capability::decrements());
- mlogger->set(l_mdm_buf, buffer::get_total_alloc());
}
}
mdm_plb.add_u64_counter(l_mdm_capa, "cap+", "Capabilities added");
mdm_plb.add_u64_counter(l_mdm_caps, "cap-", "Capabilities removed");
mdm_plb.add_u64(l_mdm_heap, "heap", "Heap size");
- mdm_plb.add_u64(l_mdm_buf, "buf", "Buffer size");
mdm_plb.set_prio_default(PerfCountersBuilder::PRIO_DEBUGONLY);
mdm_plb.add_u64(l_mdm_rss, "rss", "RSS");
l_mdm_caps,
l_mdm_rss,
l_mdm_heap,
- l_mdm_buf,
l_mdm_last,
};
"rbt", PerfCountersBuilder::PRIO_INTERESTING);
osd_plb.add_u64(l_osd_loadavg, "loadavg", "CPU load");
- osd_plb.add_u64(l_osd_buf, "buffer_bytes", "Total allocated buffer size", NULL, 0, unit_t(UNIT_BYTES));
- osd_plb.add_u64(l_osd_history_alloc_bytes, "history_alloc_Mbytes", NULL, 0, unit_t(UNIT_BYTES));
- osd_plb.add_u64(l_osd_history_alloc_num, "history_alloc_num");
osd_plb.add_u64(
l_osd_cached_crc, "cached_crc", "Total number getting crc from crc_cache");
osd_plb.add_u64(
ceph_assert(tick_timer_lock.is_locked());
dout(10) << "tick_without_osd_lock" << 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());
logger->set(l_osd_cached_crc, buffer::get_cached_crc());
logger->set(l_osd_cached_crc_adjusted, buffer::get_cached_crc_adjusted());
logger->set(l_osd_missed_crc, buffer::get_missed_crc());
l_osd_rbytes,
l_osd_loadavg,
- l_osd_buf,
- l_osd_history_alloc_bytes,
- l_osd_history_alloc_num,
l_osd_cached_crc,
l_osd_cached_crc_adjusted,
l_osd_missed_crc,
#add_ceph_test(test_pidfile.sh ${CMAKE_CURRENT_SOURCE_DIR}/test_pidfile.sh)
add_ceph_test(smoke.sh ${CMAKE_CURRENT_SOURCE_DIR}/smoke.sh)
-add_ceph_test(unittest_bufferlist.sh ${CMAKE_SOURCE_DIR}/src/unittest_bufferlist.sh)
# XXX are these safe to remove? they used to be around for ceph-disk tox testing
set(env_vars_for_tox_tests
static char cmd[128];
TEST(Buffer, constructors) {
- bool ceph_buffer_track = get_env_bool("CEPH_BUFFER_TRACK");
unsigned len = 17;
- uint64_t history_alloc_bytes = 0;
- uint64_t history_alloc_num = 0;
//
// buffer::create
//
- if (ceph_buffer_track) {
- EXPECT_EQ(0, buffer::get_total_alloc());
- }
-
{
bufferptr ptr(buffer::create(len));
- history_alloc_bytes += len;
- history_alloc_num++;
EXPECT_EQ(len, ptr.length());
- if (ceph_buffer_track) {
- EXPECT_EQ(len, (unsigned)buffer::get_total_alloc());
- EXPECT_EQ(history_alloc_bytes, buffer::get_history_alloc_bytes());
- EXPECT_EQ(history_alloc_num, buffer::get_history_alloc_num());
- }
}
//
// buffer::claim_char
//
- if (ceph_buffer_track) {
- EXPECT_EQ(0, buffer::get_total_alloc());
- }
-
{
char* str = new char[len];
::memset(str, 'X', len);
bufferptr ptr(buffer::claim_char(len, str));
- if (ceph_buffer_track) {
- EXPECT_EQ(len, (unsigned)buffer::get_total_alloc());
- EXPECT_EQ(history_alloc_bytes, buffer::get_history_alloc_bytes());
- EXPECT_EQ(history_alloc_num, buffer::get_history_alloc_num());
- }
EXPECT_EQ(len, ptr.length());
EXPECT_EQ(str, ptr.c_str());
bufferptr clone = ptr.clone();
- history_alloc_bytes += len;
- history_alloc_num++;
EXPECT_EQ(0, ::memcmp(clone.c_str(), ptr.c_str(), len));
delete [] str;
}
//
// buffer::create_static
//
- if (ceph_buffer_track) {
- EXPECT_EQ(0, buffer::get_total_alloc());
- }
-
{
char* str = new char[len];
bufferptr ptr(buffer::create_static(len, str));
- if (ceph_buffer_track) {
- EXPECT_EQ(0, buffer::get_total_alloc());
- EXPECT_EQ(history_alloc_bytes, buffer::get_history_alloc_bytes());
- EXPECT_EQ(history_alloc_num, buffer::get_history_alloc_num());
- }
EXPECT_EQ(len, ptr.length());
EXPECT_EQ(str, ptr.c_str());
delete [] str;
//
// buffer::create_malloc
//
- if (ceph_buffer_track) {
- EXPECT_EQ(0, buffer::get_total_alloc());
- }
-
{
bufferptr ptr(buffer::create_malloc(len));
- history_alloc_bytes += len;
- history_alloc_num++;
- if (ceph_buffer_track) {
- EXPECT_EQ(len, (unsigned)buffer::get_total_alloc());
- EXPECT_EQ(history_alloc_bytes, buffer::get_history_alloc_bytes());
- EXPECT_EQ(history_alloc_num, buffer::get_history_alloc_num());
- }
EXPECT_EQ(len, ptr.length());
// this doesn't throw on my x86_64 wheezy box --sage
//EXPECT_THROW(buffer::create_malloc((unsigned)ULLONG_MAX), buffer::bad_alloc);
//
// buffer::claim_malloc
//
- if (ceph_buffer_track) {
- EXPECT_EQ(0, buffer::get_total_alloc());
- }
-
{
char* str = (char*)malloc(len);
::memset(str, 'X', len);
bufferptr ptr(buffer::claim_malloc(len, str));
- if (ceph_buffer_track) {
- EXPECT_EQ(len, (unsigned)buffer::get_total_alloc());
- EXPECT_EQ(history_alloc_bytes, buffer::get_history_alloc_bytes());
- EXPECT_EQ(history_alloc_num, buffer::get_history_alloc_num());
- }
EXPECT_EQ(len, ptr.length());
EXPECT_EQ(str, ptr.c_str());
bufferptr clone = ptr.clone();
- history_alloc_bytes += len;
- history_alloc_num++;
EXPECT_EQ(0, ::memcmp(clone.c_str(), ptr.c_str(), len));
}
//
// buffer::copy
//
- if (ceph_buffer_track) {
- EXPECT_EQ(0, buffer::get_total_alloc());
- }
-
{
const std::string expected(len, 'X');
bufferptr ptr(buffer::copy(expected.c_str(), expected.size()));
- history_alloc_bytes += len;
- history_alloc_num++;
- if (ceph_buffer_track) {
- EXPECT_EQ(len, (unsigned)buffer::get_total_alloc());
- EXPECT_EQ(history_alloc_bytes, buffer::get_history_alloc_bytes());
- EXPECT_EQ(history_alloc_num, buffer::get_history_alloc_num());
- }
EXPECT_NE(expected.c_str(), ptr.c_str());
EXPECT_EQ(0, ::memcmp(expected.c_str(), ptr.c_str(), len));
}
//
// buffer::create_page_aligned
//
- if (ceph_buffer_track) {
- EXPECT_EQ(0, buffer::get_total_alloc());
- }
-
{
bufferptr ptr(buffer::create_page_aligned(len));
- history_alloc_bytes += len;
- history_alloc_num++;
::memset(ptr.c_str(), 'X', len);
- if (ceph_buffer_track) {
- EXPECT_EQ(len, (unsigned)buffer::get_total_alloc());
- EXPECT_EQ(history_alloc_bytes, buffer::get_history_alloc_bytes());
- EXPECT_EQ(history_alloc_num, buffer::get_history_alloc_num());
- }
// doesn't throw on my x86_64 wheezy box --sage
//EXPECT_THROW(buffer::create_page_aligned((unsigned)ULLONG_MAX), buffer::bad_alloc);
#ifndef DARWIN
ASSERT_TRUE(ptr.is_page_aligned());
#endif // DARWIN
bufferptr clone = ptr.clone();
- history_alloc_bytes += len;
- history_alloc_num++;
EXPECT_EQ(0, ::memcmp(clone.c_str(), ptr.c_str(), len));
- if (ceph_buffer_track) {
- EXPECT_EQ(history_alloc_bytes, buffer::get_history_alloc_bytes());
- EXPECT_EQ(history_alloc_num, buffer::get_history_alloc_num());
- }
- }
- if (ceph_buffer_track) {
- EXPECT_EQ(0, buffer::get_total_alloc());
}
}
/*
* Local Variables:
* compile-command: "cd .. ; make unittest_bufferlist &&
- * ulimit -s unlimited ; CEPH_BUFFER_TRACK=true valgrind \
+ * ulimit -s unlimited ; valgrind \
* --max-stackframe=20000000 --tool=memcheck \
* ./unittest_bufferlist # --gtest_filter=BufferList.constructors"
* End:
+++ /dev/null
-#!/bin/sh
-#
-# Ceph - scalable distributed file system
-#
-# Copyright (C) 2013 Cloudwatt <libre.licensing@cloudwatt.com>
-#
-# Author: Loic Dachary <loic@dachary.org>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU Library Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Library Public License for more details.
-#
-CEPH_BUFFER_TRACK=true unittest_bufferlist