From: Mohamad Gebai Date: Thu, 27 Sep 2018 17:33:56 +0000 (-0400) Subject: osd: implement flush_cache() method for Filestore X-Git-Tag: v14.0.1~56^2~7 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d6eed7bfee853962d012498c88cf18122128c5f7;p=ceph.git osd: implement flush_cache() method for Filestore Signed-off-by: Mohamad Gebai --- diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index 1ccfee6eb5c5..65b52f534695 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -1479,7 +1479,7 @@ public: virtual void get_db_statistics(Formatter *f) { } virtual void generate_db_histogram(Formatter *f) { } - virtual void flush_cache() { } + virtual int flush_cache() { return 0; } virtual void dump_perf_counters(Formatter *f) {} virtual int get_cache_obj_count() { return -1; diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 2ff1d2ae49ba..8ae5567650cc 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -12554,12 +12554,14 @@ void BlueStore::_flush_cache() // We use a best-effort policy instead, e.g., // we don't care if there are still some pinned onodes/data in the cache // after this command is completed. -void BlueStore::flush_cache() +int BlueStore::flush_cache() { dout(10) << __func__ << dendl; for (auto i : cache_shards) { i->trim_all(); } + + return 0; } void BlueStore::_apply_padding(uint64_t head_pad, diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 0f548e16f5d8..9fc3ebef7439 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -2356,7 +2356,7 @@ public: void get_db_statistics(Formatter *f) override; void generate_db_histogram(Formatter *f) override; void _flush_cache(); - void flush_cache() override; + int flush_cache() override; void dump_perf_counters(Formatter *f) override { f->open_object_section("perf_counters"); logger->dump_formatted(f, false); diff --git a/src/os/filestore/FileStore.cc b/src/os/filestore/FileStore.cc index 102eab53d547..5e116d864af3 100644 --- a/src/os/filestore/FileStore.cc +++ b/src/os/filestore/FileStore.cc @@ -1413,6 +1413,30 @@ int FileStore::version_stamp_is_valid(uint32_t *version) return 0; } +int FileStore::flush_cache() +{ + string drop_caches_file = "/proc/sys/vm/drop_caches"; + int drop_caches_fd = ::open(drop_caches_file.c_str(), O_WRONLY), ret = 0; + char buf[2] = "3"; + int len = strlen(buf); + + if (drop_caches_fd < 0) { + ret = -errno; + derr << __FUNC__ << ": failed to open " << drop_caches_file << ": " << cpp_strerror(ret) << dendl; + return ret; + } + + if (::write(drop_caches_fd, buf, len) < 0) { + ret = -errno; + derr << __FUNC__ << ": failed to write to " << drop_caches_file << ": " << cpp_strerror(ret) << dendl; + goto out; + } + +out: + ::close(drop_caches_fd); + return ret; +} + int FileStore::write_version_stamp() { dout(1) << __FUNC__ << ": " << target_version << dendl; diff --git a/src/os/filestore/FileStore.h b/src/os/filestore/FileStore.h index 8077cb018353..e9e5ce603f74 100644 --- a/src/os/filestore/FileStore.h +++ b/src/os/filestore/FileStore.h @@ -504,6 +504,7 @@ public: f->close_section(); } + int flush_cache() override; int write_version_stamp(); int version_stamp_is_valid(uint32_t *version); int update_version_stamp(); diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 4deb1430ffe8..647a93537c2a 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -6504,8 +6504,13 @@ int OSD::_do_command( else if (prefix == "clear_cache") { dout(20) << "clearing all caches" << dendl; - // Clear the objectstore's cache - store->flush_cache(); + // Clear the objectstore's cache - onode and buffer for Bluestore, + // system's pagecache for Filestore + r = store->flush_cache(); + if (r < 0) { + ds << "Error flushing objectstore cache: " << cpp_strerror(r); + goto out; + } // Clear osd map cache { Mutex::Locker l(service.map_cache_lock);