From: Yan, Zheng Date: Tue, 12 May 2015 07:08:20 +0000 (+0800) Subject: client: invalidate kernel dcache when cache size exceeds limits X-Git-Tag: v9.0.2~152^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9591df35819ba8cdb7b7a07658fa04a61b8bb2b4;p=ceph.git client: invalidate kernel dcache when cache size exceeds limits make client try invalidating kernel dcache when its cache size exceeds "client_cache_size" config option. Signed-off-by: Yan, Zheng --- diff --git a/src/client/Client.cc b/src/client/Client.cc index de285676448..e18c77c728a 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -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 &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); + } +} + diff --git a/src/client/Client.h b/src/client/Client.h index 4430e565fac..36d3ef4dbda 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -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 &changed); }; #endif