From: Greg Farnum Date: Mon, 3 Feb 2014 22:36:02 +0000 (-0800) Subject: FDCache: implement a basic sharding of the FDCache X-Git-Tag: v0.85~37^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a9f76d4303c02083200af1b7ce0b6ef3fefcd2c3;p=ceph.git FDCache: implement a basic sharding of the FDCache This is just a basic sharding. A more sophisticated implementation would rely on something other than luck for keeping the distribution equitable. The minimum FDCache shard size is 1. Signed-off-by: Greg Farnum Signed-off-by: Somnath Roy --- diff --git a/src/common/config_opts.h b/src/common/config_opts.h index ee4353f2af93..aff4f2563593 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -713,6 +713,7 @@ OPTION(filestore_split_multiple, OPT_INT, 2) OPTION(filestore_update_to, OPT_INT, 1000) OPTION(filestore_blackhole, OPT_BOOL, false) // drop any new transactions on the floor OPTION(filestore_fd_cache_size, OPT_INT, 128) // FD lru size +OPTION(filestore_fd_cache_shards, OPT_INT, 16) // FD number of shards OPTION(filestore_dump_file, OPT_STR, "") // file onto which store transaction dumps OPTION(filestore_kill_at, OPT_INT, 0) // inject a failure at the n'th opportunity OPTION(filestore_inject_stall, OPT_INT, 0) // artificially stall for N seconds in op queue thread diff --git a/src/os/FDCache.h b/src/os/FDCache.h index 712355b48192..39872f0af789 100644 --- a/src/os/FDCache.h +++ b/src/os/FDCache.h @@ -23,6 +23,7 @@ #include "common/Cond.h" #include "common/shared_cache.hpp" #include "include/compat.h" +#include "include/intarith.h" /** * FD Cache @@ -49,32 +50,42 @@ public: }; private: - SharedLRU registry; CephContext *cct; + const int registry_shards; + SharedLRU *registry; public: - FDCache(CephContext *cct) : cct(cct) { + FDCache(CephContext *cct) : cct(cct), + registry_shards(cct->_conf->filestore_fd_cache_shards) { assert(cct); cct->_conf->add_observer(this); - registry.set_size(cct->_conf->filestore_fd_cache_size); + registry = new SharedLRU[registry_shards]; + for (int i = 0; i < registry_shards; ++i) { + registry[i].set_size( + MAX((cct->_conf->filestore_fd_cache_size / registry_shards), 1)); + } } ~FDCache() { cct->_conf->remove_observer(this); + delete[] registry; } typedef ceph::shared_ptr FDRef; FDRef lookup(const ghobject_t &hoid) { - return registry.lookup(hoid); + int registry_id = hoid.hobj.hash % registry_shards; + return registry[registry_id].lookup(hoid); } FDRef add(const ghobject_t &hoid, int fd, bool *existed) { - return registry.add(hoid, new FD(fd), existed); + int registry_id = hoid.hobj.hash % registry_shards; + return registry[registry_id].add(hoid, new FD(fd), existed); } /// clear cached fd for hoid, subsequent lookups will get an empty FD void clear(const ghobject_t &hoid) { - registry.clear(hoid); - assert(!registry.lookup(hoid)); + int registry_id = hoid.hobj.hash % registry_shards; + registry[registry_id].clear(hoid); + assert(!registry[registry_id].lookup(hoid)); } /// md_config_obs_t @@ -88,7 +99,9 @@ public: void handle_conf_change(const md_config_t *conf, const std::set &changed) { if (changed.count("filestore_fd_cache_size")) { - registry.set_size(conf->filestore_fd_cache_size); + for (int i = 0; i < registry_shards; ++i) + registry[i].set_size( + MAX((conf->filestore_fd_cache_size / registry_shards), 1)); } }