Message ID | 20240626160631.3636515-1-Liam.Howlett@oracle.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [1/2] maple_tree: fix alloc node fail issue | expand |
On Wed, Jun 26, 2024 at 12:06:30PM -0400, Liam R. Howlett wrote: >From: Jiazi Li <jqqlijiazi@gmail.com> > >In the following code, the second call to the mas_node_count will >return -ENOMEM: > > mas_node_count(mas, MAPLE_ALLOC_SLOTS + 1); > mas_node_count(mas, MAPLE_ALLOC_SLOTS * 2 + 2); > >This is because there may be some full maple_alloc node in current >maple state. Use full maple_alloc node will make max_req equal to 0. >And it leads to mt_alloc_bulk return 0. >As a result, mas_node_count set mas.node to MA_ERROR(-ENOMEM). > >Find a non-full maple_alloc node, and if necessary, use this non-full >node in the next while loop. > >Fixes: 54a611b60590 ("Maple Tree: add new data structure") >Suggested-by: Liam R. Howlett <Liam.Howlett@oracle.com> >Signed-off-by: Jiazi Li <jqqlijiazi@gmail.com> >Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> Reviewed-by: Wei Yang <richard.weiyang@gmail.com> This looks good to me. I don't see it is in the master. Not sure this is missed.
Andrew, I think these two were missed. Can you please pick them up? Thanks, Liam * Liam R. Howlett <Liam.Howlett@oracle.com> [240626 12:06]: > From: Jiazi Li <jqqlijiazi@gmail.com> > > In the following code, the second call to the mas_node_count will > return -ENOMEM: > > mas_node_count(mas, MAPLE_ALLOC_SLOTS + 1); > mas_node_count(mas, MAPLE_ALLOC_SLOTS * 2 + 2); > > This is because there may be some full maple_alloc node in current > maple state. Use full maple_alloc node will make max_req equal to 0. > And it leads to mt_alloc_bulk return 0. > As a result, mas_node_count set mas.node to MA_ERROR(-ENOMEM). > > Find a non-full maple_alloc node, and if necessary, use this non-full > node in the next while loop. > > Fixes: 54a611b60590 ("Maple Tree: add new data structure") > Suggested-by: Liam R. Howlett <Liam.Howlett@oracle.com> > Signed-off-by: Jiazi Li <jqqlijiazi@gmail.com> > Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> > --- > lib/maple_tree.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/lib/maple_tree.c b/lib/maple_tree.c > index 634d49e39a02..fe5c6fab26c3 100644 > --- a/lib/maple_tree.c > +++ b/lib/maple_tree.c > @@ -1272,7 +1272,10 @@ static inline void mas_alloc_nodes(struct ma_state *mas, gfp_t gfp) > > node->node_count += count; > allocated += count; > - node = node->slot[0]; > + /* find a non-full node*/ > + do { > + node = node->slot[0]; > + } while (unlikely(node->node_count == MAPLE_ALLOC_SLOTS)); > requested -= count; > } > mas->alloc->total = allocated; > -- > 2.43.0 >
diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 634d49e39a02..fe5c6fab26c3 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1272,7 +1272,10 @@ static inline void mas_alloc_nodes(struct ma_state *mas, gfp_t gfp) node->node_count += count; allocated += count; - node = node->slot[0]; + /* find a non-full node*/ + do { + node = node->slot[0]; + } while (unlikely(node->node_count == MAPLE_ALLOC_SLOTS)); requested -= count; } mas->alloc->total = allocated;