]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: invalidate kernel dcache when cache size exceeds limits
authorYan, Zheng <zyan@redhat.com>
Tue, 12 May 2015 07:08:20 +0000 (15:08 +0800)
committerYan, Zheng <zyan@redhat.com>
Wed, 13 May 2015 03:24:49 +0000 (11:24 +0800)
make client try invalidating kernel dcache when its cache size
exceeds "client_cache_size" config option.

Signed-off-by: Yan, Zheng <zyan@redhat.com>
src/client/Client.cc
src/client/Client.h

index de285676448290f052c8bcde6111c93e8f1336a5..e18c77c728abc4024c96a24e56b2a4792a32d55a 100644 (file)
@@ -431,6 +431,8 @@ int Client::init()
 
   client_lock.Unlock();
 
+  cct->_conf->add_observer(this);
+
   AdminSocket* admin_socket = cct->get_admin_socket();
   int ret = admin_socket->register_command("mds_requests",
                                           "mds_requests",
@@ -485,6 +487,8 @@ void Client::shutdown()
 {
   ldout(cct, 1) << "shutdown" << dendl;
 
+  cct->_conf->remove_observer(this);
+
   AdminSocket* admin_socket = cct->get_admin_socket();
   admin_socket->unregister_command("mds_requests");
   admin_socket->unregister_command("mds_sessions");
@@ -543,7 +547,7 @@ void Client::shutdown()
 // ===================
 // metadata cache stuff
 
-void Client::trim_cache()
+void Client::trim_cache(bool trim_kernel_dcache)
 {
   ldout(cct, 20) << "trim_cache size " << lru.lru_get_size() << " max " << lru.lru_get_max() << dendl;
   unsigned last = 0;
@@ -560,6 +564,9 @@ void Client::trim_cache()
     trim_dentry(dn);
   }
 
+  if (trim_kernel_dcache && lru.lru_get_size() > lru.lru_get_max())
+    _invalidate_kernel_dcache();
+
   // hose root?
   if (lru.lru_get_size() == 0 && root && root->get_num_ref() == 0 && inode_map.size() == 1 + root_parents.size()) {
     ldout(cct, 15) << "trim_cache trimmed root " << root << dendl;
@@ -4948,6 +4955,7 @@ void Client::tick()
     check_caps(in, true);
   }
 
+  trim_cache(true);
 }
 
 void Client::renew_caps()
@@ -10870,3 +10878,23 @@ void Client::set_cap_epoch_barrier(epoch_t e)
   cap_epoch_barrier = e;
 }
 
+const char** Client::get_tracked_conf_keys() const
+{
+  static const char* keys[] = {
+    "client_cache_size",
+    "client_cache_mid",
+    NULL
+  };
+  return keys;
+}
+
+void Client::handle_conf_change(const struct md_config_t *conf,
+                               const std::set <std::string> &changed)
+{
+  if (changed.count("client_cache_size") ||
+      changed.count("client_cache_mid")) {
+    lru.lru_set_max(cct->_conf->client_cache_size);
+    lru.lru_set_midpoint(cct->_conf->client_cache_mid);
+  }
+}
+
index 4430e565faca747558e74bcf76e6350f81bed79f..36d3ef4dbdafb274e4f43a7609cc979c3e895e2d 100644 (file)
@@ -214,7 +214,7 @@ struct dir_result_t {
   }
 };
 
-class Client : public Dispatcher {
+class Client : public Dispatcher, public md_config_obs_t {
  public:
   using Dispatcher::cct;
 
@@ -439,7 +439,7 @@ protected:
   void touch_dn(Dentry *dn);
 
   // trim cache.
-  void trim_cache();
+  void trim_cache(bool trim_kernel_dcache=false);
   void trim_cache_for_reconnect(MetaSession *s);
   void trim_dentry(Dentry *dn);
   void trim_caps(MetaSession *s, int max);
@@ -966,6 +966,10 @@ public:
 
   void ll_register_callbacks(struct client_callback_args *args);
   int test_dentry_handling(bool can_invalidate);
+
+  virtual const char** get_tracked_conf_keys() const;
+  virtual void handle_conf_change(const struct md_config_t *conf,
+                                 const std::set <std::string> &changed);
 };
 
 #endif