memblock: Avoid useless checks in memblock_merge_regions().
authorPeng Zhang <zhangpeng.00@bytedance.com>
Sun, 29 Jan 2023 09:00:34 +0000 (17:00 +0800)
committerMike Rapoport (IBM) <rppt@kernel.org>
Tue, 31 Jan 2023 13:51:56 +0000 (15:51 +0200)
commit2fe03412e2e1be3d5ab37b8351a37c3aec506556
tree62276218dce64352cc252c0929e74723d341fb42
parentad500fb2d11b3739dcbc17a31976828b9161ecf5
memblock: Avoid useless checks in memblock_merge_regions().

memblock_merge_regions() is called after regions have been modified to
merge the neighboring compatible regions. That will check all regions
but most checks are useless.

Most of the time we only insert one or a few new regions, or modify one or
a few regions. At this time, we don't need to check all the regions. We
only need to check the changed regions, because other not related regions
cannot be merged.

Add two parameters to memblock_merge_regions() to indicate the lower and
upper boundary to scan.

Debug code that counts the number of total iterations in
memblock_merge_regions(), like for instance

void memblock_merge_regions(struct memblock_type *type)
{
static int iteration_count = 0;
static int max_nr_regions = 0;

max_nr_regions = max(max_nr_regions, (int)type->cnt);
...
while () {
iteration_count++;
...
}
pr_info("iteration_count: %d max_nr_regions %d", iteration_count,
max_nr_regions);
}

Produces the following numbers on a physical machine with 1T of memory:

before: [2.472243] iteration_count: 45410 max_nr_regions 178
after:  [2.470869] iteration_count: 923 max_nr_regions 176

The actual startup speed seems to change little, but it does reduce the
scan overhead.

Signed-off-by: Peng Zhang <zhangpeng.00@bytedance.com>
Link: https://lore.kernel.org/r/20230129090034.12310-3-zhangpeng.00@bytedance.com
[rppt: massaged the changelog]
Signed-off-by: Mike Rapoport (IBM) <rppt@kernel.org>
mm/memblock.c