From: Wei Yang <richard.weiyang@gmail.com>
To: rppt@kernel.org, akpm@linux-foundation.org
Cc: linux-mm@kvack.org, Wei Yang <richard.weiyang@gmail.com>
Subject: [Patch v2 4/8] mm/memblock: remove consecutive regions at once
Date: Thu, 25 Apr 2024 07:19:25 +0000 [thread overview]
Message-ID: <20240425071929.18004-5-richard.weiyang@gmail.com> (raw)
In-Reply-To: <20240425071929.18004-1-richard.weiyang@gmail.com>
In memblock_remove_range, we would remove consecutive regions after
isolation.
Instead of removing each region from end to start one by one, we could
remove those consecutive regions at once.
Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
---
mm/memblock.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/mm/memblock.c b/mm/memblock.c
index 5a363ef283d0..53e3aa2cd9a2 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -343,12 +343,15 @@ static phys_addr_t __init_memblock memblock_find_in_range(phys_addr_t start,
return ret;
}
-static void __init_memblock memblock_remove_region(struct memblock_type *type, unsigned long r)
+static void __init_memblock memblock_remove_regions(struct memblock_type *type,
+ unsigned long r,
+ unsigned int num)
{
- type->total_size -= type->regions[r].size;
- memmove(&type->regions[r], &type->regions[r + 1],
- (type->cnt - (r + 1)) * sizeof(type->regions[r]));
- type->cnt--;
+ for (int i = 0; i < num; i++)
+ type->total_size -= type->regions[r + i].size;
+ memmove(&type->regions[r], &type->regions[r + num],
+ (type->cnt - (r + num)) * sizeof(type->regions[r]));
+ type->cnt -= num;
/* Special case for empty arrays */
if (type->cnt == 0) {
@@ -360,6 +363,11 @@ static void __init_memblock memblock_remove_region(struct memblock_type *type, u
}
}
+static void __init_memblock memblock_remove_region(struct memblock_type *type, unsigned long r)
+{
+ memblock_remove_regions(type, r, 1);
+}
+
#ifndef CONFIG_ARCH_KEEP_MEMBLOCK
/**
* memblock_discard - discard memory and reserved arrays if they were allocated
@@ -846,14 +854,14 @@ static int __init_memblock memblock_remove_range(struct memblock_type *type,
phys_addr_t base, phys_addr_t size)
{
int start_rgn, end_rgn;
- int i, ret;
+ int ret;
ret = memblock_isolate_range(type, base, size, &start_rgn, &end_rgn);
if (ret)
return ret;
- for (i = end_rgn - 1; i >= start_rgn; i--)
- memblock_remove_region(type, i);
+ if (end_rgn - start_rgn)
+ memblock_remove_regions(type, start_rgn, end_rgn - start_rgn);
return 0;
}
--
2.34.1
next prev parent reply other threads:[~2024-04-25 7:20 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-25 7:19 [Patch v2 0/8] memblock: clenup Wei Yang
2024-04-25 7:19 ` [Patch v2 1/8] memblock tests: reserve the 129th memory block at all possible position Wei Yang
2024-04-28 6:35 ` Mike Rapoport
2024-04-28 12:22 ` Wei Yang
2024-04-29 14:17 ` Mike Rapoport
2024-04-30 0:12 ` Wei Yang
2024-04-25 7:19 ` Wei Yang [this message]
2024-04-28 6:44 ` [Patch v2 4/8] mm/memblock: remove consecutive regions at once Mike Rapoport
2024-04-28 12:37 ` Wei Yang
2024-04-25 7:19 ` [Patch v2 5/8] memblock tests: add memblock_overlaps_region_checks Wei Yang
2024-04-25 7:19 ` [Patch v2 6/8] mm/memblock: return true directly on finding overlap region Wei Yang
2024-04-25 7:19 ` [Patch v2 7/8] mm/memblock: use PAGE_ALIGN_DOWN to get pgend in free_memmap Wei Yang
2024-04-25 7:19 ` [Patch v2 8/8] mm/memblock: default region's nid may be MAX_NUMNODES Wei Yang
[not found] ` <20240425071929.18004-3-richard.weiyang@gmail.com>
2024-04-28 6:40 ` [Patch v2 2/8] memblock tests: add memblock_reserve_many_may_conflict_check() Mike Rapoport
2024-04-28 12:36 ` Wei Yang
2024-04-30 1:49 ` Wei Yang
2024-05-01 8:44 ` Mike Rapoport
[not found] ` <20240425071929.18004-4-richard.weiyang@gmail.com>
2024-04-28 6:43 ` [Patch v2 3/8] mm/memblock: fix comment for memblock_isolate_range() Mike Rapoport
2024-04-28 13:07 ` Wei Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240425071929.18004-5-richard.weiyang@gmail.com \
--to=richard.weiyang@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-mm@kvack.org \
--cc=rppt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).