From: Mohamad Gebai Date: Sun, 12 Aug 2018 15:43:15 +0000 (+0300) Subject: osd: add clear_cache and get_cache_object_count commands X-Git-Tag: v14.0.1~56^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=65767fbd353ad3acdd59ab944eeddb8959ac23bb;p=ceph.git osd: add clear_cache and get_cache_object_count commands Fixes: http://tracker.ceph.com/issues/24176 Signed-off-by: Mohamad Gebai --- diff --git a/src/common/shared_cache.hpp b/src/common/shared_cache.hpp index 283bff401c5a..7db8108c2550 100644 --- a/src/common/shared_cache.hpp +++ b/src/common/shared_cache.hpp @@ -123,6 +123,10 @@ public: } } + int get_count() { + return lru.size(); + } + /// adjust container comparator (for purposes of get_next sort order) void reset_comparator(C comp) { // get_next uses weak_refs; that's the only container we need to diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index 736cab460d3b..1ccfee6eb5c5 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -1481,6 +1481,9 @@ public: virtual void generate_db_histogram(Formatter *f) { } virtual void flush_cache() { } virtual void dump_perf_counters(Formatter *f) {} + virtual int get_cache_obj_count() { + return -1; + } virtual string get_type() = 0; diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 6c15953dd2da..0f548e16f5d8 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -2333,6 +2333,13 @@ public: int _fsck(bool deep, bool repair); void set_cache_shards(unsigned num) override; + int get_cache_obj_count() { + int count = 0; + for (auto i: cache_shards) { + count += i->_get_num_onodes(); + } + return count; + } int validate_hobject_key(const hobject_t &obj) const override { return 0; diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 3d4d6c35c899..4deb1430ffe8 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -6020,6 +6020,12 @@ COMMAND("compact", COMMAND("smart name=devid,type=CephString,req=False", "runs smartctl on this osd devices. ", "osd", "rw", "cli,rest") +COMMAND("clear_cache", + "Clear OSD caches", + "osd", "rw", "cli,rest") +COMMAND("get_cache_object_count", + "Get OSD caches object count", + "osd", "r", "cli,rest") }; void OSD::do_command( @@ -6496,6 +6502,46 @@ int OSD::_do_command( probe_smart(devid, ds); } + else if (prefix == "clear_cache") { + dout(20) << "clearing all caches" << dendl; + // Clear the objectstore's cache + store->flush_cache(); + // Clear osd map cache + { + Mutex::Locker l(service.map_cache_lock); + service.map_cache.clear(); + } + // Clear the objectcontext cache (per PG) + vector pgs; + _get_pgs(&pgs); + for (auto& pg: pgs) { + pg->clear_cache(); + } + } + + else if (prefix == "get_cache_object_count") { + int store_cache_count = store->get_cache_obj_count(); + int obj_ctx_count = 0; + int osd_map_count = service.map_cache.get_count(); + vector pgs; + _get_pgs(&pgs); + for (auto& pg: pgs) { + obj_ctx_count += pg->get_cache_obj_count(); + } + if (f) { + f->open_object_section("caches_object_count"); + f->dump_int("object_ctx", obj_ctx_count); + f->dump_int("objectstore_onode", store_cache_count); + f->dump_int("osd_map", osd_map_count); + f->close_section(); + f->flush(ds); + } else { + ds << "object_ctx: " << obj_ctx_count; + ds << "objectstore_onode: " << store_cache_count; + ds << "osd_map: " << osd_map_count; + } + } + else { ss << "unrecognized command '" << prefix << "'"; r = -EINVAL; diff --git a/src/osd/PG.h b/src/osd/PG.h index 3aa6b180ea50..dd1ba00ce320 100644 --- a/src/osd/PG.h +++ b/src/osd/PG.h @@ -458,6 +458,8 @@ public: OpRequestRef& op, ThreadPool::TPHandle &handle ) = 0; + virtual void clear_cache() = 0; + virtual int get_cache_obj_count() = 0; virtual void snap_trimmer(epoch_t epoch_queued) = 0; virtual int do_command( diff --git a/src/osd/PrimaryLogPG.cc b/src/osd/PrimaryLogPG.cc index 14aa42c13cdd..0c9ecbe80759 100644 --- a/src/osd/PrimaryLogPG.cc +++ b/src/osd/PrimaryLogPG.cc @@ -11954,6 +11954,11 @@ void PrimaryLogPG::clear_async_reads() } } +void PrimaryLogPG::clear_cache() +{ + object_contexts.clear(); +} + void PrimaryLogPG::on_shutdown() { dout(10) << __func__ << dendl; diff --git a/src/osd/PrimaryLogPG.h b/src/osd/PrimaryLogPG.h index 262341d32d03..3707bb984730 100644 --- a/src/osd/PrimaryLogPG.h +++ b/src/osd/PrimaryLogPG.h @@ -1435,6 +1435,10 @@ public: ConnectionRef conn, ceph_tid_t tid) override; + void clear_cache(); + int get_cache_obj_count() { + return object_contexts.get_count(); + } void do_request( OpRequestRef& op, ThreadPool::TPHandle &handle) override;