if (addr.get_device_id() == rbm->get_device_id()) {
if (rbm->get_start() <= addr) {
INFO("allocate addr: {} len: {}", addr, len);
+ stats.used_bytes += len;
rbm->mark_space_used(addr, len);
}
return;
if (addr.get_device_id() == rbm->get_device_id()) {
if (rbm->get_start() <= addr) {
INFO("free addr: {} len: {}", addr, len);
+ ceph_assert(stats.used_bytes >= len);
+ stats.used_bytes -= len;
rbm->mark_space_free(addr, len);
}
return;
RBMCleaner::mount_ret RBMCleaner::mount()
{
stats = {};
+ register_metrics();
return seastar::do_with(
rb_group->get_rb_managers(),
[](auto &rbs) {
return all_match;
}
+void RBMCleaner::register_metrics()
+{
+ namespace sm = seastar::metrics;
+
+ metrics.add_group("rbm_cleaner", {
+ sm::make_counter("total_bytes",
+ [this] { return get_total_bytes(); },
+ sm::description("the size of the space")),
+ sm::make_counter("available_bytes",
+ [this] { return get_total_bytes() - get_journal_bytes() - stats.used_bytes; },
+ sm::description("the size of the space is available")),
+ sm::make_counter("used_bytes", stats.used_bytes,
+ sm::description("the size of the space occupied by live extents")),
+ });
+}
+
}
store_statfs_t get_stat() const final {
store_statfs_t st;
- // TODO
+ st.total = get_total_bytes();
+ st.available = get_total_bytes() - get_journal_bytes() - stats.used_bytes;
+ st.allocated = get_journal_bytes() + stats.used_bytes;
+ st.data_stored = get_journal_bytes() + stats.used_bytes;
return st;
}
paddr_t alloc_paddr(extent_len_t length) {
// TODO: implement allocation strategy (dirty metadata and multiple devices)
auto rbs = rb_group->get_rb_managers();
- return rbs[0]->alloc_extent(length);
+ auto paddr = rbs[0]->alloc_extent(length);
+ stats.used_bytes += length;
+ return paddr;
+ }
+
+ size_t get_total_bytes() const {
+ auto rbs = rb_group->get_rb_managers();
+ size_t total = 0;
+ for (auto p : rbs) {
+ total += p->get_device()->get_available_size();
+ }
+ return total;
+ }
+
+ size_t get_journal_bytes() const {
+ auto rbs = rb_group->get_rb_managers();
+ size_t total = 0;
+ for (auto p : rbs) {
+ total += p->get_journal_size();
+ }
+ return total;
}
// Testing interfaces
*/
uint64_t projected_used_bytes = 0;
} stats;
+ seastar::metrics::metric_group metrics;
+ void register_metrics();
ExtentCallbackInterface *extent_callback = nullptr;
BackgroundListener *background_callback = nullptr;
virtual Device* get_device() = 0;
virtual paddr_t get_start() = 0;
virtual rbm_extent_state_t get_extent_state(paddr_t addr, size_t size) = 0;
+ virtual size_t get_journal_size() const = 0;
virtual ~RandomBlockManager() {}
};
using RandomBlockManagerRef = std::unique_ptr<RandomBlockManager>;