]> www.infradead.org Git - users/willy/xarray.git/commitdiff
XArray: Remove radix tree compatibility
authorMatthew Wilcox <willy@infradead.org>
Mon, 17 Dec 2018 23:05:18 +0000 (18:05 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 9 Aug 2019 01:38:13 +0000 (21:38 -0400)
The xa_flags field in the XArray was compatible with the radix tree
in order to make conversion easier.  With the page cache converted,
all future conversions will be done one data structure at a time, so
there is no more need for this compatibility.  This reduces the header
dependencies of the XArray to not require gfp.h, which would otherwise
introduce a header loop in a later patch.

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

index e9eab4c9df968c9ae67f691fdd4e0a4b1c61bceb..4b9fec9e36c15b7727da1687b444d6597ed5499a 100644 (file)
 #include <linux/xarray.h>
 
 /* Keep unconverted code working */
-#define radix_tree_root                xarray
 #define radix_tree_node                xa_node
 
+struct radix_tree_root {
+       spinlock_t      xa_lock;
+       gfp_t           xa_flags;
+       void __rcu *    xa_head;
+};
+
 /*
  * The bottom two bits of the slot determine how the remaining bits in the
  * slot are interpreted:
@@ -69,7 +74,11 @@ static inline bool radix_tree_is_internal_node(void *ptr)
 #define RADIX_TREE(name, mask) \
        struct radix_tree_root name = RADIX_TREE_INIT(name, mask)
 
-#define INIT_RADIX_TREE(root, mask) xa_init_flags(root, mask)
+#define INIT_RADIX_TREE(root, mask) do {                               \
+       spin_lock_init(&(root)->xa_lock);                               \
+       (root)->xa_flags = mask;                                        \
+       (root)->xa_head = NULL;                                         \
+} while (0)
 
 static inline bool radix_tree_empty(const struct radix_tree_root *root)
 {
index 5921599b6dc4f5f573ebf28a3a5553e0e391eda0..1c7ccdd072baeffd297dcb25fdc82430e141d427 100644 (file)
@@ -11,7 +11,7 @@
 
 #include <linux/bug.h>
 #include <linux/compiler.h>
-#include <linux/gfp.h>
+#include <linux/err.h>
 #include <linux/kconfig.h>
 #include <linux/kernel.h>
 #include <linux/rcupdate.h>
@@ -256,18 +256,14 @@ enum xa_lock_type {
        XA_LOCK_BH = 2,
 };
 
-/*
- * Values for xa_flags.  The radix tree stores its GFP flags in the xa_flags,
- * and we remain compatible with that.
- */
-#define XA_FLAGS_LOCK_IRQ      ((__force gfp_t)XA_LOCK_IRQ)
-#define XA_FLAGS_LOCK_BH       ((__force gfp_t)XA_LOCK_BH)
-#define XA_FLAGS_TRACK_FREE    ((__force gfp_t)4U)
-#define XA_FLAGS_ZERO_BUSY     ((__force gfp_t)8U)
-#define XA_FLAGS_ALLOC_WRAPPED ((__force gfp_t)16U)
-#define XA_FLAGS_ACCOUNT       ((__force gfp_t)32U)
-#define XA_FLAGS_MARK(mark)    ((__force gfp_t)((1U << __GFP_BITS_SHIFT) << \
-                                               (__force unsigned)(mark)))
+/* Values for xa_flags. */
+#define XA_FLAGS_LOCK_IRQ      XA_LOCK_IRQ
+#define XA_FLAGS_LOCK_BH       XA_LOCK_BH
+#define XA_FLAGS_TRACK_FREE    (1U << 2)
+#define XA_FLAGS_ZERO_BUSY     (1U << 3)
+#define XA_FLAGS_ALLOC_WRAPPED (1U << 4)
+#define XA_FLAGS_ACCOUNT       (1U << 5)
+#define XA_FLAGS_MARK(mark)    ((1U << 8) << (__force unsigned)(mark))
 
 /* ALLOC is for a normal 0-based alloc.  ALLOC1 is for an 1-based alloc */
 #define XA_FLAGS_ALLOC (XA_FLAGS_TRACK_FREE | XA_FLAGS_MARK(XA_FREE_MARK))
@@ -292,7 +288,7 @@ enum xa_lock_type {
 struct xarray {
        spinlock_t      xa_lock;
 /* private: The rest of the data structure is not to be used directly. */
-       gfp_t           xa_flags;
+       unsigned int    xa_flags;
        void __rcu *    xa_head;
 };
 
@@ -371,7 +367,7 @@ void xa_destroy(struct xarray *);
  *
  * Context: Any context.
  */
-static inline void xa_init_flags(struct xarray *xa, gfp_t flags)
+static inline void xa_init_flags(struct xarray *xa, unsigned int flags)
 {
        spin_lock_init(&xa->xa_lock);
        xa->xa_flags = flags;
@@ -1090,7 +1086,10 @@ struct xa_node {
        unsigned char   count;          /* Total entry count */
        unsigned char   nr_values;      /* Value entry count */
        struct xa_node __rcu *parent;   /* NULL at top of tree */
-       struct xarray   *array;         /* The array we belong to */
+       union {
+               struct xarray   *array;         /* The array we belong to */
+               struct radix_tree_root *tree;
+       };
        union {
                struct list_head private_list;  /* For tree user */
                struct rcu_head rcu_head;       /* Used when freeing node */
index 99869dd4acc8de057d57dcd3bb4a9595efc055fd..91d138b0dfb4290d6eec536502c0a2bbe050081e 100644 (file)
@@ -291,7 +291,7 @@ out:
                ret->count = count;
                ret->nr_values = nr_values;
                ret->parent = parent;
-               ret->array = root;
+               ret->tree = root;
        }
        return ret;
 }