summaryrefslogtreecommitdiffstats
path: root/drivers/md/persistent-data/dm-btree.h
diff options
context:
space:
mode:
authorJoe Thornber <ejt@redhat.com>2016-09-15 10:49:24 -0400
committerMike Snitzer <snitzer@redhat.com>2016-09-22 11:15:04 -0400
commit7d111c81fa29041c730010450618917fb05cab62 (patch)
treefc16361f87df6a69ff78f4280ef76cb570838aa6 /drivers/md/persistent-data/dm-btree.h
parent9d1b404cbc3f990a4035dcf7ddd37adac2a99b3f (diff)
downloadtalos-op-linux-7d111c81fa29041c730010450618917fb05cab62.tar.gz
talos-op-linux-7d111c81fa29041c730010450618917fb05cab62.zip
dm btree: introduce cursor api
This uses prefetching to speed up iteration through a btree. Signed-off-by: Joe Thornber <ejt@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Diffstat (limited to 'drivers/md/persistent-data/dm-btree.h')
-rw-r--r--drivers/md/persistent-data/dm-btree.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/drivers/md/persistent-data/dm-btree.h b/drivers/md/persistent-data/dm-btree.h
index c74301fa5a37..db9bd26adf31 100644
--- a/drivers/md/persistent-data/dm-btree.h
+++ b/drivers/md/persistent-data/dm-btree.h
@@ -176,4 +176,39 @@ int dm_btree_walk(struct dm_btree_info *info, dm_block_t root,
int (*fn)(void *context, uint64_t *keys, void *leaf),
void *context);
+
+/*----------------------------------------------------------------*/
+
+/*
+ * Cursor API. This does not follow the rolling lock convention. Since we
+ * know the order that values are required we can issue prefetches to speed
+ * up iteration. Use on a single level btree only.
+ */
+#define DM_BTREE_CURSOR_MAX_DEPTH 16
+
+struct cursor_node {
+ struct dm_block *b;
+ unsigned index;
+};
+
+struct dm_btree_cursor {
+ struct dm_btree_info *info;
+ dm_block_t root;
+
+ bool prefetch_leaves;
+ unsigned depth;
+ struct cursor_node nodes[DM_BTREE_CURSOR_MAX_DEPTH];
+};
+
+/*
+ * Creates a fresh cursor. If prefetch_leaves is set then it is assumed
+ * the btree contains block indexes that will be prefetched. The cursor is
+ * quite large, so you probably don't want to put it on the stack.
+ */
+int dm_btree_cursor_begin(struct dm_btree_info *info, dm_block_t root,
+ bool prefetch_leaves, struct dm_btree_cursor *c);
+void dm_btree_cursor_end(struct dm_btree_cursor *c);
+int dm_btree_cursor_next(struct dm_btree_cursor *c);
+int dm_btree_cursor_get_value(struct dm_btree_cursor *c, uint64_t *key, void *value_le);
+
#endif /* _LINUX_DM_BTREE_H */
OpenPOWER on IntegriCloud