From patchwork Fri Jan 13 08:26:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 43071 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp151809wrt; Fri, 13 Jan 2023 00:30:02 -0800 (PST) X-Google-Smtp-Source: AMrXdXtemfgBJ3L+69mKXZ+Ol1FPSvCcIpD5kcTTs8ZEgbTrCyqtBSawO2odFwVrxCodMuTcVxOy X-Received: by 2002:a05:6a00:4c8c:b0:581:61a7:c8f0 with SMTP id eb12-20020a056a004c8c00b0058161a7c8f0mr58452439pfb.4.1673598601867; Fri, 13 Jan 2023 00:30:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673598601; cv=none; d=google.com; s=arc-20160816; b=EBeqD2MsvzyKkeFGBhGIqVjkN5i1zs2x7Cm5ZVX1bnQynXWrIrST+RRLx3wYUwmyO7 hVTGaKRIeO+TJzJx9o4s7uGJcMSyXRkcErJQFozs1u0sNp3JsKENKc8gvacNuEwrRUg6 5ybuLUUcFHXaIcyaq9KSkYF61YDSsEPIPyXzGToKDMP0BhwZRArz1tXcbt8MSYpweM08 7vjZmvA6MgxZujSTFNgqu90OYAU63EPiR+l9zbVIhRpeUFzFlpNveXYTu+xKCFchEEmT SigrLNEezKCNuG9j8sYXniRfSdGahq//gtVeoc3tha8rKpAiBjg0SEg33Lz+uQe8SOr+ i+0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Q4Az0GQIpAo5qLK4eslBRX7WJSl1cxutE/mioG/uZxc=; b=bD5rIkKpOeboqdDflHRv0haD/l6zFmbgZDGrmTPF3IiliuKaSSppPugCdG5PGU8Vnj pkQ3KfyPY/9CEqm9JzpkaGB976f+pvpS1s6CLmhxn1su1+D+G7efH4vtXjufUYMZMjEI itJcuYAbUpKjvbfwH11hTQJ7dpcoAxXhn5r2f68w0dBJzCk+IKJD1b6aLgx4XLIOTkTh jzu59k41yxpcofVS4Drw6HwVyufaYh+n78A00KclM2DDHlhk2mbbxCbsDNE1GyvmIG7V uHHxiJouwueGQWGYUVXgkCY2LZZ9hmXMG1inFWc2G/5P3dsh4nEimm5P8m/WKf8CigXB EOMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=MpnWYaJF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u17-20020a056a00099100b00581e4ef2df9si20080206pfg.207.2023.01.13.00.29.49; Fri, 13 Jan 2023 00:30:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=MpnWYaJF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234853AbjAMI2N (ORCPT + 99 others); Fri, 13 Jan 2023 03:28:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232007AbjAMI1l (ORCPT ); Fri, 13 Jan 2023 03:27:41 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D10B342633 for ; Fri, 13 Jan 2023 00:27:16 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id z1-20020a17090a66c100b00226f05b9595so8584942pjl.0 for ; Fri, 13 Jan 2023 00:27:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q4Az0GQIpAo5qLK4eslBRX7WJSl1cxutE/mioG/uZxc=; b=MpnWYaJF2T4qlC9e913gYzl9AiD8aMnsvQKAqLMg1yjsF0soBswn5aF6VSp72MhgAY 2g1ioFdZFpeEptHS5Sm2x3Qgtz45T3zAYavuNbvTxLAbmG/8Up0DSPdD6FjIMBbuf++z dD5W8xWo6PA1QZ67Tit3KfPwWe/sqvW96xIpG/jn+owrIeO3WTd3MetvHFgZ7sDV1+XV owF5gECfqxzfyOuGrjseOKHUtJEzOhq02ccaTKLB5WdzfWOYT3DnaniY/u5eJALne30V 10JMG9ugSSxV3R/E/LOj1nLFQefTA2CuZIUEfsE/GV68ojR8OnoK2zg8HWRRwTnyD2+X KyaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q4Az0GQIpAo5qLK4eslBRX7WJSl1cxutE/mioG/uZxc=; b=d9hQ4vS4MuvQht4ZNC/IAefBEcNzhBp6A/Z+Y7y67Sip6pDa7BIfmcZ7u19SHP9Yaj oBUJN/lHG0eV7+uif0XdXqEBsLK9UCQczOSwdGayt6dTzJQgMzX1Naptp80fFpeu4nw4 4o5Th3VYH5/2K21GAkVowrDoK0bHBFnTJhRauRBAM+Hy7QW8jdtDNMUDtSCd8MhPDMC1 PHg7m3VXN6a26mVOGiA45CgWhCpRypAgGzeJAqHtaaGqXGoFLMbNpdglrURubYSqRrlA xFqhSs4E602SFw0RDvY7xcRU84jUqPNfb/xFNcCOt/mKX7hVP+0Dmi7h6xO9B4YxT6Xq Z6zg== X-Gm-Message-State: AFqh2krucnsPYF8AdF0Q7VWKXTwp+U/SYYZggjfo/x9zPVQppQyVu+ja 0/w3s03a7y0nw35YgzoJF/WNUA== X-Received: by 2002:a05:6a20:9f48:b0:ac:29b6:a235 with SMTP id ml8-20020a056a209f4800b000ac29b6a235mr91778538pzb.54.1673598436328; Fri, 13 Jan 2023 00:27:16 -0800 (PST) Received: from GL4FX4PXWL.bytedance.net ([139.177.225.251]) by smtp.gmail.com with ESMTPSA id l123-20020a622581000000b005818d429d98sm13092738pfl.136.2023.01.13.00.27.13 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 13 Jan 2023 00:27:16 -0800 (PST) From: Peng Zhang To: rppt@kernel.org, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Peng Zhang Subject: [PATCH 3/3] memblock: Avoid useless checks in memblock_merge_regions(). Date: Fri, 13 Jan 2023 16:26:59 +0800 Message-Id: <20230113082659.65276-4-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230113082659.65276-1-zhangpeng.00@bytedance.com> References: <20230113082659.65276-1-zhangpeng.00@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754895327655124432?= X-GMAIL-MSGID: =?utf-8?q?1754895327655124432?= memblock_merge_regions() is called after regions have been modified to merge the neighboring compatible regions. That will check all regions but most checks is 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 regions. We only need to check the changed regions, because other not related regions cannot be merged. So this patch add two parameters to memblock_merge_regions() to indicate the lower and upper boundary to scan. Signed-off-by: Peng Zhang --- mm/memblock.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/mm/memblock.c b/mm/memblock.c index cb92770ac22e..e19eb08efc73 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -523,15 +523,18 @@ static int __init_memblock memblock_double_array(struct memblock_type *type, /** * memblock_merge_regions - merge neighboring compatible regions * @type: memblock type to scan - * - * Scan @type and merge neighboring compatible regions. + * @start_rgn: start scanning from (@start_rgn - 1) + * @end_rgn: end scanning at (@end_rgn - 1) + * Scan @type and merge neighboring compatible regions in [@start_rgn - 1, @end_rgn) */ -static void __init_memblock memblock_merge_regions(struct memblock_type *type) +static void __init_memblock memblock_merge_regions(struct memblock_type *type, + int start_rgn, + int end_rgn) { - int i = 0; + int i = max(start_rgn - 1, 0); - /* cnt never goes below 1 */ - while (i < type->cnt - 1) { + end_rgn = min(end_rgn, (int)type->cnt - 1); + while (i < end_rgn) { struct memblock_region *this = &type->regions[i]; struct memblock_region *next = &type->regions[i + 1]; @@ -548,6 +551,7 @@ static void __init_memblock memblock_merge_regions(struct memblock_type *type) /* move forward from next + 1, index of which is i + 2 */ memmove(next, next + 1, (type->cnt - (i + 2)) * sizeof(*next)); type->cnt--; + end_rgn--; } } @@ -604,7 +608,7 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, bool insert = false; phys_addr_t obase = base; phys_addr_t end = base + memblock_cap_size(base, &size); - int idx, start_idx, nr_new; + int idx, start_idx, nr_new, start_rgn = -1, end_rgn; struct memblock_region *rgn; if (!size) @@ -659,10 +663,14 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, #endif WARN_ON(flags != rgn->flags); nr_new++; - if (insert) + if (insert) { + if (start_rgn == -1) + start_rgn = idx; + end_rgn = idx + 1; memblock_insert_region(type, idx++, base, rbase - base, nid, flags); + } } /* area below @rend is dealt with, forget about it */ base = min(rend, end); @@ -671,9 +679,13 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, /* insert the remaining portion */ if (base < end) { nr_new++; - if (insert) + if (insert) { + if (start_rgn == -1) + start_rgn = idx; + end_rgn = idx + 1; memblock_insert_region(type, idx, base, end - base, nid, flags); + } } if (!nr_new) @@ -690,7 +702,7 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, insert = true; goto repeat; } else { - memblock_merge_regions(type); + memblock_merge_regions(type, start_rgn, end_rgn); return 0; } } @@ -927,7 +939,7 @@ static int __init_memblock memblock_setclr_flag(phys_addr_t base, r->flags &= ~flag; } - memblock_merge_regions(type); + memblock_merge_regions(type, start_rgn, end_rgn); return 0; } @@ -1300,7 +1312,7 @@ int __init_memblock memblock_set_node(phys_addr_t base, phys_addr_t size, for (i = start_rgn; i < end_rgn; i++) memblock_set_region_node(&type->regions[i], nid); - memblock_merge_regions(type); + memblock_merge_regions(type, start_rgn, end_rgn); #endif return 0; }