All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] memblock: avoid some repeat when add new range
@ 2022-06-15  9:40 Jinyu Tang
  2022-06-26 14:05 ` Mike Rapoport
  0 siblings, 1 reply; 2+ messages in thread
From: Jinyu Tang @ 2022-06-15  9:40 UTC (permalink / raw)
  To: rppt; +Cc: akpm, linux-mm, linux-kernel, Jinyu Tang

The worst case is that the new memory range overlaps all existing
regions,which need type->cnt + 1 free area of struct memblock_region.
So if type->cnt + 1 + type->cnt is less than type->max,we can insert
regions directly.And becase of merge operation in the end of function,
tpye->cnt increase slowly for many cases.So this patch can avoid
unnecessary repeat for many cases when add new memory range.

Signed-off-by: Jinyu Tang <tjytimi@163.com>
---
V1 -> V2: 1.Change the code as reviewer suggestions
           2.Add comment in the code
           3.Move the code above the repeat lable, because if reapeat
           code executed twice, insert is already true and don't need
           to test

 mm/memblock.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/mm/memblock.c b/mm/memblock.c
index e4f03a6e8..e94661fd3 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -593,6 +593,17 @@ static int __init_memblock memblock_add_range(struct memblock_type *type,
 		type->total_size = size;
 		return 0;
 	}
+
+	/*
+	 * The max free regions needed is when new range overlaps all existing
+	 * regions, which will cost type->cnt + 1 free regions. So if
+	 * type->cnt * 2 + 1 is less than type->max, We can confirmed
+	 * that there is enough number of regions, and we can insert
+	 * regions directly.
+	 */
+	if (type->cnt * 2 + 1 < type->max)
+		insert = true;
+
 repeat:
 	/*
 	 * The following is executed twice.  Once with %false @insert and
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] memblock: avoid some repeat when add new range
  2022-06-15  9:40 [PATCH v2] memblock: avoid some repeat when add new range Jinyu Tang
@ 2022-06-26 14:05 ` Mike Rapoport
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Rapoport @ 2022-06-26 14:05 UTC (permalink / raw)
  To: Jinyu Tang; +Cc: akpm, linux-mm, linux-kernel

On Wed, Jun 15, 2022 at 05:40:15PM +0800, Jinyu Tang wrote:
> The worst case is that the new memory range overlaps all existing
> regions,which need type->cnt + 1 free area of struct memblock_region.
> So if type->cnt + 1 + type->cnt is less than type->max,we can insert
> regions directly.And becase of merge operation in the end of function,
> tpye->cnt increase slowly for many cases.So this patch can avoid
> unnecessary repeat for many cases when add new memory range.
> 
> Signed-off-by: Jinyu Tang <tjytimi@163.com>

Applied to memblock/for-kernelci with minor changes to comment and
changelog text.

Thanks,
Mike.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-26 14:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-15  9:40 [PATCH v2] memblock: avoid some repeat when add new range Jinyu Tang
2022-06-26 14:05 ` Mike Rapoport

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.