summaryrefslogtreecommitdiffstats
path: root/xlators/performance/io-cache
diff options
context:
space:
mode:
authorRaghavendra G <raghavendra@gluster.com>2010-01-25 05:43:24 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-01-25 04:32:23 -0800
commit61dbadb2e775d8f2011157c453100a77024e87bf (patch)
treedd281a04d08f3a6ff2b83a569f3224a9cdfc9d65 /xlators/performance/io-cache
parent3eef8dfd1bd7775e2b5ddddb07726b4bf4f6ee22 (diff)
performance/io-cache: cache only those files whose size falls under configured window.
Signed-off-by: Raghavendra G <raghavendra@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 570 (Cache only those files whose sizes falls under a configured window size) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=570
Diffstat (limited to 'xlators/performance/io-cache')
-rw-r--r--xlators/performance/io-cache/src/io-cache.c191
-rw-r--r--xlators/performance/io-cache/src/io-cache.h3
2 files changed, 130 insertions, 64 deletions
diff --git a/xlators/performance/io-cache/src/io-cache.c b/xlators/performance/io-cache/src/io-cache.c
index f01d8e3bb81..020a9f1621d 100644
--- a/xlators/performance/io-cache/src/io-cache.c
+++ b/xlators/performance/io-cache/src/io-cache.c
@@ -183,39 +183,56 @@ ioc_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
ioc_table_t *table = this->private;
uint8_t cache_still_valid = 0;
uint64_t tmp_ioc_inode = 0;
-
+ uint32_t weight = 0xffffffff;
+ const char *path = NULL;
+
if (op_ret != 0)
goto out;
- inode_ctx_get (inode, this, &tmp_ioc_inode);
- ioc_inode = (ioc_inode_t *)(long)tmp_ioc_inode;
- if (ioc_inode) {
- ioc_inode_lock (ioc_inode);
- {
- if (ioc_inode->cache.mtime == 0) {
- ioc_inode->cache.mtime = stbuf->st_mtime;
- }
- }
- ioc_inode_unlock (ioc_inode);
+ LOCK (&inode->lock);
+ {
+ __inode_ctx_get (inode, this, &tmp_ioc_inode);
+ ioc_inode = (ioc_inode_t *)(long)tmp_ioc_inode;
+
+ if (!ioc_inode) {
+ weight = ioc_get_priority (table, path);
+
+ ioc_inode = ioc_inode_update (table, inode,
+ weight);
+
+ __inode_ctx_put (inode, this,
+ (uint64_t)(long)ioc_inode);
+ }
+ }
+ UNLOCK (&inode->lock);
+
+ ioc_inode_lock (ioc_inode);
+ {
+ if (ioc_inode->cache.mtime == 0) {
+ ioc_inode->cache.mtime = stbuf->st_mtime;
+ }
+
+ ioc_inode->st_size = stbuf->st_size;
+ }
+ ioc_inode_unlock (ioc_inode);
- cache_still_valid = ioc_cache_still_valid (ioc_inode,
- stbuf);
+ cache_still_valid = ioc_cache_still_valid (ioc_inode,
+ stbuf);
- if (!cache_still_valid) {
- ioc_inode_flush (ioc_inode);
- }
+ if (!cache_still_valid) {
+ ioc_inode_flush (ioc_inode);
+ }
- ioc_table_lock (ioc_inode->table);
- {
- list_move_tail (&ioc_inode->inode_lru,
- &table->inode_lru[ioc_inode->weight]);
- }
- ioc_table_unlock (ioc_inode->table);
- }
+ ioc_table_lock (ioc_inode->table);
+ {
+ list_move_tail (&ioc_inode->inode_lru,
+ &table->inode_lru[ioc_inode->weight]);
+ }
+ ioc_table_unlock (ioc_inode->table);
out:
- STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, inode, stbuf, dict,
- postparent);
+ STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, inode, stbuf,
+ dict, postparent);
return 0;
}
@@ -467,35 +484,25 @@ ioc_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
path = local->file_loc.path;
if (op_ret != -1) {
- /* look for ioc_inode corresponding to this fd */
- LOCK (&fd->inode->lock);
- {
- __inode_ctx_get (fd->inode, this, &tmp_ioc_inode);
- ioc_inode = (ioc_inode_t *)(long)tmp_ioc_inode;
+ inode_ctx_get (fd->inode, this, &tmp_ioc_inode);
+ ioc_inode = (ioc_inode_t *)(long)tmp_ioc_inode;
- if (!ioc_inode) {
- /*
- this is the first time someone is opening
- this file, assign weight
- */
- weight = ioc_get_priority (table, path);
-
- ioc_inode = ioc_inode_update (table, inode,
- weight);
-
- __inode_ctx_put (fd->inode, this,
- (uint64_t)(long)ioc_inode);
- } else {
- ioc_table_lock (ioc_inode->table);
- {
- list_move_tail (&ioc_inode->inode_lru,
- &table->inode_lru[ioc_inode->weight]);
- }
- ioc_table_unlock (ioc_inode->table);
+ ioc_table_lock (ioc_inode->table);
+ {
+ list_move_tail (&ioc_inode->inode_lru,
+ &table->inode_lru[ioc_inode->weight]);
+ }
+ ioc_table_unlock (ioc_inode->table);
+
+ ioc_inode_lock (ioc_inode);
+ {
+ if ((table->min_file_size > ioc_inode->st_size)
+ || ((table->max_file_size >= 0)
+ && (table->max_file_size < ioc_inode->st_size))) {
+ fd_ctx_set (fd, this, 1);
}
-
- }
- UNLOCK (&fd->inode->lock);
+ }
+ ioc_inode_unlock (ioc_inode);
/* If mandatory locking has been enabled on this file,
we disable caching on it */
@@ -558,21 +565,27 @@ ioc_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
path = local->file_loc.path;
if (op_ret != -1) {
- {
- /* assign weight */
- weight = ioc_get_priority (table, path);
+ /* assign weight */
+ weight = ioc_get_priority (table, path);
+
+ ioc_inode = ioc_inode_update (table, inode, weight);
- ioc_inode = ioc_inode_update (table, inode, weight);
+ ioc_inode_lock (ioc_inode);
+ {
+ ioc_inode->cache.mtime = buf->st_mtime;
+ ioc_inode->st_size = buf->st_size;
- ioc_inode_lock (ioc_inode);
- {
- ioc_inode->cache.mtime = buf->st_mtime;
+ if ((table->min_file_size > ioc_inode->st_size)
+ || ((table->max_file_size >= 0)
+ && (table->max_file_size < ioc_inode->st_size))) {
+ fd_ctx_set (fd, this, 1);
}
- ioc_inode_unlock (ioc_inode);
+ }
+ ioc_inode_unlock (ioc_inode);
+
+ inode_ctx_put (fd->inode, this,
+ (uint64_t)(long)ioc_inode);
- inode_ctx_put (fd->inode, this,
- (uint64_t)(long)ioc_inode);
- }
/*
* If mandatory locking has been enabled on this file,
* we disable caching on it
@@ -1324,7 +1337,7 @@ init (xlator_t *this)
ioc_table_t *table = NULL;
dict_t *options = this->options;
uint32_t index = 0;
- char *cache_size_string = NULL;
+ char *cache_size_string = NULL, *tmp = NULL;
int32_t ret = -1;
glusterfs_ctx_t *ctx = NULL;
@@ -1394,8 +1407,48 @@ init (xlator_t *this)
}
}
table->max_pri ++;
+
+ table->min_file_size = 0;
+
+ tmp = data_to_str (dict_get (options, "min-file-size"));
+ if (tmp != NULL) {
+ if (gf_string2bytesize (tmp,
+ (uint64_t *)&table->min_file_size) != 0) {
+ gf_log ("io-cache", GF_LOG_ERROR,
+ "invalid number format \"%s\" of "
+ "\"option min-file-size\"", tmp);
+ goto out;
+ }
+
+ gf_log (this->name, GF_LOG_TRACE,
+ "using min-file-size %"PRIu64"", table->min_file_size);
+ }
+
+ table->max_file_size = -1;
+ tmp = data_to_str (dict_get (options, "max-file-size"));
+ if (tmp != NULL) {
+ if (gf_string2bytesize (tmp,
+ (uint64_t *)&table->max_file_size) != 0) {
+ gf_log ("io-cache", GF_LOG_ERROR,
+ "invalid number format \"%s\" of "
+ "\"option max-file-size\"", tmp);
+ goto out;
+ }
+
+ gf_log (this->name, GF_LOG_TRACE,
+ "using max-file-size %"PRIu64"", table->max_file_size);
+ }
INIT_LIST_HEAD (&table->inodes);
+ if ((table->max_file_size >= 0)
+ && (table->min_file_size > table->max_file_size)) {
+ gf_log ("io-cache", GF_LOG_ERROR, "minimum size (%"
+ PRIu64") of a file that can be cached is "
+ "greater than maximum size (%"PRIu64")",
+ table->min_file_size, table->max_file_size);
+ goto out;
+ }
+
table->inode_lru = CALLOC (table->max_pri, sizeof (struct list_head));
if (table->inode_lru == NULL) {
goto out;
@@ -1477,5 +1530,15 @@ struct volume_options options[] = {
.min = 4 * GF_UNIT_MB,
.max = 6 * GF_UNIT_GB
},
+ { .key = {"min-file-size"},
+ .type = GF_OPTION_TYPE_SIZET,
+ .min = -1,
+ .max = -1
+ },
+ { .key = {"max-file-size"},
+ .type = GF_OPTION_TYPE_SIZET,
+ .min = -1,
+ .max = -1
+ },
{ .key = {NULL} },
};
diff --git a/xlators/performance/io-cache/src/io-cache.h b/xlators/performance/io-cache/src/io-cache.h
index 44f621f8078..b1e061eeef3 100644
--- a/xlators/performance/io-cache/src/io-cache.h
+++ b/xlators/performance/io-cache/src/io-cache.h
@@ -141,6 +141,7 @@ struct ioc_cache {
struct ioc_inode {
struct ioc_table *table;
+ off_t st_size;
struct ioc_cache cache;
struct list_head inode_list; /*
* list of inodes, maintained by
@@ -159,6 +160,8 @@ struct ioc_table {
uint64_t page_size;
uint64_t cache_size;
uint64_t cache_used;
+ int64_t min_file_size;
+ int64_t max_file_size;
struct list_head inodes; /* list of inodes cached */
struct list_head active;
struct list_head *inode_lru;