[sheepdog] [PATCH] sheep: fix object cache size setting

Liu Yuan namei.unix at gmail.com
Tue Sep 25 05:29:55 CEST 2012


From: Liu Yuan <tailai.ly at taobao.com>

Use megabytes as unit and allow users to spefify size ranging from 1 ~ 4294967295
megabytes for object cache.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/object_cache.c |    2 ++
 sheep/sheep.c        |   10 +++++-----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 109b56e..f2f164c 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -548,6 +548,7 @@ static void do_reclaim(struct work *work)
 		else
 			data_length = SD_DATA_OBJ_SIZE;
 
+		data_length = data_length / 1024 / 1024;
 		uatomic_sub(&sys_cache.cache_size, data_length);
 		free(entry);
 	}
@@ -644,6 +645,7 @@ static void add_to_object_cache(struct object_cache *oc, uint32_t idx,
 		data_length = SD_INODE_SIZE;
 	else
 		data_length = SD_DATA_OBJ_SIZE;
+	data_length = data_length / 1024 / 1024;
 
 	entry = xzalloc(sizeof(*entry));
 	entry->oc = oc;
diff --git a/sheep/sheep.c b/sheep/sheep.c
index 3be45ff..7fa8249 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -193,17 +193,17 @@ static void object_cache_size_set(char *s)
 	const char *header = "size=";
 	int len = strlen(header);
 	char *size, *p;
-	uint32_t cache_size;
-	const uint32_t max_cache_size = UINT32_MAX / 1024 / 1024;
+	uint64_t cache_size;
+	const uint32_t max_cache_size = UINT32_MAX;
 
 	assert(!strncmp(s, header, len));
 
 	size = s + len;
-	cache_size = strtol(size, &p, 10);
-	if (size == p || cache_size < 0 || max_cache_size < cache_size)
+	cache_size = strtoull(size, &p, 10);
+	if (size == p || max_cache_size < cache_size)
 		goto err;
 
-	sys->object_cache_size = cache_size * 1024 * 1024;
+	sys->object_cache_size = cache_size;
 	return;
 
 err:
-- 
1.7.10.2




More information about the sheepdog mailing list