From patchwork Wed Sep 4 11:55:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qiang Liu X-Patchwork-Id: 13790663 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 351D3CD3431 for ; Wed, 4 Sep 2024 11:56:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A6A8C8D0255; Wed, 4 Sep 2024 07:56:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A1A5B8D0253; Wed, 4 Sep 2024 07:56:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E1928D0255; Wed, 4 Sep 2024 07:56:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6CC948D0253 for ; Wed, 4 Sep 2024 07:56:09 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D00A61C4B9E for ; Wed, 4 Sep 2024 11:56:08 +0000 (UTC) X-FDA: 82526902416.01.6061F7E Received: from chinatelecom.cn (smtpnm6-02.21cn.com [182.42.154.78]) by imf01.hostedemail.com (Postfix) with ESMTP id BC73140014 for ; Wed, 4 Sep 2024 11:56:05 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of liuq131@chinatelecom.cn designates 182.42.154.78 as permitted sender) smtp.mailfrom=liuq131@chinatelecom.cn; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725450942; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=Tyi4J1mAr6WLyp4KPFNbRYQMABXXt3a2cbJ1qFG29vA=; b=pihQpQNfmPMXpjrnOo++nWgqBI12cHqqe4Wz7KMd+zoXawjXg0mp/PK5ov+bCSdMTWOzV2 on4mMhr6pmZLJVDLggw920SjXDob3nAK24DhHbSttggH7Y2CLzyVuYs5M7hKVRA0LlKMKy Xlc9W8D59tbQnDRN3pVFe4nWPSSB1Os= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of liuq131@chinatelecom.cn designates 182.42.154.78 as permitted sender) smtp.mailfrom=liuq131@chinatelecom.cn; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725450942; a=rsa-sha256; cv=none; b=QzBbuOyHNMHNhH3OKFnYOya3Stt83+ZETEG4YiQcjhD+eZOHD/ORw+WMylN9TD7wUUzZiL Zbo1ZZoH11Xa95HV0l7CJB+6NEbw7uE+webX515WDe5zK67pLRHyO/ORAADZwvf+vblI/l QL03ft1Rs5BflMY7gGP3GZrYGeiagHk= HMM_SOURCE_IP: 192.168.139.44:0.676036293 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-36.111.64.85 (unknown [192.168.139.44]) by chinatelecom.cn (HERMES) with SMTP id 9AB8012493AAD; Wed, 4 Sep 2024 19:55:54 +0800 (CST) X-189-SAVE-TO-SEND: +liuq131@chinatelecom.cn Received: from ([36.111.64.85]) by gateway-ssl-dep-67bdc54df-cz88j with ESMTP id 50f9eb8ac02841c4a3715450ac640d7c for rppt@kernel.org; Wed, 04 Sep 2024 19:56:01 CST X-Transaction-ID: 50f9eb8ac02841c4a3715450ac640d7c X-Real-From: liuq131@chinatelecom.cn X-Receive-IP: 36.111.64.85 X-MEDUSA-Status: 0 From: Qiang Liu To: rppt@kernel.org, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qiang Liu Subject: [PATCH] mm/mm_init.c: add zidcache to the init_reserved_page function Date: Wed, 4 Sep 2024 19:55:41 +0800 Message-Id: <20240904115541.6519-1-liuq131@chinatelecom.cn> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: n4pb5ar4i1rtd3q1pn4px6kiq7fr8qhx X-Rspamd-Queue-Id: BC73140014 X-Rspamd-Server: rspam11 X-HE-Tag: 1725450965-674502 X-HE-Meta: U2FsdGVkX18kKotXdAqsffAzdSS3fybAxZG45G5/1cIx2lqxT1AciuYDTD19PoYGsc5kGj6n1daVL5JGjMJln8oJKGz974Mooc9Akhb/W5W7uB+dl+MJks8vTOLoAfdYm2V98BQv/+86jS6qhc5ERmBiFJL9EKnZW/TSZbjS5dH/amBr2LN+fvRYeGB/qNGxej2Rz6EVJdgLQR3RVsjRVg6oH+TE0MZYyjDczY33Ke+5VdEowtaselNeXx3AgsJ6N0kgXMBfiuuks/sEegcOCd4sF9JlSufdJ+eSP0Ah/jsIK3erpkWQPaL0K32E/S3H1E9OcamNEC+55lFoGB8UUDgMeRpwnJdzYuNGkW5ME7uTWoMCIvpZiWwsJEc2r52nHVdvA7eBK/MXJ7oTTqJsopgzR2W8xhz+ZDnNnMVn4k4TIO8GdBprItAOdpA6Ed3FzOneq4NOvYGwm4gfEq7DxKHw3702l+A5EUhWIvnuslND5ML3WAhkL1DLMRlpCqe6UuJ852XpB0ZFpwBKMK/LVrx1V04lNYb5PqPfjp8BEEbOHIDAQTA4TTwDJxcJuD5Ahd6t5zLITgcIGLBTmuGlwYI6PNGUay2C/DD2EtqLC1viR6BSbe0Yx7zeacVLHI9iZAgNmQfw/LWPU9VOmexwD131APbkUNvywut9r6KdiYsBXFnej0cKuHNMAtW78J6DFzpeuHhbTZFWhXWsTqxMS3ytByWUKDizuvyApAOmwIYtCAKpO708nG7J9C5W7znoTV2yDhnNVYvzuiPDsLbk78wo+iHdt40mSj4riUo+Mrqm3rYx+MxbI489uJsyrl6r1bycINyCY0jDIaKkK1KSofxgN68/Ad7Y7hKacZnIemYZJJxtySikGf1AUlFfinuHDRaTpWzWluEoYjD8M3U/iZg6kJCuq1FPDypvZA3I/UZUeF+Lb+zhakgQSSVZe2H/7I5a1SKW/ufZx+GKyze oxwUwTW7 ZpiA0XIzTzeNSLSsQgUwLcVRUy2Tq0hlnaQireGF6Rbjf/BotDc+YsGDu0Jwo5dZ/CBsOP4ulbxY+iOJdkGtn5fdbP/DKEjFhp3upzUz77UH7r7Si8C/JkrtQ15b1vB5sMHQh30Uxt4KHijA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.064299, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Each call to the init_reserved_page function will look up the corresponding zid for the given pfn parameter. Even if subsequent calls have the same zid for the pfn as the current one, the lookup will be repeated. During system initialization, the memmap_init_reserved_pages function calls init_reserved_page for each contiguous memory region in mem_region. Implementing a cache for zid can significantly improve performance. Tests have shown that adding a zid cache reduces the execution time of the memmap_init_reserved_pages function by over 7%. Signed-off-by: Qiang Liu --- mm/mm_init.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mm/mm_init.c b/mm/mm_init.c index 51960079875b..2d5b5ffa962b 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -710,19 +710,25 @@ static void __meminit init_reserved_page(unsigned long pfn, int nid) { pg_data_t *pgdat; int zid; + struct zone *zone; + static int zidcache; if (early_page_initialised(pfn, nid)) return; pgdat = NODE_DATA(nid); - for (zid = 0; zid < MAX_NR_ZONES; zid++) { - struct zone *zone = &pgdat->node_zones[zid]; + zone = &pgdat->node_zones[zidcache]; + if (unlikely(zone_spans_pfn(zone, pfn))) + for (zid = 0; zid < MAX_NR_ZONES; zid++) { + zone = &pgdat->node_zones[zid]; - if (zone_spans_pfn(zone, pfn)) - break; - } - __init_single_page(pfn_to_page(pfn), pfn, zid, nid); + if (zone_spans_pfn(zone, pfn)) { + zidcache = zid; + break; + } + } + __init_single_page(pfn_to_page(pfn), pfn, zidcache, nid); } #else static inline void pgdat_set_deferred_range(pg_data_t *pgdat) {}