]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Add preallocation support
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Thu, 21 Apr 2022 00:37:48 +0000 (20:37 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Thu, 21 Apr 2022 22:34:52 +0000 (18:34 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
include/linux/maple_tree.h
lib/maple_tree.c

index 8f4d87129a3ec0b9701356deb5530f6f5ee244fd..ded42d30628789475fdd18e20d735b01489058a3 100644 (file)
@@ -454,8 +454,10 @@ void *mas_walk(struct ma_state *mas);
 void *mas_store(struct ma_state *mas, void *entry);
 void *mas_erase(struct ma_state *mas);
 int mas_store_gfp(struct ma_state *mas, void *entry, gfp_t gfp);
+void mas_store_prealloc(struct ma_state *mas, void *entry);
 void *mas_find(struct ma_state *mas, unsigned long max);
 void *mas_find_rev(struct ma_state *mas, unsigned long min);
+int mas_preallocate(struct ma_state *mas, void *entry, gfp_t gfp);
 
 bool mas_nomem(struct ma_state *mas, gfp_t gfp);
 void mas_pause(struct ma_state *mas);
index d6a10216521e3648f47bc4b8eaa3be9f0ef674a8..c955cdef79bebce335ddf95aa768daf495c4804c 100644 (file)
@@ -5548,6 +5548,44 @@ retry:
        return 0;
 }
 
+/**
+ * mas_store_prealloc() - Store a value into the tree using memeory
+ * preallocated in the maple state.
+ * @mas: The maple state
+ * @entry: The entry to store.
+ */
+void mas_store_prealloc(struct ma_state *mas, void *entry)
+{
+       MA_WR_STATE(wr_mas, mas, entry);
+
+       mas_wr_store_setup(&wr_mas);
+       trace_ma_write(__func__, mas, 0, entry);
+       mas_wr_store_entry(&wr_mas);
+       BUG_ON(mas_is_err(mas));
+       mas_destroy(mas);
+}
+
+/**
+ * mas_preallocate() - Preallocate enough nodes for a store operation
+ * @mas: The maple state
+ * @entry: The entry that will be stored
+ *
+ * Return: 0 on success, -ENOMEM if memory could not be allocated.
+ */
+int mas_preallocate(struct ma_state *mas, void *entry, gfp_t gfp)
+{
+
+       mas_set_alloc_req(mas, 1 + mas_mt_height(mas) * 3);
+       mas_alloc_nodes(mas, gfp);
+       if (likely(mas->node != MA_ERROR(-ENOMEM)))
+               return 0;
+
+       mas_set_alloc_req(mas, 0);
+       mas_destroy(mas);
+       mas->node = MAS_START;
+       return -ENOMEM;
+}
+
 /*
  * mas_expected_entries() - Set the expected number of entries that will be inserted.
  * @mas: The maple state