From: Jinyu Tang Date: Wed, 15 Jun 2022 09:40:15 +0000 (+0800) Subject: memblock: avoid some repeat when add new range X-Git-Tag: v6.0-rc1~51^2~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=28e1a8f4b0ff1eafc320ec733b9c61ee7eb633ea;p=thirdparty%2Fkernel%2Flinux.git 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 [rppt: massaged comment and changelog text] Signed-off-by: Mike Rapoport --- diff --git a/mm/memblock.c b/mm/memblock.c index e4f03a6e8e56e..16f006521afad 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 worst case is when new range overlaps all existing regions, + * then we'll need type->cnt + 1 empty regions in @type. So if + * type->cnt * 2 + 1 is less than type->max, we know + * that there is enough empty regions in @type, 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