{extent_types_t::TEST_BLOCK_PHYSICAL, ext_label("TEST_BLOCK_PHYSICAL")}
};
+ auto counter_label = sm::label("counter");
+ std::map<std::string, sm::label_instance> labels_by_counter {
+ {"EXTENTS", counter_label("EXTENTS")},
+ {"BYTES", counter_label("BYTES")},
+ {"DELTA_BYTES", counter_label("DELTA_BYTES")},
+ };
+
/*
* trans_created
*/
{"FRESH", effort_label("FRESH")},
};
- auto counter_label = sm::label("counter");
- std::map<std::string, sm::label_instance> labels_by_counter {
- {"EXTENTS", counter_label("EXTENTS")},
- {"BYTES", counter_label("BYTES")},
- {"DELTA_BYTES", counter_label("DELTA_BYTES")},
- };
-
auto register_effort =
[this, &labels_by_src, &labels_by_effort, &labels_by_counter]
(const char* category,
register_read_effort_successful(counter_name, value);
}
}
+
+ /**
+ * Cached extents (including placeholders)
+ */
+ metrics.add_group(
+ "cache",
+ {
+ sm::make_counter(
+ "cached_extents",
+ [this] {
+ return extents.size();
+ },
+ sm::description("total number of cached extents"),
+ {labels_by_counter.find("EXTENTS")->second}
+ ),
+ sm::make_counter(
+ "cached_extents",
+ [this] {
+ return extents.get_bytes();
+ },
+ sm::description("total bytes of cached extents"),
+ {labels_by_counter.find("BYTES")->second}
+ ),
+ }
+ );
}
void Cache::add_extent(CachedExtentRef ref)
void clear() {
extent_index.clear();
+ bytes = 0;
}
void insert(CachedExtent &extent) {
extent.get_length());
ceph_assert(a == b);
- extent_index.insert(extent);
+ [[maybe_unused]] auto [iter, inserted] = extent_index.insert(extent);
+ assert(inserted);
extent.parent_index = this;
+
+ bytes += extent.get_length();
}
void erase(CachedExtent &extent) {
assert(extent.parent_index);
- extent_index.erase(extent);
+ auto erased = extent_index.erase(extent);
extent.parent_index = nullptr;
+
+ if (erased) {
+ bytes -= extent.get_length();
+ }
}
void replace(CachedExtent &to, CachedExtent &from) {
+ assert(to.get_length() == from.get_length());
extent_index.replace_node(extent_index.s_iterator_to(from), to);
from.parent_index = nullptr;
to.parent_index = this;
return extent_index.end();
}
- void merge(ExtentIndex &&other) {
- for (auto it = other.extent_index.begin();
- it != other.extent_index.end();
- ) {
- auto &ext = *it;
- ++it;
- other.extent_index.erase(ext);
- extent_index.insert(ext);
- }
+ auto size() const {
+ return extent_index.size();
}
- ~ExtentIndex() { assert(extent_index.empty()); }
+ auto get_bytes() const {
+ return bytes;
+ }
+
+ ~ExtentIndex() {
+ assert(extent_index.empty());
+ assert(bytes == 0);
+ }
+
+private:
+ uint64_t bytes = 0;
};
class LogicalCachedExtent;