Skip to content

Commit 28e1a8f

Browse files
tjy-zhurppt
authored andcommitted
memblock: avoid some repeat when add new range
The worst case is that the new memory range overlaps all existing regions, which requires type->cnt + 1 empty struct memblock_region slots in the type->regions array. So if type->cnt + 1 + type->cnt is less than type->max, we can insert regions directly rather than calculate the needed amount before the insertion. And becase of merge operation in the end of function, tpye->cnt will increase slowly for many cases. This change allows to avoid unnecessary repeat of memblock ranges traversal for many cases when adding new memory range. Signed-off-by: Jinyu Tang <[email protected]> [rppt: massaged comment and changelog text] Signed-off-by: Mike Rapoport <[email protected]>
1 parent 03c765b commit 28e1a8f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

mm/memblock.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,17 @@ static int __init_memblock memblock_add_range(struct memblock_type *type,
593593
type->total_size = size;
594594
return 0;
595595
}
596+
597+
/*
598+
* The worst case is when new range overlaps all existing regions,
599+
* then we'll need type->cnt + 1 empty regions in @type. So if
600+
* type->cnt * 2 + 1 is less than type->max, we know
601+
* that there is enough empty regions in @type, and we can insert
602+
* regions directly.
603+
*/
604+
if (type->cnt * 2 + 1 < type->max)
605+
insert = true;
606+
596607
repeat:
597608
/*
598609
* The following is executed twice. Once with %false @insert and

0 commit comments

Comments
 (0)