*/
#include <linux/maple_tree.h>
+#include <linux/slab.h>
+
+static struct kmem_cache *maple_node_cache;
+
+static struct maple_node *mt_alloc_one(gfp_t gfp)
+{
+ return kmem_cache_alloc(maple_node_cache, gfp | __GFP_ZERO);
+}
+
+static void mt_free_rcu(struct rcu_head *head)
+{
+ struct maple_node *node = container_of(head, struct maple_node, rcu);
+ kmem_cache_free(maple_node_cache, node);
+}
+
+static void mt_free(struct maple_node *node)
+{
+ node->parent = node;
+ call_rcu(&node->rcu, mt_free_rcu);
+}
static inline enum maple_type mt_node_type(const void *entry)
{
return mt_node_type(entry) < maple_range_16;
}
-static inline bool ma_is_reserved(const void *entry)
+static inline bool mt_is_reserved(const void *entry)
{
return ((unsigned long)entry < 4096) && xa_is_internal(entry);
}
return (void *)((unsigned long)node | (type << 3) | 2);
}
-void mtree_init(struct maple_tree *mt) {
+void mtree_init(struct maple_tree *mt)
+{
spin_lock_init(&mt->ma_lock);
mt->ma_flags = 0;
mt->ma_root = NULL;
}
-void *mtree_load(struct maple_tree *mt, unsigned long index) {
+
+void *mtree_load(struct maple_tree *mt, unsigned long index)
+{
return NULL;
}
-int mtree_insert(struct maple_tree *mt, unsigned long index, void *entry, gfp_t gfp) {
+
+int mtree_insert(struct maple_tree *mt, unsigned long index, void *entry, gfp_t gfp)
+{
return -EINVAL;
}
+
int mtree_insert_range(struct maple_tree *mt, unsigned long first,
- unsigned long last, void *entry, gfp_t gfp) {
+ unsigned long last, void *entry, gfp_t gfp)
+{
return -EINVAL;
}
-int mtree_erase(struct maple_tree *mt, unsigned long index) {
+
+int mtree_erase(struct maple_tree *mt, unsigned long index)
+{
return -EINVAL;
}
-void mtree_destroy(struct maple_tree *mt) {
+void mtree_destroy(struct maple_tree *mt)
+{
+}
+
+void __init maple_tree_init(void)
+{
+ maple_node_cache = kmem_cache_create("maple node",
+ sizeof(struct maple_node), sizeof(struct maple_node),
+ SLAB_PANIC | SLAB_RECLAIM_ACCOUNT, NULL);
}
#ifdef MT_DEBUG
xa_to_value(entry), entry);
else if (xa_is_zero(entry))
pr_cont("zero (%ld)\n", xa_to_internal(entry));
- else if (ma_is_reserved(entry))
+ else if (mt_is_reserved(entry))
pr_cont("UNKNOWN ENTRY (%p)\n", entry);
else
pr_cont("%p\n", entry);
tree.ma_root = xa_mk_value(0);
mt_dump(&tree);
- posix_memalign(&node, 128, 128);
+ node = mt_alloc_one(GFP_KERNEL);
node->parent = (void *)((unsigned long)(&tree) | 1);
node->slot[0] = xa_mk_value(0);
node->slot[1] = xa_mk_value(1);
node->mr64.pivot[2] = 0;
tree.ma_root = mt_mk_node(node, maple_leaf_64);
mt_dump(&tree);
+
+ mt_free(node);
}
void maple_tree_tests(void)
int __weak main(void)
{
- radix_tree_init();
+ maple_tree_init();
maple_tree_tests();
- radix_tree_cpu_dead(1);
rcu_barrier();
if (nr_allocated)
printf("nr_allocated = %d\n", nr_allocated);