[sheepdog] [PATCH] object cache: move calc_object_bmap() out of lock
Liu Yuan
namei.unix at gmail.com
Wed May 16 16:55:59 CEST 2012
From: Liu Yuan <tailai.ly at taobao.com>
It doesn't need lock protection at all.
- remove unnecessary check against len, because it will never be 0
- add a warning in push_cache_object() to indicate nothing to flush, if
this happens, we have a bug.
Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
sheep/object_cache.c | 9 ++++-----
1 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 4f1ff49..5ba063d 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -46,9 +46,6 @@ static uint64_t calc_object_bmap(size_t len, off_t offset)
int start, end, nr;
uint64_t bmap = 0;
- if (!len)
- return 0;
-
start = offset / CACHE_BLOCK_SIZE;
end = (offset + len - 1) / CACHE_BLOCK_SIZE;
@@ -341,8 +338,8 @@ int object_cache_rw(struct object_cache *oc, uint32_t idx, struct request *req)
ret = write_cache_object(oc->vid, idx, req->data, hdr->data_length, hdr->offset);
if (ret != SD_RES_SUCCESS)
goto out;
- pthread_mutex_lock(&oc->lock);
bmap = calc_object_bmap(hdr->data_length, hdr->offset);
+ pthread_mutex_lock(&oc->lock);
add_to_dirty_tree_and_list(oc, idx, bmap, NULL, 0);
pthread_mutex_unlock(&oc->lock);
} else {
@@ -517,8 +514,10 @@ static int push_cache_object(uint32_t vid, uint32_t idx,
dprintf("%"PRIx64", create %d\n", oid, create);
- if (!bmap)
+ if (!bmap) {
+ dprintf("WARN: nothing to flush\n");
return SD_RES_SUCCESS;
+ }
memset(&fake_req, 0, sizeof(fake_req));
--
1.7.8.2
More information about the sheepdog
mailing list