]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: preallocate nodes in mas_erase()
authorSidhartha Kumar <sidhartha.kumar@oracle.com>
Wed, 14 Aug 2024 16:19:33 +0000 (12:19 -0400)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 17 Aug 2024 00:53:18 +0000 (17:53 -0700)
Use mas_wr_preallocate() in mas_erase() to preallocate enough nodes to
complete the erase.  Add error handling by skipping the store if the
preallocation lead to some error besides no memory.

Link: https://lkml.kernel.org/r/20240814161944.55347-7-sidhartha.kumar@oracle.com
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Cc: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
lib/maple_tree.c

index 58985107cf0055537522881d5c0709d701f52947..8ba52ffa778e1f043d3f3eca67797745eb494550 100644 (file)
@@ -6371,14 +6371,18 @@ write_retry:
 
        /* Must reset to ensure spanning writes of last slot are detected */
        mas_reset(mas);
-       mas_wr_store_setup(&wr_mas);
-       mas_wr_store_entry(&wr_mas);
+       mas_wr_preallocate(&wr_mas, NULL);
        if (mas_nomem(mas, GFP_KERNEL)) {
                /* in case the range of entry changed when unlocked */
                mas->index = mas->last = index;
                goto write_retry;
        }
 
+       if (mas_is_err(mas))
+               goto out;
+
+       mas_wr_store_entry(&wr_mas);
+out:
        mas_destroy(mas);
        return entry;
 }