]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Pass GFP flags from callers
authorMatthew Wilcox <willy@infradead.org>
Sat, 1 Dec 2018 15:20:35 +0000 (10:20 -0500)
committerMatthew Wilcox <willy@infradead.org>
Sat, 1 Dec 2018 17:14:13 +0000 (12:14 -0500)
The API needs to allow the callers to specify GFP flags as some users
will not be able to tolerate sleeping.  There's no need for GFP flags
for erase, load or destroy as those do not need to allocate memory.

Signed-off-by: Matthew Wilcox <willy@infradead.org>
include/linux/maple_tree.h
lib/maple_tree.c
lib/test_maple_tree.c

index 3eea6082b77fb2edd9fea4c78a6efe83d9e54f21..8898d1f8994372e8bb3b874bf668edb5293fa23e 100644 (file)
@@ -148,15 +148,14 @@ void mtree_init(struct maple_tree *mt);
 
 void *mtree_load(struct maple_tree *mt, unsigned long index);
 
+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);
-
-int mtree_insert_range(struct maple_tree *mt, unsigned long start,
-                       unsigned long end, void *entry);
+int mtree_insert_range(struct maple_tree *mt, unsigned long first,
+                       unsigned long last, void *entry, gfp_t gfp);
 
 int mtree_erase(struct maple_tree *mt, unsigned long index);
 
 int mtree_destroy(struct maple_tree *mt);
 
-
 #endif
index 5dff567d949f022cd8c25589e496054341c2b9a1..9ef8bd57d5a45c6d58971f0a3938120e7a5cedb1 100644 (file)
@@ -77,16 +77,15 @@ static inline bool _maple_is_node_4(struct maple_state *ms)
 static struct maple_node *_maple_new_node(gfp_t gfp)
 {
        struct maple_node *mn;
-       size_t size = sizeof(struct maple_node);
-       mn = kmalloc(size, gfp);
-       if (mn == NULL)
+
+       mn = kzalloc(sizeof(*mn), gfp);
+       if (!mn)
                goto kmalloc_failed;
 
        mn->map64.parent = NULL;
 
 kmalloc_failed:
        return mn;
-
 }
 
 static bool __maple_nomem(struct maple_state *ms, gfp_t gfp)
@@ -537,10 +536,10 @@ void mtree_init(struct maple_tree *mt)
 EXPORT_SYMBOL(maple_init);
 
 /* Store an entry for a given range.
- * Does not overwrite, returns -EEXISTS if the entry exists already
+ * Does not overwrite, returns -EEXIST if the entry exists already
  */
 int mtree_insert_range(struct maple_tree *mt, unsigned long start,
-                       unsigned long end, void *entry)
+                       unsigned long end, void *entry, gfp_t gfp)
 {
        int ret = -EEXIST;
        void *walked = NULL;
@@ -565,7 +564,7 @@ retry:
 
        ret = _maple_insert(&ms, entry);
        if (ret == -ENOMEM) {
-               if (__maple_nomem(&ms, GFP_KERNEL | __GFP_ZERO)) // Drops lock.
+               if (__maple_nomem(&ms, gfp))
                        goto retry;
        }
 
@@ -576,11 +575,12 @@ already_exists:
 }
 
 /* Store an entry at an index.
- * Does not overwrite, returns -EEXISTS if the entry exists already
+ * Does not overwrite, returns -EEXIST if the entry exists already
  */
-int mtree_insert(struct maple_tree *mt, unsigned long index, void *entry)
+int mtree_insert(struct maple_tree *mt, unsigned long index, void *entry,
+               gfp_t gfp)
 {
-       return mtree_insert_range(mt, index, index, entry);
+       return mtree_insert_range(mt, index, index, entry, gfp);
 }
 EXPORT_SYMBOL(mtree_insert);
 
index 178b362dc841dde2302305cb1c464ad577a05a61..293f7343f5d0c2d559b7b3076b5f89dc7882dceb 100644 (file)
@@ -34,12 +34,12 @@ void mt_dump(const struct maple_tree *mt) { }
 static int mtree_test_insert(struct maple_tree *mt, unsigned long index,
                                void *ptr)
 {
-       return mtree_insert(mt, index, ptr);
+       return mtree_insert(mt, index, ptr, GFP_KERNEL);
 }
 static int mtree_test_insert_range(struct maple_tree *mt, unsigned long start,
                                unsigned long end, void *ptr)
 {
-       return mtree_insert_range(mt, start, end, ptr);
+       return mtree_insert_range(mt, start, end, ptr, GFP_KERNEL);
 }
 
 static void *mtree_test_load(struct maple_tree *mt, unsigned long index)