* [PATCH] memblock: avoid some repeat when add new range
@ 2022-06-09 2:41 tjytimi
2022-06-13 4:45 ` Mike Rapoport
2022-06-14 7:52 ` Yixun Lan
0 siblings, 2 replies; 3+ messages in thread
From: tjytimi @ 2022-06-09 2:41 UTC (permalink / raw)
To: rppt, akpm; +Cc: linux-mm, linux-kernel, tjytimi
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: tjytimi <tjytimi@163.com>
---
mm/memblock.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/memblock.c b/mm/memblock.c
index e4f03a6e8..243cd7de5 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -602,6 +602,9 @@ static int __init_memblock memblock_add_range(struct memblock_type *type,
base = obase;
nr_new = 0;
+ if (type->cnt<<1 < type->max - 1)
+ insert = true;
+
for_each_memblock_type(idx, type, rgn) {
phys_addr_t rbase = rgn->base;
phys_addr_t rend = rbase + rgn->size;
--
2.32.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] memblock: avoid some repeat when add new range
2022-06-09 2:41 [PATCH] memblock: avoid some repeat when add new range tjytimi
@ 2022-06-13 4:45 ` Mike Rapoport
2022-06-14 7:52 ` Yixun Lan
1 sibling, 0 replies; 3+ messages in thread
From: Mike Rapoport @ 2022-06-13 4:45 UTC (permalink / raw)
To: tjytimi; +Cc: akpm, linux-mm, linux-kernel
On Thu, Jun 09, 2022 at 10:41:22AM +0800, tjytimi 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: tjytimi <tjytimi@163.com>
> ---
> mm/memblock.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/mm/memblock.c b/mm/memblock.c
> index e4f03a6e8..243cd7de5 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -602,6 +602,9 @@ static int __init_memblock memblock_add_range(struct memblock_type *type,
> base = obase;
> nr_new = 0;
>
> + if (type->cnt<<1 < type->max - 1)
> + insert = true;
> +
Several things here:
- cnt * 2 looks clearer than cnt << 1 and the performance difference (if
any) is negligible
- I think checking that cnt + 1 < max is easier to read
- there should be space around operators, i.e. cnt << 1
I'd also appreciate a comment in the code with the explanation similar
to the changelog
> for_each_memblock_type(idx, type, rgn) {
> phys_addr_t rbase = rgn->base;
> phys_addr_t rend = rbase + rgn->size;
> --
> 2.32.0
>
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] memblock: avoid some repeat when add new range
2022-06-09 2:41 [PATCH] memblock: avoid some repeat when add new range tjytimi
2022-06-13 4:45 ` Mike Rapoport
@ 2022-06-14 7:52 ` Yixun Lan
1 sibling, 0 replies; 3+ messages in thread
From: Yixun Lan @ 2022-06-14 7:52 UTC (permalink / raw)
To: tjytimi; +Cc: rppt, akpm, linux-mm, linux-kernel
On 10:41 Thu 09 Jun , tjytimi 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: tjytimi <tjytimi@163.com>
Can you fix the author/signed-off tag with your real legal name?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v4.18#n460
> ---
> mm/memblock.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/mm/memblock.c b/mm/memblock.c
> index e4f03a6e8..243cd7de5 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -602,6 +602,9 @@ static int __init_memblock memblock_add_range(struct memblock_type *type,
> base = obase;
> nr_new = 0;
>
> + if (type->cnt<<1 < type->max - 1)
> + insert = true;
> +
> for_each_memblock_type(idx, type, rgn) {
> phys_addr_t rbase = rgn->base;
> phys_addr_t rend = rbase + rgn->size;
> --
> 2.32.0
>
--
Yixun Lan (dlan)
Gentoo Linux Developer
GPG Key ID AABEFD55
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-14 7:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-09 2:41 [PATCH] memblock: avoid some repeat when add new range tjytimi
2022-06-13 4:45 ` Mike Rapoport
2022-06-14 7:52 ` Yixun Lan
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.