diff mbox series

[6.6.y] maple_tree: do not preallocate nodes for slot stores

Message ID 20231212195255.219624-1-sidhartha.kumar@oracle.com (mailing list archive)
State New
Headers show
Series [6.6.y] maple_tree: do not preallocate nodes for slot stores | expand

Commit Message

Sidhartha Kumar Dec. 12, 2023, 7:52 p.m. UTC
mas_preallocate() defaults to requesting 1 node for preallocation and then
,depending on the type of store, will update the request variable. There
isn't a check for a slot store type, so slot stores are preallocating the
default 1 node. Slot stores do not require any additional nodes, so add a
check for the slot store case that will bypass node_count_gfp(). Update
the tests to reflect that slot stores do not require allocations.

User visible effects of this bug include increased memory usage from the
unneeded node that was allocated.

Fixes: 0b8bb544b1a7 ("maple_tree: update mas_preallocate() testing")
Cc: <stable@vger.kernel.org> # 6.6+
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
This is a modified backport as the patch to fix this in upstream does not
apply to 6.6 because the node_end field was moved from the ma_wr_state to
the ma_state after 6.6.

 lib/maple_tree.c                 | 6 ++++++
 tools/testing/radix-tree/maple.c | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

Comments

Sidhartha Kumar Dec. 13, 2023, 8:54 p.m. UTC | #1
On 12/12/23 11:52 AM, Sidhartha Kumar wrote:
> mas_preallocate() defaults to requesting 1 node for preallocation and then
> ,depending on the type of store, will update the request variable. There
> isn't a check for a slot store type, so slot stores are preallocating the
> default 1 node. Slot stores do not require any additional nodes, so add a
> check for the slot store case that will bypass node_count_gfp(). Update
> the tests to reflect that slot stores do not require allocations.
> 
> User visible effects of this bug include increased memory usage from the
> unneeded node that was allocated.
> 
> Fixes: 0b8bb544b1a7 ("maple_tree: update mas_preallocate() testing")
> Cc: <stable@vger.kernel.org> # 6.6+
> Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> ---
> This is a modified backport as the patch to fix this in upstream does not
> apply to 6.6 because the node_end field was moved from the ma_wr_state to
> the ma_state after 6.6.
  Please disregard this patch, the upstream fix[1] does actually apply correctly 
to the 6.6 stable branch.

Sorry for the noise,
Sid

[1] 
https://lore.kernel.org/linux-mm/20231213205058.386589-1-sidhartha.kumar@oracle.com/T/#u



