]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: implement flush_cache() method for Filestore
authorMohamad Gebai <mgebai@suse.com>
Thu, 27 Sep 2018 17:33:56 +0000 (13:33 -0400)
committerMohamad Gebai <mgebai@suse.com>
Wed, 10 Oct 2018 15:45:51 +0000 (11:45 -0400)
Signed-off-by: Mohamad Gebai <mgebai@suse.com>
src/os/ObjectStore.h
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h
src/os/filestore/FileStore.cc
src/os/filestore/FileStore.h
src/osd/OSD.cc

index 1ccfee6eb5c52575482934eed7bc8f3da052adf8..65b52f5346955d9bdd4941232d19ed9e9bc03897 100644 (file)
@@ -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;
index 2ff1d2ae49ba4d9813cbfc8b64cc3be1a90b28e1..8ae5567650ccc82d54587f8b0252891a9f197b5d 100644 (file)
@@ -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,
index 0f548e16f5d8ef707fb7d2f979c1b28b73564fe0..9fc3ebef74390b3f731dac23101dc0bfbbd8d17e 100644 (file)
@@ -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);
index 102eab53d547512c470f7d3cf8fa028f1bc127de..5e116d864af3f3cbb969854b8ad91c2beea05159 100644 (file)
@@ -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;
index 8077cb0183531ac2a5ca50feb1440bd1c18b40f1..e9e5ce603f74dd5008b94981015769d36719bd25 100644 (file)
@@ -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();
index 4deb1430ffe83894ba38399087046579d1a3f6e8..647a93537c2a86481d118d179aeadc63e12d09d1 100644 (file)
@@ -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);