From: Liu Yuan <tailai...@taobao.com> Also Set cache high watermark as 90% to be large cache friendly.
Signed-off-by: Liu Yuan <tailai...@taobao.com> --- sheep/object_cache.c | 71 +++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/sheep/object_cache.c b/sheep/object_cache.c index a4b06e2..82759be 100644 --- a/sheep/object_cache.c +++ b/sheep/object_cache.c @@ -22,7 +22,6 @@ #include <sys/file.h> #include <dirent.h> #include <urcu/uatomic.h> -#include <urcu/rculist.h> #include "sheep_priv.h" #include "util.h" @@ -414,7 +413,12 @@ out: * - skip the dirty object if it is not in push(writeback) phase. * - wait on the dirty object if it is in push phase. */ -#define HIGH_WATERMARK (sys->object_cache_size * 8 / 10) + +/* + * 90% is targeted for a large cache quota such as 200G, then we have 20G + * buffer which is large enough to prevent cache overrun. + */ +#define HIGH_WATERMARK (sys->object_cache_size * 9 / 10) static void do_reclaim_object(struct object_cache *oc) { struct object_cache_entry *entry, *t; @@ -717,54 +721,45 @@ static int object_cache_pull(struct object_cache *oc, uint32_t idx) struct sd_req hdr; struct sd_rsp *rsp = (struct sd_rsp *)&hdr; int ret = SD_RES_NO_MEM; - uint64_t oid; - uint32_t data_length; + uint64_t oid = idx_to_oid(oc->vid, idx); + uint32_t data_length = get_objsize(oid); void *buf; - if (idx_has_vdi_bit(idx)) { - oid = vid_to_vdi_oid(oc->vid); - data_length = SD_INODE_SIZE; - } else { - oid = vid_to_data_oid(oc->vid, idx); - data_length = SD_DATA_OBJ_SIZE; - } - buf = valloc(data_length); - if (buf == NULL) { - eprintf("failed to allocate memory\n"); - goto out; - } + if (!buf) + panic("%m\n"); sd_init_req(&hdr, SD_OP_READ_OBJ); hdr.data_length = data_length; hdr.obj.oid = oid; hdr.obj.offset = 0; ret = exec_local_req(&hdr, buf); + if (ret != SD_RES_SUCCESS) + goto err; - if (ret == SD_RES_SUCCESS) { - dprintf("oid %"PRIx64" pulled successfully\n", oid); - - ret = create_cache_object(oc, idx, buf, rsp->data_length, - rsp->obj.offset, data_length); - /* - * We try to delay reclaim objects to avoid object ping-pong - * because the pulled object is clean and likely to be reclaimed - * in a cache over high watermark. We can't simply pass without - * waking up reclaimer because the cache is easy to be filled - * full with a read storm. - */ - switch (ret) { - case SD_RES_SUCCESS: - add_to_lru_cache(oc, idx, false); - object_cache_try_to_reclaim(1); - break; - case SD_RES_OID_EXIST: - ret = SD_RES_SUCCESS; - break; - } + dprintf("oid %"PRIx64" pulled successfully\n", oid); + ret = create_cache_object(oc, idx, buf, rsp->data_length, + rsp->obj.offset, data_length); + /* + * We try to delay reclaim objects to avoid object ping-pong + * because the pulled object is clean and likely to be reclaimed + * in a cache over high watermark. We can't simply pass without + * waking up reclaimer because the cache is easy to be filled + * full with a read storm. + */ + switch (ret) { + case SD_RES_SUCCESS: + add_to_lru_cache(oc, idx, false); + object_cache_try_to_reclaim(1); + break; + case SD_RES_OID_EXIST: + ret = SD_RES_SUCCESS; + break; + default: + break; } +err: free(buf); -out: return ret; } -- 1.7.9.5 -- sheepdog mailing list sheepdog@lists.wpkg.org http://lists.wpkg.org/mailman/listinfo/sheepdog