From 726ec6f9819bd29bc6e7a75c06a800fa6e6ac10f Mon Sep 17 00:00:00 2001 From: Raghavendra G Date: Wed, 7 Oct 2009 10:09:34 +0000 Subject: performance/stat-prefetch: checking for cache and creation if not present is made atomic. Signed-off-by: Anand V. Avati BUG: 284 (performance actually decreases for 'ls -l' on a directory containing large number of files with stat-prefetch loaded) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=284 --- .../performance/stat-prefetch/src/stat-prefetch.c | 87 ++++++++++++++++------ 1 file changed, 64 insertions(+), 23 deletions(-) (limited to 'xlators/performance/stat-prefetch/src') diff --git a/xlators/performance/stat-prefetch/src/stat-prefetch.c b/xlators/performance/stat-prefetch/src/stat-prefetch.c index 222e5b737..69f9f2ba8 100644 --- a/xlators/performance/stat-prefetch/src/stat-prefetch.c +++ b/xlators/performance/stat-prefetch/src/stat-prefetch.c @@ -224,18 +224,14 @@ sp_cache_free (sp_cache_t *cache) sp_cache_t * -sp_get_cache_fd (xlator_t *this, fd_t *fd) +__sp_get_cache_fd (xlator_t *this, fd_t *fd) { - sp_cache_t *cache = NULL; - uint64_t value = 0; - int32_t ret = -1; + int32_t ret = -1; + sp_cache_t *cache = NULL; + uint64_t value = 0; sp_fd_ctx_t *fd_ctx = NULL; - if (fd == NULL) { - goto out; - } - - ret = fd_ctx_get (fd, this, &value); + ret = __fd_ctx_get (fd, this, &value); if (ret == -1) { goto out; } @@ -244,9 +240,30 @@ sp_get_cache_fd (xlator_t *this, fd_t *fd) LOCK (&fd_ctx->lock); { - cache = fd_ctx->cache; + cache = fd_ctx->cache; } UNLOCK (&fd_ctx->lock); + +out: + return cache; +} + + +sp_cache_t * +sp_get_cache_fd (xlator_t *this, fd_t *fd) +{ + sp_cache_t *cache = NULL; + + if (fd == NULL) { + goto out; + } + + LOCK (&fd->lock); + { + cache = __sp_get_cache_fd (this, fd); + } + UNLOCK (&fd->lock); + out: return cache; } @@ -378,13 +395,13 @@ out: inline int32_t -sp_put_cache (xlator_t *this, fd_t *fd, sp_cache_t *cache) +__sp_put_cache (xlator_t *this, fd_t *fd, sp_cache_t *cache) { sp_fd_ctx_t *fd_ctx = NULL; int32_t ret = -1; uint64_t value = 0; - ret = fd_ctx_get (fd, this, &value); + ret = __fd_ctx_get (fd, this, &value); if (!ret) { fd_ctx = (void *)(long)value; } else { @@ -395,7 +412,7 @@ sp_put_cache (xlator_t *this, fd_t *fd, sp_cache_t *cache) goto out; } - ret = fd_ctx_set (fd, this, (long)(void *)fd_ctx); + ret = __fd_ctx_set (fd, this, (long)(void *)fd_ctx); if (ret == -1) { sp_fd_ctx_free (fd_ctx); goto out; @@ -417,6 +434,23 @@ out: } +inline int32_t +sp_put_cache (xlator_t *this, fd_t *fd, sp_cache_t *cache) +{ + int32_t ret = -1; + + if (fd != NULL) { + LOCK (&fd->lock); + { + ret = __sp_put_cache (this, fd, cache); + } + UNLOCK (&fd->lock); + } + + return ret; +} + + int32_t sp_cache_add_entries (sp_cache_t *cache, gf_dirent_t *entries) { @@ -823,21 +857,28 @@ sp_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, fd = local->fd; - cache = sp_get_cache_fd (this, fd); - if (cache == NULL) { - cache = sp_cache_init (); + LOCK (&fd->lock); + { + cache = __sp_get_cache_fd (this, fd); if (cache == NULL) { - goto out; - } + cache = sp_cache_init (); + if (cache == NULL) { + goto unlock; + } - ret = sp_put_cache (this, fd, cache); - if (ret == -1) { - sp_cache_free (cache); - goto out; + ret = __sp_put_cache (this, fd, cache); + if (ret == -1) { + sp_cache_free (cache); + goto unlock; + } } } +unlock: + UNLOCK (&fd->lock); - sp_cache_add_entries (cache, entries); + if (cache != NULL) { + sp_cache_add_entries (cache, entries); + } out: SP_STACK_UNWIND (frame, op_ret, op_errno, entries); -- cgit