From: Matthew Wilcox Date: Mon, 17 Dec 2018 23:05:18 +0000 (-0500) Subject: XArray: Remove radix tree compatibility X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=916a26dc6f1c1042c716d0f3cd9062ca81ed914e;p=users%2Fwilly%2Fxarray.git XArray: Remove radix tree compatibility 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 --- diff --git a/include/linux/radix-tree.h b/include/linux/radix-tree.h index e9eab4c9df96..4b9fec9e36c1 100644 --- a/include/linux/radix-tree.h +++ b/include/linux/radix-tree.h @@ -18,9 +18,14 @@ #include /* 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) { diff --git a/include/linux/xarray.h b/include/linux/xarray.h index 5921599b6dc4..1c7ccdd072ba 100644 --- a/include/linux/xarray.h +++ b/include/linux/xarray.h @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include #include @@ -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 */ diff --git a/lib/radix-tree.c b/lib/radix-tree.c index 99869dd4acc8..91d138b0dfb4 100644 --- a/lib/radix-tree.c +++ b/lib/radix-tree.c @@ -291,7 +291,7 @@ out: ret->count = count; ret->nr_values = nr_values; ret->parent = parent; - ret->array = root; + ret->tree = root; } return ret; }