summaryrefslogtreecommitdiffstats
path: root/xlators/performance
diff options
context:
space:
mode:
authorDavid Wolinsky <davidiw@fb.com>2015-10-08 16:05:20 -0700
committerJeff Darcy <jeff@pl.atyp.us>2017-07-14 13:41:42 +0000
commitbc02e5423d097aff5280a849b7c6e6cf5d63ef96 (patch)
treec4901be6b501a5df5588ee46949b4bc5626c9063 /xlators/performance
parente8029ec1fc205b5dace0c29ae3d1fe5b960e54fc (diff)
[io-cache] cache statfs
Summary: cache calls to statfs - io-cache must be enabled - then enable statfs caching - also can configure an independent cache time Test Plan: unit test basic/cache.t Reviewers: rwareing, sshreyas Subscribers: rappleye Differential Revision: https://phabricator.fb.com/D2524471 Change-Id: I55e0a773f9e24c2358d6fbbabbaf58bd5bd89ffc Tasks: 8618383 Reviewed-on: https://review.gluster.org/17771 Smoke: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Jeff Darcy <jeff@pl.atyp.us> Tested-by: Jeff Darcy <jeff@pl.atyp.us> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Diffstat (limited to 'xlators/performance')
-rw-r--r--xlators/performance/io-cache/src/io-cache.c102
-rw-r--r--xlators/performance/io-cache/src/io-cache.h41
2 files changed, 127 insertions, 16 deletions
diff --git a/xlators/performance/io-cache/src/io-cache.c b/xlators/performance/io-cache/src/io-cache.c
index 98c37746921..f199b229bc2 100644
--- a/xlators/performance/io-cache/src/io-cache.c
+++ b/xlators/performance/io-cache/src/io-cache.c
@@ -1479,6 +1479,74 @@ ioc_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
return 0;
}
+int32_t
+ioc_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno,
+ struct statvfs *buf, dict_t *xdata)
+{
+ ioc_table_t *table = NULL;
+ struct ioc_statvfs *cache = NULL;
+
+ if (op_ret != 0)
+ goto out;
+
+ table = this->private;
+ cache = &table->statfs_cache;
+
+ LOCK (&cache->lock);
+
+ gettimeofday (&cache->tv, NULL);
+ cache->buf = *buf;
+
+ UNLOCK (&cache->lock);
+
+out:
+ STACK_UNWIND_STRICT (statfs, frame, op_ret, op_errno, buf, xdata);
+ return 0;
+}
+
+int
+ioc_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
+{
+ ioc_table_t *table = NULL;
+ struct ioc_statvfs *cache = NULL;
+ struct statvfs buf;
+ struct timeval tv = {0,};
+
+ table = this->private;
+ cache = &table->statfs_cache;
+
+ if (!cache->enabled)
+ goto disabled;
+
+ gettimeofday (&tv, NULL);
+
+ LOCK (&cache->lock);
+
+ if (time_elapsed (&tv, &cache->tv) >= cache->timeout) {
+ UNLOCK (&cache->lock);
+ goto uncached;
+ }
+
+ buf = cache->buf;
+
+ UNLOCK (&cache->lock);
+
+ STACK_UNWIND_STRICT (statfs, frame, 0, 0, &buf, xdata);
+
+ return 0;
+
+disabled:
+ STACK_WIND_TAIL (frame, FIRST_CHILD (frame->this),
+ FIRST_CHILD (frame->this)->fops->statfs, loc, xdata);
+ return 0;
+
+uncached:
+ STACK_WIND (frame, ioc_statfs_cbk,
+ FIRST_CHILD (frame->this),
+ FIRST_CHILD (frame->this)->fops->statfs, loc, xdata);
+ return 0;
+}
int32_t
ioc_get_priority_list (const char *opt_str, struct list_head *first)
@@ -1696,6 +1764,13 @@ reconfigure (xlator_t *this, dict_t *options)
}
table->cache_size = cache_size_new;
+ GF_OPTION_RECONF ("statfs-cache", table->statfs_cache.enabled,
+ options, bool, unlock);
+
+ GF_OPTION_RECONF ("statfs-cache-timeout",
+ table->statfs_cache.timeout,
+ options, int32, unlock);
+
ret = 0;
}
unlock:
@@ -1755,6 +1830,10 @@ init (xlator_t *this)
GF_OPTION_INIT ("max-file-size", table->max_file_size, size_uint64, out);
+ GF_OPTION_INIT ("statfs-cache", table->statfs_cache.enabled, bool, out);
+
+ GF_OPTION_INIT ("statfs-cache-timeout", table->statfs_cache.timeout, int32, out);
+
if (!check_cache_size_ok (this, table->cache_size)) {
ret = -1;
goto out;
@@ -1827,6 +1906,11 @@ init (xlator_t *this)
ctx = this->ctx;
ioc_log2_page_size = log_base2 (ctx->page_size);
+ LOCK_INIT (&table->statfs_cache.lock);
+ /* Invalidate statfs cache */
+ table->statfs_cache.tv.tv_sec = 0;
+ table->statfs_cache.tv.tv_usec = 0;
+
out:
if (ret == -1) {
if (table != NULL) {
@@ -2096,6 +2180,7 @@ fini (xlator_t *this)
GF_ASSERT (list_empty (&table->inode_lru[i]));
}
+ LOCK_DESTROY (&table->statfs_cache.lock);
GF_ASSERT (list_empty (&table->inodes));
*/
pthread_mutex_destroy (&table->table_lock);
@@ -2120,6 +2205,7 @@ struct xlator_fops fops = {
.readdirp = ioc_readdirp,
.discard = ioc_discard,
.zerofill = ioc_zerofill,
+ .statfs = ioc_statfs,
};
@@ -2171,5 +2257,21 @@ struct volume_options options[] = {
.description = "Maximum file size which would be cached by the "
"io-cache translator."
},
+ { .key = {"statfs-cache"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "0",
+ .description = "The cached statfs for a filesystem will be "
+ "till 'statfs-cache-timeout' seconds, after which re-validation "
+ "is performed."
+ },
+ { .key = {"statfs-cache-timeout"},
+ .type = GF_OPTION_TYPE_INT,
+ .min = 0,
+ .max = 60,
+ .default_value = "1",
+ .description = "The cached statfs for a filesystem will be "
+ "till 'statfs-cache-timeout' seconds, after which re-validation "
+ "is performed."
+ },
{ .key = {NULL} },
};
diff --git a/xlators/performance/io-cache/src/io-cache.h b/xlators/performance/io-cache/src/io-cache.h
index d7c823fe962..da71b2f2371 100644
--- a/xlators/performance/io-cache/src/io-cache.h
+++ b/xlators/performance/io-cache/src/io-cache.h
@@ -148,23 +148,32 @@ struct ioc_inode {
inode_t *inode;
};
+struct ioc_statvfs {
+ struct statvfs buf;
+ int32_t timeout;
+ struct timeval tv;
+ gf_boolean_t enabled;
+ gf_lock_t lock;
+};
+
struct ioc_table {
- uint64_t page_size;
- uint64_t cache_size;
- uint64_t cache_used;
- uint64_t min_file_size;
- uint64_t max_file_size;
- struct list_head inodes; /* list of inodes cached */
- struct list_head active;
- struct list_head *inode_lru;
- struct list_head priority_list;
- int32_t readv_count;
- pthread_mutex_t table_lock;
- xlator_t *xl;
- uint32_t inode_count;
- int32_t cache_timeout;
- int32_t max_pri;
- struct mem_pool *mem_pool;
+ uint64_t page_size;
+ uint64_t cache_size;
+ uint64_t cache_used;
+ uint64_t min_file_size;
+ uint64_t max_file_size;
+ struct list_head inodes; /* list of inodes cached */
+ struct list_head active;
+ struct list_head *inode_lru;
+ struct list_head priority_list;
+ int32_t readv_count;
+ pthread_mutex_t table_lock;
+ xlator_t *xl;
+ uint32_t inode_count;
+ int32_t cache_timeout;
+ int32_t max_pri;
+ struct mem_pool *mem_pool;
+ struct ioc_statvfs statfs_cache;
};
typedef struct ioc_table ioc_table_t;