Skip to content

Commit

Permalink
crimson/os/seastore/rbm: implement get_stat()
Browse files Browse the repository at this point in the history
Signed-off-by: Myoungwon Oh <[email protected]>
  • Loading branch information
myoungwon committed Mar 23, 2023
1 parent 4ca0190 commit 3c21cff
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/crimson/os/seastore/async_cleaner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,7 @@ void RBMCleaner::mark_space_used(
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;
Expand All @@ -1646,6 +1647,8 @@ void RBMCleaner::mark_space_free(
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;
Expand Down Expand Up @@ -1690,6 +1693,7 @@ RBMCleaner::clean_space_ret RBMCleaner::clean_space()
RBMCleaner::mount_ret RBMCleaner::mount()
{
stats = {};
register_metrics();
return seastar::do_with(
rb_group->get_rb_managers(),
[](auto &rbs) {
Expand Down Expand Up @@ -1783,4 +1787,20 @@ bool RBMCleaner::equals(const RBMSpaceTracker &_other) const
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")),
});
}

}
29 changes: 27 additions & 2 deletions src/crimson/os/seastore/async_cleaner.h
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,10 @@ class RBMCleaner : public AsyncCleaner {

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;
}

Expand Down Expand Up @@ -1687,7 +1690,27 @@ class RBMCleaner : public AsyncCleaner {
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
Expand Down Expand Up @@ -1722,6 +1745,8 @@ class RBMCleaner : public AsyncCleaner {
*/
uint64_t projected_used_bytes = 0;
} stats;
seastar::metrics::metric_group metrics;
void register_metrics();

ExtentCallbackInterface *extent_callback = nullptr;
BackgroundListener *background_callback = nullptr;
Expand Down
1 change: 1 addition & 0 deletions src/crimson/os/seastore/random_block_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class RandomBlockManager {
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>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ class BlockRBManager final : public RandomBlockManager {
return allocator->get_extent_state(addr, size);
}

size_t get_journal_size() const final {
return device->get_journal_size();
}

private:
/*
* this contains the number of bitmap blocks, free blocks and
Expand Down

0 comments on commit 3c21cff

Please sign in to comment.