maple_tree: lock checking and clean ups
Subsystems (7)
Liam R. Howlett (Oracle)
maintainerv3 cover maple_tree: lock checking and clean ups
In this series:
1. Try to detect lock issues
A number of syzbot reports are incorrectly pointing to the mm exit as a source of the locking error. The first three patches attempt to help users detect errors in their locking - but they still have to use LOCKDEP. I guess it's still down to hope and prayers.
2. Documentation fixes
The documentation was lacking clarity, there are updates to try and help the users, especially around the erase() cases.
3. Two benign issues
The cyclic allocator may have a race, although no in-kernel user can hit it.
The erase functions may cause allocation issues if used with the incorrect locking type, but none are present in-tree.
4. The erase gfp uses
mas_erase() and mtree_erase() do not take a gfp argument. To improve reliability of the erase, the first attempt to allocate will be GFP_NOWAIT, followed by a retry (if necessary of GFP_KERNEL | GFP_NOFAIL. This will ensure the data is gone. I've updated the documentation to make it more clear as well. mas_store() is not addressed in the same way, but may need to be updated at a later date, but that may require changing callers so it is out of scope here.
Beyond these goals there are some test fixes, some general speed-up patches targeting extra work and cycles, and dropping dead code.
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
Changes since v2:
- Added a mas_nomem_nofail() function for mas_erase() - Thanks Jason, Vlastimil, and Pedro.
- Dropped the WARN_ON() that was triggered by syzbot and questioned by Andrew - Thanks Andrew (and the syzbot)
Liam R. Howlett (Oracle) (19):
maple_tree: Add rcu locking check when LOCKDEP is enabled locking/lockdep: Add sequence counter to held_lock
maple_tree: Add write lock checking with lockdep sequence numbers
maple_tree: Documentation fix
maple_tree: Drop dead code from mas_extend_spanning_null()
maple_tree: Drop MAPLE_ALLOC_SLOTS
maple_tree: Clarify comments on mas_nomem()
maple_tree: Use prefetched value in mas_wr_store_type()
maple_tree: Optimise mas_wr_node_store() when not in rcu mode
maple_tree: micro optimisation of mas_wr_store_type()
maple_tree: Add bulk parent set helper
maple_tree: Catch race in mas_alloc_cyclic()
maple_tree: Document that erase may use GFP_KERNEL for allocations
maple_tree: Avoid mas_erase() and mtree_erase() failures
maple_tree: Document erase and allocations better
maple_tree: Change two GFP flags in tests
maple_tree: Fix argument name in header
maple_tree: Avoid extra gap calculation
maple_tree: Add helper mas_make_walkable()
Documentation/core-api/maple_tree.rst | 23 +- include/linux/lockdep.h | 3 + include/linux/lockdep_types.h | 3 +- include/linux/maple_tree.h | 12 +- include/linux/sched.h | 1 + kernel/locking/lockdep.c | 58 +++- lib/maple_tree.c | 394 ++++++++++++++++++-------- tools/testing/radix-tree/maple.c | 4 +- 8 files changed, 366 insertions(+), 132 deletions(-)
Signature · 1 line
2.47.3
Liam R. Howlett (Oracle)
maintainerPATCH v3 1/19 maple_tree: Add rcu locking check when LOCKDEP is enabled
When CONFIG_LOCKDEP and CONFIG_RCU_STRICT_GRACE_PERIOD is enabled, check for rcu locking issues by recording the grace period in the maple state and checking the rcu window is still valid whenever the maple state is reused with a state that is not MA_START or MA_PAUSED.
--- include/linux/maple_tree.h | 3 +++ lib/maple_tree.c | 50 +++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-)
include/linux/maple_tree.h +3 -0
@@ -484,6 +484,9 @@ struct ma_state {unsigned char mas_flags;unsigned char end;/* The end of the node */ enum store_type store_type;/* The type of store needed for this operation */ +#if IS_ENABLED (CONFIG_LOCKDEP ) &&IS_ENABLED (CONFIG_RCU_STRICT_GRACE_PERIOD ) +unsigned long rcu_gp; +#endif };struct ma_wr_state {
lib/maple_tree.c +49 -1
134 lines not on this page · raw message
Signature · 1 line
2.47.3
Liam R. Howlett (Oracle)
maintainerPATCH v3 2/19 locking/lockdep: Add sequence counter to held_lock
In reply to Liam R. Howlett (Oracle)Add an 8 bit small sequence counter to the held_lock struct to detect if the lock as been dropped and reacquired. This is useful when a data structure depends on a constant locking context, but is not able to detect locking and unlocking of the lock through its own API.
Since the __lock_unpin_lock() will no longer detect underflow by casting the unsigned int to a signed int, update the casting code to use a temp variable for calculations using a signed int.
--- include/linux/lockdep.h | 3 ++ include/linux/lockdep_types.h | 3 +- include/linux/sched.h | 1 + kernel/locking/lockdep.c | 58 ++++++++++++++++++++++++++++++----- 4 files changed, 57 insertions(+), 8 deletions(-)
include/linux/lockdep.h +3 -0
@@ -273,6 +273,9 @@ extern struct pin_cookie lock_pin_lock(struct lockdep_map *lock);extern void lock_repin_lock (struct lockdep_map *lock,struct pin_cookie );extern void lock_unpin_lock (struct lockdep_map *lock,struct pin_cookie ); +extern u32 lock_sequence (struct lockdep_map *lock); +#define lockdep_sequence (lock) lock_sequence(&(lock)->dep_map) +#define lockdep_depth (tsk) (debug_locks ? (tsk)->lockdep_depth : 0)#define lockdep_assert (cond) \
include/linux/lockdep_types.h +2 -1
@@ -253,7 +253,8 @@ struct held_lock { unsigned int hardirqs_off:1; unsigned int sync:1; unsigned int references:11; /* 32 bits */ - unsigned int pin_count; + unsigned int pin_count:24; + unsigned int seq_count:8; };#else /* !CONFIG_LOCKDEP */
include/linux/sched.h +1 -0
@@ -1288,6 +1288,7 @@ struct task_struct {u64 curr_chain_key;int lockdep_depth;unsigned int lockdep_recursion; +unsigned int lockdep_seq;struct held_lock held_locks[MAX_LOCK_DEPTH ];#endif
kernel/locking/lockdep.c +51 -7
111 lines not on this page · raw message
Signature · 1 line
2.47.3
Liam R. Howlett (Oracle)
maintainerPATCH v3 3/19 maple_tree: Add write lock checking with lockdep sequence numbers
In reply to Liam R. Howlett (Oracle)Use the lockdep sequence numbers to ensure the write lock is not dropped between write operations. The lockdep sequence is recorded on any walk that starts from the top of the tree and re-checked prior to any operation using an active node.
When lockdep detects an issue, it sets debug_locks to 0 disabling further reports. __lock_sequnece() will return u32 ~0 when debug_locks is zero, and the real sequnece count cannot return such a high value as it is less than 32bits.
By always updating the sequence number, regardless of lock state and by ignoring ~0 value in the sequence number will avoid ever printing a WARN_ON when lockdep sets debug_locks to 0.
--- include/linux/maple_tree.h | 7 +++-- lib/maple_tree.c | 64 +++++++++++++++++++++++++++++++------- 2 files changed, 57 insertions(+), 14 deletions(-)
include/linux/maple_tree.h +5 -2
@@ -484,9 +484,12 @@ struct ma_state {unsigned char mas_flags;unsigned char end;/* The end of the node */ enum store_type store_type;/* The type of store needed for this operation */ -#if IS_ENABLED (CONFIG_LOCKDEP ) &&IS_ENABLED (CONFIG_RCU_STRICT_GRACE_PERIOD ) +#ifdef CONFIG_LOCKDEP +u32 ld_seq; +#ifdef CONFIG_RCU_STRICT_GRACE_PERIOD unsigned long rcu_gp; -#endif +#endif /* CONFIG_RCU_STRICT_GRACE_PERIOD */ +#endif /* CONFIG_LOCKDEP */ };struct ma_wr_state {
lib/maple_tree.c +52 -12
123 lines not on this page · raw message
Signature · 1 line
2.47.3
Liam R. Howlett (Oracle)
maintainerPATCH v3 4/19 maple_tree: Documentation fix
In reply to Liam R. Howlett (Oracle)Don't include the word flag in the quotes with the actual flag.
--- Documentation/core-api/maple_tree.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/core-api/maple_tree.rst +1 -1
@@ -211,7 +211,7 @@ Advanced Locking The maple tree uses a spinlock by default, but external locks can be used for tree updates as well. To use an external lock, the tree must be initialized -with the ``MT_FLAGS_LOCK_EXTERN flag``, this is usually done with the +with the ``MT_FLAGS_LOCK_EXTERN`` flag, this is usually done with the MTREE_INIT_EXT() #define, which takes an external lock as an argument. Functions and structures
Signature · 1 line
2.47.3
Liam R. Howlett (Oracle)
maintainerPATCH v3 5/19 maple_tree: Drop dead code from mas_extend_spanning_null()
In reply to Liam R. Howlett (Oracle)mas_extend_spanning_null() had a clause if the end of the range being written (mas->last) is the same as the end of the existing range it is overwriting (wr_mas->r_max), action will be taken.
This code path is not possible because the only calling function increments mas->last (unless it's ULONG_MAX) to walk to one beyond the write and then resets the value back to the initial value.
In the case of mas->last == ULONG_MAX, then the second part of the statement will always be false - mas->last cannot be less than the node max.
This code never executed and is flawed anyways (the arguments are incorrectly ordered), so removing it is the safest action. Since the code never executes, it is not fixing any issue so Fixes tag is not given.
--- lib/maple_tree.c | 7 ------- 1 file changed, 7 deletions(-)
lib/maple_tree.c +0 -7
@@ -2997,13 +2997,6 @@ static inline void mas_extend_spanning_null(struct ma_wr_state *l_wr_mas,if (r_mas->last < r_wr_mas->r_max) r_mas->last = r_wr_mas->r_max; r_mas->offset++; - }else if ((r_mas->last == r_wr_mas->r_max) && - (r_mas->last < r_mas->max) && - !mas_slot_locked (r_mas, r_wr_mas->slots, r_mas->offset +1 )) { - r_mas->last =mas_safe_pivot (r_mas, r_wr_mas->pivots, - r_wr_mas->type, r_mas->offset +1 ); - r_mas->offset++; - r_wr_mas->r_max = r_mas->last; } }
Signature · 1 line
2.47.3
Liam R. Howlett (Oracle)
maintainerPATCH v3 6/19 maple_tree: Drop MAPLE_ALLOC_SLOTS
In reply to Liam R. Howlett (Oracle)MAPLE_ALLOC_SLOTS is no longer used, so remove it.
--- include/linux/maple_tree.h | 2 -- 1 file changed, 2 deletions(-)
include/linux/maple_tree.h +0 -2
@@ -28,13 +28,11 @@#define MAPLE_NODE_SLOTS 31/* 256 bytes including ->parent */ #define MAPLE_RANGE64_SLOTS 16/* 256 bytes */ #define MAPLE_ARANGE64_SLOTS 10/* 240 bytes */ -#define MAPLE_ALLOC_SLOTS (MAPLE_NODE_SLOTS - 1)#else /* 32bit sizes */ #define MAPLE_NODE_SLOTS 63/* 256 bytes including ->parent */ #define MAPLE_RANGE64_SLOTS 32/* 256 bytes */ #define MAPLE_ARANGE64_SLOTS 21/* 240 bytes */ -#define MAPLE_ALLOC_SLOTS (MAPLE_NODE_SLOTS - 2)#endif /* defined(CONFIG_64BIT) || defined(BUILD_VDSO32_64) */ #define MAPLE_NODE_MASK 255UL
Signature · 1 line
2.47.3
Liam R. Howlett (Oracle)
maintainerPATCH v3 7/19 maple_tree: Clarify comments on mas_nomem()
In reply to Liam R. Howlett (Oracle)When an allocation completely fails, the return is false. If the allocation succeeds or partially succeeds, return true to indicate a retry of the operation. Note that since the lock may have been dropped, the operation is retried from the start - including potentially allocating more memory.
--- lib/maple_tree.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
lib/maple_tree.c +7 -2
@@ -5677,10 +5677,11 @@ EXPORT_SYMBOL_GPL(mas_erase);/** * mas_nomem() - Check if there was an error allocating and do the allocation -* if necessary If there are allocations, then free them. +* if necessary. +* * @mas: The maple state * @gfp: The GFP_FLAGS to use for allocations -* Return: true on allocation, false otherwise. +* Return: False on no memory. True otherwise (partial success as well) */ bool mas_nomem(struct ma_state *mas, gfp_t gfp) __must_hold(mas->tree->ma_lock)
@@ -5696,6 +5697,10 @@ bool mas_nomem(struct ma_state *mas, gfp_t gfp)mas_alloc_nodes (mas, gfp); } +/* +* Return false on zero forward progress. Partial allocations are kept +* so the retry path will attempt to get the rest. +*/ if (!mas->sheaf && !mas->alloc)return false;
Signature · 1 line
2.47.3
Liam R. Howlett (Oracle)
maintainerPATCH v3 8/19 maple_tree: Use prefetched value in mas_wr_store_type()
In reply to Liam R. Howlett (Oracle)The slot contents exist in wr_mas->content, which has less overhead than reading the slot again.
--- lib/maple_tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/maple_tree.c +1 -1
@@ -3280,7 +3280,7 @@ static inline void mas_wr_slot_store(struct ma_wr_state *wr_mas)void __rcu **slots = wr_mas->slots;bool gap = false; - gap |= !mt_slot_locked (mas->tree, slots, offset); + gap |= !wr_mas->content; gap |= !mt_slot_locked (mas->tree, slots, offset +1 );if (wr_mas->offset_end - offset ==1 ) {
Signature · 1 line
2.47.3
Liam R. Howlett (Oracle)
maintainerPATCH v3 9/19 maple_tree: Optimise mas_wr_node_store() when not in rcu mode
In reply to Liam R. Howlett (Oracle)Clearing the entire node on the stack is unnecessary since most of the node will be overwritten anyways. Just clear what isn't used after the data is in place.
Benchmarking shows a speedup of 0.67% on a height 4 tree with 2048 entries.
--- lib/maple_tree.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
lib/maple_tree.c +17 -3
@@ -3187,7 +3187,7 @@ static void mas_wr_spanning_store(struct ma_wr_state *wr_mas)static inline void mas_wr_node_store (struct ma_wr_state *wr_mas) {unsigned char dst_offset, offset_end; -unsigned char copy_size, node_pivots; +unsigned char copy_size, node_pivots, node_slots;struct maple_node reuse, *newnode;unsigned long *dst_pivots;void __rcu **dst_slots;
@@ -3200,6 +3200,7 @@ static inline void mas_wr_node_store(struct ma_wr_state *wr_mas) in_rcu =mt_in_rcu (mas->tree); offset_end = wr_mas->offset_end; node_pivots = mt_pivots[wr_mas->type]; + node_slots = mt_slots[wr_mas->type];/* Assume last adds an entry */ new_end = mas->end +1 - offset_end + mas->offset;if (mas->last == wr_mas->end_piv) {
@@ -3211,7 +3212,6 @@ static inline void mas_wr_node_store(struct ma_wr_state *wr_mas)if (in_rcu) { newnode =mas_pop_node (mas); }else { -memset (&reuse,0 ,sizeof (struct maple_node )); newnode = &reuse; }
@@ -3255,7 +3255,21 @@ static inline void mas_wr_node_store(struct ma_wr_state *wr_mas) dst_pivots[new_end] = mas->max; done: -mas_leaf_set_meta (newnode, maple_leaf_64, new_end); +if (!in_rcu && new_end +2 < node_slots) { +unsigned char clear_from = new_end +1 ; + +/* +* Note that the last slot is never cleared, since the metadata +* will be stored there or it has a value. +*/ +memset (dst_slots + clear_from,0 , +sizeof (void __rcu *) * (node_slots - clear_from)); +if (clear_from < node_pivots) +memset (dst_pivots + clear_from,0 , +sizeof (unsigned long ) * (node_pivots - clear_from)); + } + +mas_leaf_set_meta (newnode, wr_mas->type, new_end);if (in_rcu) {struct maple_enode *old_enode = mas->node;
Signature · 1 line
2.47.3
Liam R. Howlett (Oracle)
maintainerPATCH v3 10/19 maple_tree: micro optimisation of mas_wr_store_type()
In reply to Liam R. Howlett (Oracle)Use three new local booleans instead of reading other structures. This has shown an increase of 0.62% on a 2048 entry tree of height 4.
--- lib/maple_tree.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
lib/maple_tree.c +15 -3
@@ -3737,6 +3737,9 @@ static inline enum store_type mas_wr_store_type(struct ma_wr_state *wr_mas) {struct ma_state *mas = wr_mas->mas;unsigned char new_end; +bool appending; +bool one_slot; +bool in_rcu;if (unlikely (mas_is_none (mas) ||mas_is_ptr (mas)))return wr_store_root;
@@ -3756,21 +3759,30 @@ static inline enum store_type mas_wr_store_type(struct ma_wr_state *wr_mas)return wr_new_root; new_end =mas_wr_new_end (wr_mas); + in_rcu =mt_in_rcu (mas->tree); + appending = mas->offset == mas->end; + one_slot = wr_mas->offset_end - mas->offset ==1 ; +/* Potential spanning rebalance collapsing a node */ if (new_end < mt_min_slots[wr_mas->type]) {if (!mte_is_root (mas->node))return wr_rebalance; +if (!in_rcu) { +if (appending) +return wr_append; +else if (mas->end == new_end && one_slot) +return wr_slot_store; + }return wr_node_store; }if (new_end >= mt_slots[wr_mas->type])return wr_split_store; -if (!mt_in_rcu (mas->tree) && (mas->offset == mas->end)) +if (!in_rcu && appending)return wr_append; -if ((new_end == mas->end) && (!mt_in_rcu (mas->tree) || - (wr_mas->offset_end - mas->offset ==1 ))) +if (new_end == mas->end && (!in_rcu || one_slot))return wr_slot_store;return wr_node_store;
Signature · 1 line
2.47.3
Liam R. Howlett (Oracle)
maintainerPATCH v3 11/19 maple_tree: Add bulk parent set helper
In reply to Liam R. Howlett (Oracle)Instead of calculating the parent pointer each time for a child, cache the majority of the parent pointer and only change the slot per child.
Drop the mas_set_parent() function since the last user has been removed.
Testing on a tree containing 2048 entries of height 4 had an increased gain of 3.51% on nodes tracking gaps.
--- lib/maple_tree.c | 97 +++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 55 deletions(-)
lib/maple_tree.c +42 -55
@@ -450,46 +450,6 @@ enum maple_type mas_parent_type(struct ma_state *mas, struct maple_enode *enode)return 0 ; } -/* -* mas_set_parent() - Set the parent node and encode the slot -* @mas: The maple state -* @enode: The encoded maple node. -* @parent: The encoded maple node that is the parent of @enode. -* @slot: The slot that @enode resides in @parent. -* -* Slot number is encoded in the enode->parent bit 3-6 or 2-6, depending on the -* parent type. -*/ -static inline -void mas_set_parent (struct ma_state *mas,struct maple_enode *enode, -const struct maple_enode *parent,unsigned char slot) -{ -unsigned long val = (unsigned long )parent; -unsigned long shift; -unsigned long type; -enum maple_type p_type =mte_node_type (parent); - -MAS_BUG_ON (mas, p_type == maple_dense); -MAS_BUG_ON (mas, p_type == maple_leaf_64); - -switch (p_type) { -case maple_range_64: -case maple_arange_64: - shift =MAPLE_PARENT_SLOT_SHIFT ; - type =MAPLE_PARENT_RANGE64 ; -break ; -default : -case maple_dense: -case maple_leaf_64: - shift = type =0 ; -break ; - } - - val &= ~MAPLE_NODE_MASK ;/* Clear all node metadata in parent */ - val |= (slot << shift) | type; -mte_to_node (enode)->parent =ma_parent_ptr (val); -} -/* * mte_parent_slot() - get the parent slot of @enode. * @enode: The encoded maple node.
@@ -871,6 +831,42 @@ static inline void ma_set_meta_gap(struct maple_node *mn, enum maple_type mt, meta->gap = offset; } +/* +* mas_set_parent_slots() - Bulk operation to set many slot parent pointers +* @mas: The maple state +* @parent: The encoded maple node that is the parent of @enode. +* @slot: The slot that of the @enode. +* @start_slot: The offset into @slot +* @count: The number of slots to set (eg: exclusive) +*/ +static inline +void mas_set_parent_slots (struct ma_state *mas,struct maple_enode *parent, +void __rcu **slots,unsigned char start_slot,unsigned char count) +{ +unsigned long val; +unsigned long shift; +unsigned long type; +enum maple_type p_type =mte_node_type (parent); +unsigned char i; + +MAS_BUG_ON (mas, p_type != maple_range_64 && + p_type != maple_arange_64); + + shift =MAPLE_PARENT_SLOT_SHIFT ; + type =MAPLE_PARENT_RANGE64 ; + + val = (unsigned long )parent; + val &= ~MAPLE_NODE_MASK ; + +for (i =0 ; i < count; i++) { +unsigned long pval = val | ((start_slot + i) << shift) | type; +struct maple_enode *child; + + child =mt_slot_locked (mas->tree, slots, i); +mte_to_node (child)->parent =ma_parent_ptr (pval); + } +} +/* * mat_add() - Add a @dead_enode to the ma_topiary of a list of dead nodes. * @mat: the ma_topiary, a linked list of dead nodes.
@@ -1609,14 +1605,10 @@ static inline void mas_adopt_children(struct ma_state *mas,struct maple_node *node =mte_to_node (parent);void __rcu **slots =ma_slots (node, type);unsigned long *pivots =ma_pivots (node, type); -struct maple_enode *child; -unsigned char offset; +unsigned char end; - offset =ma_data_end (node, type, pivots, mas->max); -do { - child =mas_slot_locked (mas, slots, offset); -mas_set_parent (mas, child, parent, offset); - }while (offset--); + end =ma_data_end (node, type, pivots, mas->max); +mas_set_parent_slots (mas, parent, slots,0 , end +1 ); }/*
@@ -1998,15 +1990,10 @@ unsigned long node_copy(struct ma_state *mas, struct maple_node *src, s_slots =ma_slots (src, s_mt) + start; s_pivots =ma_pivots (src, s_mt) + start;memcpy (d_slots, s_slots, size *sizeof (void __rcu *)); -if (!ma_is_leaf (d_mt) && s_mt == maple_copy) { -struct maple_enode *edst =mt_mk_node (dst, d_mt); - -for (int i =0 ; i < size; i++) -mas_set_parent (mas, -mt_slot_locked (mas->tree, d_slots, i), - edst, d_start + i); - } +if (!ma_is_leaf (d_mt) && s_mt == maple_copy) +mas_set_parent_slots (mas,mt_mk_node (dst, d_mt), + d_slots, d_start, size); d_gaps =ma_gaps (dst, d_mt);if (d_gaps) {
Signature · 1 line
2.47.3
Liam R. Howlett (Oracle)
maintainerPATCH v3 12/19 maple_tree: Catch race in mas_alloc_cyclic()
In reply to Liam R. Howlett (Oracle)If mas_alloc_cyclic() is called during a low memory situation, it is possible the lock may be dropped so reclaim can occur. There is a window where some other task may allocate the same id and cause the mas_insert() to fail with -EEXIST. In this scenario the function will return -EEXIST, which is not expected.
Modifying the retry on mas_nomem() to re-search for a slot means that any race with other writes will not matter as the lock will be held between finding the index and writing the index.
Moving the flag logic avoids cases where the flag is modified on drop lock/reacquire or when the write fails after clearing the flag.
No existing users are exposed to this issue.
--- lib/maple_tree.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-)
lib/maple_tree.c +24 -19
@@ -3868,35 +3868,40 @@ int mas_alloc_cyclic(struct ma_state *mas, unsigned long *startp, void *entry, unsigned long range_lo, unsigned long range_hi, unsigned long *next, gfp_t gfp) { - unsigned long min = range_lo; -int ret =0 ; - - range_lo =max (min, *next); - ret =mas_empty_area (mas, range_lo, range_hi,1 ); -if ((mas->tree->ma_flags &MT_FLAGS_ALLOC_WRAPPED ) && ret ==0 ) { - mas->tree->ma_flags &= ~MT_FLAGS_ALLOC_WRAPPED ; - ret =1 ; - } -if (ret <0 && range_lo > min) { -mas_reset (mas); - ret =mas_empty_area (mas, min, range_hi,1 ); -if (ret ==0 ) - ret =1 ; - } -if (ret <0 ) -return ret; + int ret; +unsigned long min; + min = range_lo;do { + range_lo =max (min, *next); + ret =mas_empty_area (mas, range_lo, range_hi,1 ); +if (ret <0 && range_lo > min) { +mas_reset (mas); + ret =mas_empty_area (mas, min, range_hi,1 ); +if (ret ==0 ) + ret =1 ; + } +if (ret <0 ) + goto out; +mas_insert (mas, entry); }while (mas_nomem (mas, gfp)); -if (mas_is_err (mas)) -return xa_err (mas->node); +if (mas_is_err (mas)) { + ret =xa_err (mas->node); + goto out; + } + +if ((mas->tree->ma_flags &MT_FLAGS_ALLOC_WRAPPED ) && ret ==0 ) { + mas->tree->ma_flags &= ~MT_FLAGS_ALLOC_WRAPPED ; + ret =1 ; + } *startp = mas->index; *next = *startp +1 ;if (*next ==0 ) mas->tree->ma_flags |=MT_FLAGS_ALLOC_WRAPPED ; +out:mas_destroy (mas);return ret; }
Signature · 1 line
2.47.3
Liam R. Howlett (Oracle)
maintainerPATCH v3 13/19 maple_tree: Document that erase may use GFP_KERNEL for allocations
In reply to Liam R. Howlett (Oracle)State that the mas_erase() and mtree_erase() functions may use GFP_KERNEL on allocation retry. Don't just depend on people reading the documentation by adding a check that will warn of the use.
--- lib/maple_tree.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
lib/maple_tree.c +21 -2
@@ -5658,6 +5658,10 @@ EXPORT_SYMBOL_GPL(mas_find_range_rev);* Searches for @mas->index, sets @mas->index and @mas->last to the range and * erases that range. * +* Note that erase requires allocations and will use GFP_KERNEL to do so if +* necessary. If the allocation fails, the internal lock will be dropped to +* retry. +* * Return: the entry that was erased or %NULL, @mas->index and @mas->last are updated. */ void *mas_erase (struct ma_state *mas)
@@ -5666,13 +5670,21 @@ void *mas_erase(struct ma_state *mas)unsigned long index = mas->index;MA_WR_STATE (wr_mas, mas,NULL ); +/* +* In low memory situations, the allocation is retried with the gfp flag +* GFP_KERNEL. The internal spinlock is dropped in mas_nomem(), however +* the external lock is not dropped. +*/ +if (mt_external_lock (mas->tree)) +might_alloc (GFP_KERNEL ); +if (!mas_is_active (mas) || !mas_is_start (mas)) mas->status = ma_start; write_retry: entry =mas_state_walk (mas);if (!entry) -return NULL ; + goto out;/* Must reset to ensure spanning writes of last slot are detected */ mas_reset (mas);
@@ -5683,8 +5695,10 @@ void *mas_erase(struct ma_state *mas) goto write_retry; } -if (mas_is_err (mas)) +if (mas_is_err (mas)) { + entry =NULL ; goto out; + }mas_wr_store_entry (&wr_mas); out:
@@ -6012,6 +6026,10 @@ EXPORT_SYMBOL(mtree_alloc_rrange);* Erasing is the same as a walk to an entry then a store of a NULL to that * ENTIRE range. In fact, it is implemented as such using the advanced API. * +* Note that erase requires allocations and will use GFP_KERNEL to do so if +* necessary. If the allocation fails, the internal lock will be dropped to +* retry. +* * Return: The entry stored at the @index or %NULL */ void *mtree_erase (struct maple_tree *mt,unsigned long index)
@@ -6021,6 +6039,7 @@ void *mtree_erase(struct maple_tree *mt, unsigned long index)MA_STATE (mas, mt, index, index);trace_ma_op (TP_FCT , &mas); +might_alloc (GFP_KERNEL );mtree_lock (mt); entry =mas_erase (&mas);mtree_unlock (mt);
Signature · 1 line
2.47.3
Re: [PATCH v3 13/19] maple_tree: Document that erase may use GFP_KERNEL for allocations
Quoted 9 lines · Liam R. Howlett (Oracle)
State that the
mas_erase()andmtree_erase()functions may useGFP_KERNELon allocation retry. Don't just depend on people reading the
documentation by adding a check that will warn of the use.Cc Jason Gunthorpe <[email protected]>Cc Rik van Riel <[email protected]>Signed-off-by Liam R. Howlett (Oracle) <[email protected]>
This is helpful. Thank you.
Signature · 1 line
All Rights Reversed.
Liam R. Howlett (Oracle)
maintainerPATCH v3 14/19 maple_tree: Avoid mas_erase() and mtree_erase() failures
In reply to Liam R. Howlett (Oracle)Failures to remove entries using the two APIs to erase the entries may result in allocation failures. The failures may go unnoticed and an unexpected entry may remain. Instead, fall back to retrying with GFP_KERNEL | __GFP_NOFAIL so that the entry will be removed.
--- include/linux/maple_tree.h | 2 ++ lib/maple_tree.c | 68 ++++++++++++++++++++++++++++---------- 2 files changed, 52 insertions(+), 18 deletions(-)
include/linux/maple_tree.h +2 -0
@@ -570,6 +570,8 @@ int mas_alloc_cyclic(struct ma_state *mas, unsigned long *startp, unsigned long *next, gfp_t gfp);bool mas_nomem (struct ma_state *mas,gfp_t gfp); +bool mas_nomem_nofail (struct ma_state *mas,unsigned long index, +unsigned long last);void mas_pause (struct ma_state *mas);void maple_tree_init (void );void mas_destroy (struct ma_state *mas);
lib/maple_tree.c +50 -18
111 lines not on this page · raw message
Signature · 1 line
2.47.3
Liam R. Howlett (Oracle)
maintainerPATCH v3 15/19 maple_tree: Document erase and allocations better
In reply to Liam R. Howlett (Oracle)During a discussion on the maple tree erase process and GFP flags, Jason suggested there be an amendment to the documentation to clarify the situation on allocations within the tree.
The added text is an attempt to better explain that the tree may allocate, even when erasing, and provide some guidance on how to work around such issues.
--- Documentation/core-api/maple_tree.rst | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
Documentation/core-api/maple_tree.rst +18 -3
@@ -17,7 +17,8 @@ supports iterating over a range of entries and going to the previous or next entry in a cache-efficient manner. The tree can also be put into an RCU-safe mode of operation which allows reading and writing concurrently. Writers must synchronize on a lock, which can be the default spinlock, or the user can set -the lock to an external lock of a different type. +the lock to an external lock of a different type. Note that external locks may +interfere with allocations in a low memory situation. The Maple Tree maintains a small memory footprint and was designed to use modern processor cache efficiently. The majority of the users will be able to
@@ -42,6 +43,15 @@ successful store operation within a given code segment when allocating cannot be done. Allocations of nodes are relatively small at around 256 bytes. +Since the maple tree uses internal nodes that are allocated and has rules on +data density, erasing an entry may cause allocations to occur. That is, +erasing an entry may consume memory. Users must take care to ensure that they +do not violate the larger system constraints on when and how memory is +allocated. Most situations are fine to allocate, but the pre-allocation +support is provided as a mechanism to avoid trickier situations. There is also +the possibility of using special entries and clean up the tree later, in +extreme circumstances. + .. _maple-tree-normal-api: Normal API
@@ -63,7 +73,9 @@ success or an error code otherwise. mtree_store_range() works in the same way but takes a range. mtree_load() is used to retrieve the entry stored at a given index. You can use mtree_erase() to erase an entire range by only knowing one value within that range, or mtree_store() call with an entry of -NULL may be used to partially erase a range or many ranges at once. +NULL may be used to partially erase a range or many ranges at once. Note that +mtree_erase() may use GFP_KERNEL | __GFP_NOFAIL for allocations and cannot +fail, but may need to sleep - do not use mtree_erase() from a blocking context. If you want to only store a new entry to a range (or index) if that range is currently ``NULL``, you can use mtree_insert_range() or mtree_insert() which
@@ -163,7 +175,10 @@ You can use mas_erase() to erase an entire range by setting index and last of the maple state to the desired range to erase. This will erase the first range that is found in that range, set the maple state index and last as the range that was erased and return the entry that existed -at that location. +at that location. Note that mas_erase() may allocate with the GFP_KERNEL +__GFP_NOFAIL and cannot fail, but may sleep. If this is not okay, consider +using mas_store_gfp() and pass it a ``NULL``, +after setting up the correct range by walking to the entry. You can walk each entry within a range by using mas_for_each(). If you want to walk each element of the tree then ``0`` and ``ULONG_MAX`` may be used as
Signature · 1 line
2.47.3
Re: [PATCH v3 15/19] maple_tree: Document erase and allocations better
Quoted 11 lines · Liam R. Howlett (Oracle)
knowing one value within that range, or
mtree_store()call with an entry of(quoted diff) +1
-1-NULL may be used to partially erase a range or many ranges at once. +NULL may be used to partially erase a range or many ranges at once.Note that
+mtree_erase() may useGFP_KERNEL|__GFP_NOFAILfor allocations and cannot
+fail, but may need to sleep - do not usemtree_erase()from a blocking context.
Do you mean "from a context that cannot block" ?
Signature · 1 line
All Rights Reversed.
Liam R. Howlett (Oracle)
maintainerRe: [PATCH v3 15/19] maple_tree: Document erase and allocations better
Quoted 14 lines · Rik van Riel
Quoted 11 lines · Liam R. Howlett (Oracle)
knowing one value within that range, or
mtree_store()call with an entry of(quoted diff) +1
-1-NULL may be used to partially erase a range or many ranges at once. +NULL may be used to partially erase a range or many ranges at once.Note that
+mtree_erase() may useGFP_KERNEL|__GFP_NOFAILfor allocations and cannot
+fail, but may need to sleep - do not usemtree_erase()from a blocking context.Do you mean "from a context that cannot block" ?
Ah, that's not clear.
"Do not use mtree_erase() from a context that cannot tolerate blocking"
Is that better?
Thanks,
Liam
Re: [PATCH v3 15/19] maple_tree: Document erase and allocations better
Quoted 16 lines · Liam R. Howlett (Oracle)
Quoted 14 lines · Rik van Riel
Quoted 11 lines · Liam R. Howlett (Oracle)
knowing one value within that range, or
mtree_store()call with an entry of(quoted diff) +1
-1-NULL may be used to partially erase a range or many ranges at once. +NULL may be used to partially erase a range or many ranges at once.Note that
+mtree_erase() may useGFP_KERNEL|__GFP_NOFAILfor allocations and cannot
+fail, but may need to sleep - do not usemtree_erase()from a blocking context.Do you mean "from a context that cannot block" ?
Quoted 5 lines
Ah, that's not clear.
"Do not use
mtree_erase()from a context that cannot tolerate blocking"Is that better?
I would say 'can sleep, so must not be called from an atomic context' ?
If that is what you mean..
Jason
Liam R. Howlett (Oracle)
maintainerPATCH v3 16/19 maple_tree: Change two GFP flags in tests
In reply to Liam R. Howlett (Oracle)The GFP flags in two tests are obviously incorrect. Make the tests correctly run by updating the GFP flags.
--- tools/testing/radix-tree/maple.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/radix-tree/maple.c +2 -2
@@ -35234,7 +35234,7 @@ static noinline void __init check_prealloc(struct maple_tree *mt)mt_set_non_kernel (1 );/* Spanning store */ mas_set_range (&mas,1 ,100 ); -MT_BUG_ON (mt,mas_preallocate (&mas, ptr,GFP_KERNEL &GFP_NOWAIT ) ==0 ); +MT_BUG_ON (mt,mas_preallocate (&mas, ptr,GFP_NOWAIT ) ==0 ); allocated =mas_allocated (&mas); height =mas_mt_height (&mas);MT_BUG_ON (mt, allocated !=0 );
@@ -35257,7 +35257,7 @@ static noinline void __init check_prealloc(struct maple_tree *mt)MT_BUG_ON (mt,mas_allocated (&mas) !=0 );mas_set_range (&mas,0 ,200 );mt_set_non_kernel (1 ); -MT_BUG_ON (mt,mas_preallocate (&mas, ptr,GFP_KERNEL &GFP_NOWAIT ) ==0 ); +MT_BUG_ON (mt,mas_preallocate (&mas, ptr,GFP_NOWAIT ) ==0 ); allocated =mas_allocated (&mas); height =mas_mt_height (&mas);MT_BUG_ON (mt, allocated !=0 );
Signature · 1 line
2.47.3
Liam R. Howlett (Oracle)
maintainerPATCH v3 17/19 maple_tree: Fix argument name in header
In reply to Liam R. Howlett (Oracle)The mas_prev_range() function takes a min and not a max.
--- include/linux/maple_tree.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/maple_tree.h +1 -1
@@ -577,7 +577,7 @@ void maple_tree_init(void);void mas_destroy (struct ma_state *mas);void *mas_prev (struct ma_state *mas,unsigned long min); -void *mas_prev_range (struct ma_state *mas,unsigned long max); +void *mas_prev_range (struct ma_state *mas,unsigned long min);void *mas_next (struct ma_state *mas,unsigned long max);void *mas_next_range (struct ma_state *mas,unsigned long max);
Signature · 1 line
2.47.3
Liam R. Howlett (Oracle)
maintainerPATCH v3 18/19 maple_tree: Avoid extra gap calculation
In reply to Liam R. Howlett (Oracle)Prior to ending the ascension loop of larger operations like split, rebalance, and spanning store the gap in the node had been calculated. Once the node is inserted into the tree, the gap is recalculated in mas_update_gap(). This can be avoided by creating a helper for mas_update_gap() that accepts the known gap value, which reduces the operations required for gap updating path.
--- lib/maple_tree.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-)
lib/maple_tree.c +17 -11
@@ -1566,14 +1566,26 @@ static inline void mas_parent_gap(struct ma_state *mas, unsigned char offset, goto ascend; } +static __always_inline void mas_update_gap_known(struct ma_state *mas, +unsigned long gap) +{ +unsigned char pslot; +unsigned long p_gap; + + pslot =mte_parent_slot (mas->node); + p_gap =ma_gaps (mte_parent (mas->node), +mas_parent_type (mas, mas->node))[pslot]; + +if (p_gap != gap) +mas_parent_gap (mas, pslot, gap); +} +/* * mas_update_gap() - Update a nodes gaps and propagate up if necessary. * @mas: the maple state. */ static inline void mas_update_gap (struct ma_state *mas) { -unsigned char pslot; -unsigned long p_gap;unsigned long max_gap;if (!mt_is_alloc (mas->tree))
@@ -1583,13 +1595,7 @@ static inline void mas_update_gap(struct ma_state *mas)return ; max_gap =mas_max_gap (mas); - - pslot =mte_parent_slot (mas->node); - p_gap =ma_gaps (mte_parent (mas->node), -mas_parent_type (mas, mas->node))[pslot]; - -if (p_gap != max_gap) -mas_parent_gap (mas, pslot, max_gap); +mas_update_gap_known (mas, max_gap); }/*
@@ -2137,8 +2143,8 @@ static inline void mas_wmb_replace(struct ma_state *mas, struct maple_copy *cp) mas->node =mt_slot_locked (mas->tree, cp->slot,0 );/* Insert the new data in the tree */ mas_topiary_replace (mas, old_enode, cp->height); -if (!mte_is_leaf (mas->node)) -mas_update_gap (mas); +if (mt_is_alloc (mas->tree) && !mte_is_root (mas->node)) +mas_update_gap_known (mas, cp->gap[0 ]);mtree_range_walk (mas); }
Signature · 1 line
2.47.3
Liam R. Howlett (Oracle)
maintainerPATCH v3 19/19 maple_tree: Add helper mas_make_walkable()
In reply to Liam R. Howlett (Oracle)A check in mas_walk() was incorrect and caused inefficient use of the maple state. The same issue existed in mas_erase(), but was left unfixed. Making a helper function is the obvious answer.
--- lib/maple_tree.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
lib/maple_tree.c +8 -5
@@ -261,6 +261,12 @@ static inline bool mas_is_underflow(struct ma_state *mas)return mas->status == ma_underflow; } +static inline void mas_make_walkable (struct ma_state *mas) +{ +if (!mas_is_active (mas) && !mas_is_start (mas)) + mas->status = ma_start; +} + static __always_inline struct maple_node *mte_to_node(const struct maple_enode *entry) {
@@ -4447,8 +4453,7 @@ void *mas_walk(struct ma_state *mas)void *entry;mas_may_init_lock_check (mas); -if (!mas_is_active (mas) && !mas_is_start (mas)) - mas->status = ma_start; +mas_make_walkable (mas); retry: entry =mas_state_walk (mas);if (mas_is_start (mas)) {
@@ -5685,9 +5690,7 @@ void *mas_erase(struct ma_state *mas)if (mt_external_lock (mas->tree))might_alloc (GFP_KERNEL ); -if (!mas_is_active (mas) || !mas_is_start (mas)) - mas->status = ma_start; - +mas_make_walkable (mas); write_retry: entry =mas_state_walk (mas);if (!entry)
Signature · 1 line
2.47.3
Liam R. Howlett (Oracle)
maintainerQuoted 29 lines · Liam R. Howlett (Oracle)
In this series:
1. Try to detect lock issues
A number of syzbot reports are incorrectly pointing to the mm exit as a source of the locking error. The first three patches attempt to help users detect errors in their locking - but they still have to use LOCKDEP. I guess it's still down to hope and prayers.2. Documentation fixes
The documentation was lacking clarity, there are updates to try and help the users, especially around theerase()cases.3. Two benign issues
The cyclic allocator may have a race, although no in-kernel user can hit it.
The erase functions may cause allocation issues if used with the incorrect locking type, but none are present in-tree.4. The erase gfp uses
mas_erase()andmtree_erase()do not take a gfp argument. To improve reliability of the erase, the first attempt to allocate will beGFP_NOWAIT, followed by a retry (if necessary ofGFP_KERNEL|GFP_NOFAIL. This will ensure the data is gone. I've updated the documentation to make it more clear as well.mas_store()is not addressed in the same way, but may need to be updated at a later date, but that may require changing callers so it is out of scope here.Beyond these goals there are some test fixes, some general speed-up patches targeting extra work and cycles, and dropping dead code.
Quoted 8 lines
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/Changes since v2:
- Added amas_nomem_nofail()function formas_erase()- Thanks Jason, Vlastimil, and Pedro.
- Dropped theWARN_ON()that was triggered by syzbot and questioned by Andrew - Thanks Andrew (and the syzbot)
Sorry, I forgot Breno Leitao's help with the lockdep testing. Thanks Breno, I appreciate the testing and help with that (and for working on debian)!
Quoted 35 lines
Liam R. Howlett (Oracle) (19):
maple_tree: Add rcu locking check when LOCKDEP is enabled locking/lockdep: Add sequence counter toheld_lock
maple_tree: Add write lock checking with lockdep sequence numbers
maple_tree: Documentation fix
maple_tree: Drop dead code frommas_extend_spanning_null()
maple_tree: DropMAPLE_ALLOC_SLOTS
maple_tree: Clarify comments onmas_nomem()
maple_tree: Use prefetched value inmas_wr_store_type()
maple_tree: Optimisemas_wr_node_store()when not in rcu mode
maple_tree: micro optimisation ofmas_wr_store_type()
maple_tree: Add bulk parent set helper
maple_tree: Catch race inmas_alloc_cyclic()
maple_tree: Document that erase may useGFP_KERNELfor allocations
maple_tree: Avoidmas_erase()andmtree_erase()failures
maple_tree: Document erase and allocations better
maple_tree: Change two GFP flags in tests
maple_tree: Fix argument name in header
maple_tree: Avoid extra gap calculation
maple_tree: Add helpermas_make_walkable()Documentation/core-api/maple_tree.rst | 23 +- include/linux/lockdep.h | 3 + include/linux/lockdep_types.h | 3 +- include/linux/maple_tree.h | 12 +- include/linux/sched.h | 1 + kernel/locking/lockdep.c | 58 +++- lib/maple_tree.c | 394 ++++++++++++++++++-------- tools/testing/radix-tree/maple.c | 4 +- 8 files changed, 366 insertions(+), 132 deletions(-)Signature · 1 line
2.47.3
Andrew Morton
maintainerQuoted 26 lines · On Fri, 21 Aug 2026 15:26:08 -0400 "Liam R. Howlett (Oracle)"…
In this series:
1. Try to detect lock issues
A number of syzbot reports are incorrectly pointing to the mm exit as a source of the locking error. The first three patches attempt to help users detect errors in their locking - but they still have to use LOCKDEP. I guess it's still down to hope and prayers.2. Documentation fixes
The documentation was lacking clarity, there are updates to try and help the users, especially around theerase()cases.3. Two benign issues
The cyclic allocator may have a race, although no in-kernel user can hit it.
The erase functions may cause allocation issues if used with the incorrect locking type, but none are present in-tree.4. The erase gfp uses
mas_erase()andmtree_erase()do not take a gfp argument. To improve reliability of the erase, the first attempt to allocate will beGFP_NOWAIT, followed by a retry (if necessary ofGFP_KERNEL|GFP_NOFAIL. This will ensure the data is gone. I've updated the documentation to make it more clear as well.mas_store()is not addressed in the same way, but may need to be updated at a later date, but that may require changing callers so it is out of scope here.
Quoted 2 lines
Beyond these goals there are some test fixes, some general speed-up patches targeting extra work and cycles, and dropping dead code.
Thanks, I updated mm.git's mm-unstable branch to this version.
I added a -fix for [13/19], per your discussion with Jason:
Documentation/core-api/maple_tree.rst renamed from Documentation/core-api/maple_tree.rst~maple_tree-document-erase-and-allocations-better-fix +2 -1
@@ -75,7 +75,8 @@ given index. You can use mtree_erase() knowing one value within that range, or mtree_store() call with an entry of NULL may be used to partially erase a range or many ranges at once. Note that mtree_erase() may use GFP_KERNEL | __GFP_NOFAIL for allocations and cannot -fail, but may need to sleep - do not use mtree_erase() from a blocking context. +fail. mtree_erase() can sleep, so it must not be called from an atomic +context. If you want to only store a new entry to a range (or index) if that range is currently ``NULL``, you can use mtree_insert_range() or mtree_insert() which
_
Sashiko said a few things which I think are new since v2.
https://sashiko.dev/#/patchset/[email protected]
Quoted 5 lines
Changes since v2:
- Added amas_nomem_nofail()function formas_erase()- Thanks Jason, Vlastimil, and Pedro.
- Dropped theWARN_ON()that was triggered by syzbot and questioned by Andrew - Thanks Andrew (and the syzbot)
Here's how v3 altered mm.git:
Documentation/core-api/maple_tree.rst | 9 ++- include/linux/maple_tree.h | 2 lib/maple_tree.c | 65 ++++++++++++++++-------- 3 files changed, 53 insertions(+), 23 deletions(-)
Documentation/core-api/maple_tree.rst renamed from Documentation/core-api/maple_tree.rst~b +6 -3
@@ -74,7 +74,9 @@ but takes a range. mtree_load() is used given index. You can use mtree_erase() to erase an entire range by only knowing one value within that range, or mtree_store() call with an entry of NULL may be used to partially erase a range or many ranges at once. Note that -mtree_erase() may use GFP_KERNEL on allocations. +mtree_erase() may use GFP_KERNEL | __GFP_NOFAIL for allocations and cannot +fail. mtree_erase() can sleep, so it must not be called from an atomic +context. If you want to only store a new entry to a range (or index) if that range is currently ``NULL``, you can use mtree_insert_range() or mtree_insert() which
@@ -174,8 +176,9 @@ You can use mas_erase() to erase an enti last of the maple state to the desired range to erase. This will erase the first range that is found in that range, set the maple state index and last as the range that was erased and return the entry that existed -at that location. Note that mas_erase() may allocate with the GFP_KERNEL flag. -If this is not okay, consider using mas_store_gfp() and pass it a ``NULL``, +at that location. Note that mas_erase() may allocate with the GFP_KERNEL +__GFP_NOFAIL and cannot fail, but may sleep. If this is not okay, consider +using mas_store_gfp() and pass it a ``NULL``, after setting up the correct range by walking to the entry. You can walk each entry within a range by using mas_for_each(). If you want
include/linux/maple_tree.h renamed from include/linux/maple_tree.h~b +2 -0
@@ -570,6 +570,8 @@ int mas_alloc_cyclic(struct ma_state *ma unsigned long *next, gfp_t gfp);bool mas_nomem (struct ma_state *mas,gfp_t gfp); +bool mas_nomem_nofail (struct ma_state *mas,unsigned long index, +unsigned long last);void mas_pause (struct ma_state *mas);void maple_tree_init (void );void mas_destroy (struct ma_state *mas);
lib/maple_tree.c renamed from lib/maple_tree.c~b +45 -20
103 lines not on this page · raw message
_