>   lib/maple_tree.c                 | 6 ++++++
>   tools/testing/radix-tree/maple.c | 2 +-
>   2 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/maple_tree.c b/lib/maple_tree.c
> index bb24d84a4922f..5950d0c0e0f69 100644
> --- a/lib/maple_tree.c
> +++ b/lib/maple_tree.c
> @@ -5501,6 +5501,12 @@ int mas_preallocate(struct ma_state *mas, void *entry, gfp_t gfp)
>   
>   	mas_wr_end_piv(&wr_mas);
>   	node_size = mas_wr_new_end(&wr_mas);
> +
> +	/* Slot store, does not require additional nodes */
> +	if ((node_size == wr_mas.node_end) && ((!mt_in_rcu(mas->tree))
> +		|| (wr_mas.offset_end - mas->offset == 1)))
> +		return 0;
> +
>   	if (node_size >= mt_slots[wr_mas.type]) {
>   		/* Split, worst case for now. */
>   		request = 1 + mas_mt_height(mas) * 2;
> diff --git a/tools/testing/radix-tree/maple.c b/tools/testing/radix-tree/maple.c
> index e5da1cad70baf..76a8990bb14e8 100644
> --- a/tools/testing/radix-tree/maple.c
> +++ b/tools/testing/radix-tree/maple.c
> @@ -35538,7 +35538,7 @@ static noinline void __init check_prealloc(struct maple_tree *mt)
>   	MT_BUG_ON(mt, mas_preallocate(&mas, ptr, GFP_KERNEL) != 0);
>   	allocated = mas_allocated(&mas);
>   	height = mas_mt_height(&mas);
> -	MT_BUG_ON(mt, allocated != 1);
> +	MT_BUG_ON(mt, allocated != 0);
>   	mas_store_prealloc(&mas, ptr);
>   	MT_BUG_ON(mt, mas_allocated(&mas) != 0);
>
Greg KH Dec. 18, 2023, 10:59 a.m. UTC | #2
On Tue, Dec 12, 2023 at 11:52:55AM -0800, Sidhartha Kumar wrote:
> mas_preallocate() defaults to requesting 1 node for preallocation and then
> ,depending on the type of store, will update the request variable. There
> isn't a check for a slot store type, so slot stores are preallocating the
> default 1 node. Slot stores do not require any additional nodes, so add a
> check for the slot store case that will bypass node_count_gfp(). Update
> the tests to reflect that slot stores do not require allocations.
> 
> User visible effects of this bug include increased memory usage from the
> unneeded node that was allocated.
> 
> Fixes: 0b8bb544b1a7 ("maple_tree: update mas_preallocate() testing")
> Cc: <stable@vger.kernel.org> # 6.6+
> Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> ---
> This is a modified backport as the patch to fix this in upstream does not
> apply to 6.6 because the node_end field was moved from the ma_wr_state to
> the ma_state after 6.6.

What is the git commit id of this change in Linus's tree?

thanks,

greg k-h
Sidhartha Kumar Dec. 18, 2023, 5:53 p.m. UTC | #3
On 12/18/23 2:59 AM, Greg KH wrote:
> On Tue, Dec 12, 2023 at 11:52:55AM -0800, Sidhartha Kumar wrote:
>> mas_preallocate() defaults to requesting 1 node for preallocation and then
>> ,depending on the type of store, will update the request variable. There
>> isn't a check for a slot store type, so slot stores are preallocating the
>> default 1 node. Slot stores do not require any additional nodes, so add a
>> check for the slot store case that will bypass node_count_gfp(). Update
>> the tests to reflect that slot stores do not require allocations.
>>
>> User visible effects of this bug include increased memory usage from the
>> unneeded node that was allocated.
>>
>> Fixes: 0b8bb544b1a7 ("maple_tree: update mas_preallocate() testing")
>> Cc: <stable@vger.kernel.org> # 6.6+
>> Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
>> ---
>> This is a modified backport as the patch to fix this in upstream does not
>> apply to 6.6 because the node_end field was moved from the ma_wr_state to
>> the ma_state after 6.6.
> 
> What is the git commit id of this change in Linus's tree?

The patch is in akpm's mm-hotfixes-unstable tree and has not made it to Linus's 
tree yet.

Thanks,
Sid
> 
> thanks,
> 
> greg k-h
Greg KH Dec. 30, 2023, 11:43 a.m. UTC | #4
On Mon, Dec 18, 2023 at 09:53:53AM -0800, Sidhartha Kumar wrote:
> On 12/18/23 2:59 AM, Greg KH wrote:
> > On Tue, Dec 12, 2023 at 11:52:55AM -0800, Sidhartha Kumar wrote:
> > > mas_preallocate() defaults to requesting 1 node for preallocation and then
> > > ,depending on the type of store, will update the request variable. There
> > > isn't a check for a slot store type, so slot stores are preallocating the
> > > default 1 node. Slot stores do not require any additional nodes, so add a
> > > check for the slot store case that will bypass node_count_gfp(). Update
> > > the tests to reflect that slot stores do not require allocations.
> > > 
> > > User visible effects of this bug include increased memory usage from the
> > > unneeded node that was allocated.
> > > 
> > > Fixes: 0b8bb544b1a7 ("maple_tree: update mas_preallocate() testing")
> > > Cc: <stable@vger.kernel.org> # 6.6+
> > > Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> > > ---
> > > This is a modified backport as the patch to fix this in upstream does not
> > > apply to 6.6 because the node_end field was moved from the ma_wr_state to
> > > the ma_state after 6.6.
> > 
> > What is the git commit id of this change in Linus's tree?
> 
> The patch is in akpm's mm-hotfixes-unstable tree and has not made it to
> Linus's tree yet.

Ok, please resend when it hits Linus's tree.
diff mbox series

Patch

diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index bb24d84a4922f..5950d0c0e0f69 100644
--- a/lib/maple_tree.c
+++ b/lib/maple_tree.c
@@ -5501,6 +5501,12 @@  int mas_preallocate(struct ma_state *mas, void *entry, gfp_t gfp)
 
 	mas_wr_end_piv(&wr_mas);
 	node_size = mas_wr_new_end(&wr_mas);
+
+	/* Slot store, does not require additional nodes */
+	if ((node_size == wr_mas.node_end) && ((!mt_in_rcu(mas->tree))
+		|| (wr_mas.offset_end - mas->offset == 1)))
+		return 0;
+
 	if (node_size >= mt_slots[wr_mas.type]) {
 		/* Split, worst case for now. */
 		request = 1 + mas_mt_height(mas) * 2;
diff --git a/tools/testing/radix-tree/maple.c b/tools/testing/radix-tree/maple.c
index e5da1cad70baf..76a8990bb14e8 100644
--- a/tools/testing/radix-tree/maple.c
+++ b/tools/testing/radix-tree/maple.c
@@ -35538,7 +35538,7 @@  static noinline void __init check_prealloc(struct maple_tree *mt)
 	MT_BUG_ON(mt, mas_preallocate(&mas, ptr, GFP_KERNEL) != 0);
 	allocated = mas_allocated(&mas);
 	height = mas_mt_height(&mas);
-	MT_BUG_ON(mt, allocated != 1);
+	MT_BUG_ON(mt, allocated != 0);
 	mas_store_prealloc(&mas, ptr);
 	MT_BUG_ON(mt, mas_allocated(&mas) != 0);