[sheepdog] [PATCH v1 3/5] sheep: change method of generating vnodes

Robin Dong robin.k.dong at gmail.com
Tue Apr 29 04:53:43 CEST 2014


From: Robin Dong <sanbai at taobao.com>

Using disks to generate new vnodes instead of nodes, the number of
vnodes generated by one disk is decided by the space of this disk.

Signed-off-by: Robin Dong <sanbai at taobao.com>
---
 include/internal_proto.h |  1 +
 include/sheep.h          | 26 ++++++++++++++++++++++++++
 sheep/group.c            | 12 +++++++++++-
 3 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/include/internal_proto.h b/include/internal_proto.h
index 3a47b85..4b920e1 100644
--- a/include/internal_proto.h
+++ b/include/internal_proto.h
@@ -159,6 +159,7 @@ struct disk_info {
 
 #ifdef HAVE_DISKVNODES
 	#define DISK_MAX     32
+	#define WEIGHT_MIN   (1ULL << 32)	/* 4G */
 	#define SD_NODE_SIZE (80 + sizeof(struct disk_info) * DISK_MAX)
 #else
 	#define SD_NODE_SIZE 80
diff --git a/include/sheep.h b/include/sheep.h
index f7f5c48..709669a 100644
--- a/include/sheep.h
+++ b/include/sheep.h
@@ -204,6 +204,31 @@ static inline bool node_eq(const struct sd_node *a, const struct sd_node *b)
 	return node_cmp(a, b) == 0;
 }
 
+#ifdef HAVE_DISKVNODES
+static inline void
+node_to_vnodes(const struct sd_node *n, struct rb_root *vroot)
+{
+
+	uint64_t node_hval = sd_hash(&n->nid, offsetof(typeof(n->nid),
+						       io_addr));
+	uint64_t hval, disk_vnodes;
+
+	for (int j = 0; j < DISK_MAX; j++) {
+		if (!n->disks[j].disk_id)
+			continue;
+		hval = fnv_64a_64(node_hval, n->disks[j].disk_id);
+		disk_vnodes = n->disks[j].disk_space / WEIGHT_MIN;
+		for (int k = 0; k < disk_vnodes; k++) {
+			hval = sd_hash_next(hval);
+			struct sd_vnode *v = xmalloc(sizeof(*v));
+			v->hash = hval;
+			v->node = n;
+			if (unlikely(rb_insert(vroot, v, rb, vnode_cmp)))
+				panic("vdisk hash collison");
+		}
+	}
+}
+#else
 static inline void
 node_to_vnodes(const struct sd_node *n, struct rb_root *vroot)
 {
@@ -220,6 +245,7 @@ node_to_vnodes(const struct sd_node *n, struct rb_root *vroot)
 			panic("vdisk hash collison");
 	}
 }
+#endif
 
 static inline void
 nodes_to_vnodes(struct rb_root *nroot, struct rb_root *vroot)
diff --git a/sheep/group.c b/sheep/group.c
index b5cc484..5e2b198 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -105,7 +105,6 @@ static void recalculate_vnodes(struct rb_root *nroot)
 	int nr_non_gateway_nodes = 0;
 	uint64_t avg_size = 0;
 	struct sd_node *n;
-	float factor;
 
 	rb_for_each_entry(n, nroot, rb) {
 		if (n->space) {
@@ -120,8 +119,19 @@ static void recalculate_vnodes(struct rb_root *nroot)
 	avg_size /= nr_non_gateway_nodes;
 
 	rb_for_each_entry(n, nroot, rb) {
+#ifdef HAVE_DISKVNODES
+		int total = 0;
+		for (int i = 0; i < DISK_MAX; i++) {
+			if (0 == n->disks[i].disk_id)
+				continue;
+			total += n->disks[i].disk_space / WEIGHT_MIN;
+		}
+		n->nr_vnodes = total;
+#else
+		float factor;
 		factor = (float)n->space / (float)avg_size;
 		n->nr_vnodes = rintf(SD_DEFAULT_VNODES * factor);
+#endif
 		sd_debug("node %s has %d vnodes, free space %" PRIu64,
 			 node_to_str(n), n->nr_vnodes, n->space);
 	}
-- 
1.7.12.4




More information about the sheepdog mailing list