#include "common/debug.h"
#include "common/errno.h"
+#include "common/perf_counters.h"
#include "BlockDevice.h"
#include "Allocator.h"
#include "StupidAllocator.h"
#define dout_prefix *_dout << "bluefs "
BlueFS::BlueFS()
- : ino_last(0),
+ : logger(NULL),
+ ino_last(0),
log_seq(0),
log_writer(NULL),
bdev(MAX_BDEV),
}
}
+void BlueFS::_init_logger()
+{
+ PerfCountersBuilder b(g_ceph_context, "BlueFS",
+ l_bluefs_first, l_bluefs_last);
+ b.add_u64_counter(l_bluefs_gift_bytes, "gift_bytes", "Bytes gifted from BlueStore");
+ b.add_u64_counter(l_bluefs_reclaim_bytes, "reclaim_bytes", "Bytes reclaimed by BlueStore");
+ b.add_u64(l_bluefs_db_total_bytes, "db_total_bytes", "Total bytes (main db device)");
+ b.add_u64(l_bluefs_db_free_bytes, "db_free_bytes", "Free bytes (main db device)");
+ b.add_u64(l_bluefs_wal_total_bytes, "wal_total_bytes", "Total bytes (wal device)");
+ b.add_u64(l_bluefs_wal_free_bytes, "wal_free_bytes", "Free bytes (wal device)");
+ b.add_u64(l_bluefs_slow_total_bytes, "slow_total_bytes", "Total bytes (slow device)");
+ b.add_u64(l_bluefs_slow_free_bytes, "slow_free_bytes", "Free bytes (slow device)");
+ b.add_u64(l_bluefs_num_files, "num_files", "File count");
+ b.add_u64(l_bluefs_log_bytes, "log_bytes", "Size of the metadata log");
+ b.add_u64_counter(l_bluefs_log_compactions, "log_compactions", "Compactions of the metadata log");
+ b.add_u64_counter(l_bluefs_logged_bytes, "logged_bytes", "Bytes written to the metadata log");
+ logger = b.create_perf_counters();
+ g_ceph_context->get_perfcounters_collection()->add(logger);
+}
+
+void BlueFS::_shutdown_logger()
+{
+ g_ceph_context->get_perfcounters_collection()->remove(logger);
+ delete logger;
+}
+
+void BlueFS::_update_logger_stats()
+{
+ // we must be holding the lock
+ logger->set(l_bluefs_num_files, file_map.size());
+ logger->set(l_bluefs_log_bytes, log_writer->file->fnode.size);
+
+ if (alloc[BDEV_WAL]) {
+ logger->set(l_bluefs_wal_total_bytes, block_total[BDEV_WAL]);
+ logger->set(l_bluefs_wal_free_bytes, alloc[BDEV_WAL]->get_free());
+ }
+ if (alloc[BDEV_DB]) {
+ logger->set(l_bluefs_db_total_bytes, block_total[BDEV_DB]);
+ logger->set(l_bluefs_db_free_bytes, alloc[BDEV_DB]->get_free());
+ }
+ if (alloc[BDEV_SLOW]) {
+ logger->set(l_bluefs_slow_total_bytes, block_total[BDEV_SLOW]);
+ logger->set(l_bluefs_slow_free_bytes, alloc[BDEV_SLOW]->get_free());
+ }
+}
+
/*static void aio_cb(void *priv, void *priv2)
{
BlueFS *fs = static_cast<BlueFS*>(priv);
assert(r == 0);
alloc[id]->init_add_free(offset, length);
}
+
+ if (logger)
+ logger->inc(l_bluefs_gift_bytes, length);
dout(10) << __func__ << " done" << dendl;
}
r = _flush_log();
assert(r == 0);
+ if (logger)
+ logger->inc(l_bluefs_reclaim_bytes, *length);
dout(1) << __func__ << " bdev " << id << " want " << want
<< " got " << *offset << "~" << *length << dendl;
return 0;
<< dendl;
_init_alloc();
+ _init_logger();
super.version = 1;
super.block_size = bdev[BDEV_DB]->get_block_size();
block_all.clear();
block_total.clear();
_stop_alloc();
+ _shutdown_logger();
dout(10) << __func__ << " success" << dendl;
return 0;
assert(log_writer->file->fnode.ino == 1);
log_writer->pos = log_writer->file->fnode.size;
dout(10) << __func__ << " log write pos set to " << log_writer->pos << dendl;
+
+ _init_logger();
return 0;
out:
dir_map.clear();
super = bluefs_super_t();
log_t.clear();
+ _shutdown_logger();
}
int BlueFS::fsck()
for (auto& r : old_extents) {
alloc[r.bdev]->release(r.offset, r.length);
}
+
+ logger->inc(l_bluefs_log_compactions);
}
void BlueFS::_pad_bl(bufferlist& bl)
_pad_bl(bl);
log_writer->append(bl);
+ logger->inc(l_bluefs_logged_bytes, bl.length());
+
log_t.clear();
log_t.seq = 0; // just so debug output is less confusing
dirty_files.erase(p++);
}
+ _update_logger_stats();
+
return 0;
}
#include "boost/intrusive/list.hpp"
#include <boost/intrusive_ptr.hpp>
+class PerfCounters;
+
class Allocator;
+enum {
+ l_bluefs_first = 732600,
+ l_bluefs_gift_bytes,
+ l_bluefs_reclaim_bytes,
+ l_bluefs_db_total_bytes,
+ l_bluefs_db_free_bytes,
+ l_bluefs_wal_total_bytes,
+ l_bluefs_wal_free_bytes,
+ l_bluefs_slow_total_bytes,
+ l_bluefs_slow_free_bytes,
+ l_bluefs_num_files,
+ l_bluefs_log_bytes,
+ l_bluefs_log_compactions,
+ l_bluefs_logged_bytes,
+ l_bluefs_last,
+};
+
class BlueFS {
public:
static constexpr unsigned MAX_BDEV = 3;
private:
std::mutex lock;
+ PerfCounters *logger;
+
// cache
map<string, DirRef> dir_map; ///< dirname -> Dir
ceph::unordered_map<uint64_t,FileRef> file_map; ///< ino -> File
vector<uint64_t> block_total; ///< sum of block_all
vector<Allocator*> alloc; ///< allocators for bdevs
+ void _init_logger();
+ void _shutdown_logger();
+ void _update_logger_stats();
+
void _init_alloc();
void _stop_alloc();