From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91AD9C43334 for ; Mon, 13 Jun 2022 04:45:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231312AbiFMEpe (ORCPT ); Mon, 13 Jun 2022 00:45:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229499AbiFMEp1 (ORCPT ); Mon, 13 Jun 2022 00:45:27 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B64D913C for ; Sun, 12 Jun 2022 21:45:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4DCEFB80D24 for ; Mon, 13 Jun 2022 04:45:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95920C34114; Mon, 13 Jun 2022 04:45:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655095523; bh=2gfgxSOdN8ePd6U0tBQuA784FmmxwA8r9uHQ7gR3/oE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=g+cruqpI45jzQMW0rt7fI1hjfkO7NkqcsGb66LHPXMdW3qe+lz99Ev2OYARQBOWMY vsfu+fsvdpCzUJ77QHleih83BohVwDFFkNGS7tBfYvp9DSggteapHvGiEV2Dp83Rsp Sg+lPkh1Bt6+UKNJ634+yPRhn+6Q7NRl7IpISHgqzeNbJdqOtG6mHJAX0oydfhBXdM qAkCZ9EVts9IvzLKPW/y9W6AbVRQP5XsF2hTwSJMgiV80fr7mxJD1Ed5N0nu8Q/SZU 8wNHu+EmXMHud8eVJovTSEdMaQUfnDjSEIWyU4YISGSL7P5mYeT7GloEL+HOh2UhTC grfYF8/qagnhA== Date: Mon, 13 Jun 2022 07:45:18 +0300 From: Mike Rapoport To: tjytimi Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] memblock: avoid some repeat when add new range Message-ID: References: <20220609024122.6679-1-tjytimi@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220609024122.6679-1-tjytimi@163.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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.