From patchwork Fri Jun 16 02:30:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yajun Deng X-Patchwork-Id: 13281951 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 A55FCEB64DA for ; Fri, 16 Jun 2023 02:30:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E39726B0074; Thu, 15 Jun 2023 22:30:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DC2808E0001; Thu, 15 Jun 2023 22:30:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C636C6B0078; Thu, 15 Jun 2023 22:30:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B265E6B0074 for ; Thu, 15 Jun 2023 22:30:28 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 759BE1A0BB7 for ; Fri, 16 Jun 2023 02:30:28 +0000 (UTC) X-FDA: 80907032136.20.38F8C49 Received: from out-54.mta0.migadu.com (out-54.mta0.migadu.com [91.218.175.54]) by imf06.hostedemail.com (Postfix) with ESMTP id 85D51180005 for ; Fri, 16 Jun 2023 02:30:26 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=lUns9qrR; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf06.hostedemail.com: domain of yajun.deng@linux.dev designates 91.218.175.54 as permitted sender) smtp.mailfrom=yajun.deng@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686882627; h=from:from: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:dkim-signature; bh=4AulDYoE3pAHZf4DySsjoslFcIuvn9gDgjSjn9hQRpg=; b=UsB6X5JHUQCr3OhhVNn59Fc0p44lSFfZB8/WwVhkfzDgnehlOxwZdbDimmLS4I968Wh290 BJDV13w3CSyg7cMSe/5/BrJcy8yD9/u/ehSoGA1BWif0gmKcrbksx0N5wqar7kRgRx7zl8 /7Ub6ZMsDusVOm1+/s0I03S2mXN/S5g= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=lUns9qrR; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf06.hostedemail.com: domain of yajun.deng@linux.dev designates 91.218.175.54 as permitted sender) smtp.mailfrom=yajun.deng@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686882627; a=rsa-sha256; cv=none; b=Aq5MhdBMHPPC44Qp6UCHUr5G4l57IFM07ACR8zn+I6wZcWbeqTtwZ0HUyIsxxx1krGAPIp lBCjL5e3hnXaazMmPytAaBGoItxqDGmM4OTC8glSsmiy3nHWN+cgVKODh7Eh6DnEVvYEfA wUiY6gR1jMCi9OSBLamor4l6MzUOjRg= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1686882624; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=4AulDYoE3pAHZf4DySsjoslFcIuvn9gDgjSjn9hQRpg=; b=lUns9qrRG5dfZ9WL7/8dbCUKFyvh2GDPdEBJOsT0sfmn4HOIghJVJCuiumKzOSWrCNwWdn cHpKfsBtLbxyMUfqlN8qwaOJPGLM5f6guXxNSlTT4sZzhH6nbRuM61xGUJYDIiaSXHsGEW 2ZD3fcz5S6RgsfHKRlGpYiG99Cru8/0= From: Yajun Deng To: akpm@linux-foundation.org, rppt@kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yajun Deng , kernel test robot Subject: [PATCH v2] mm: pass nid to reserve_bootmem_region() Date: Fri, 16 Jun 2023 10:30:11 +0800 Message-Id: <20230616023011.2952211-1-yajun.deng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 85D51180005 X-Stat-Signature: e3uqa6fop1pgq7ef9n4ecxupa4y16t57 X-HE-Tag: 1686882626-268600 X-HE-Meta: U2FsdGVkX19won2VeApEvFGEbdqT9yCdZhLBDsxa+I1BVUREedz1/A28CpOqZeRUiZKevRiuR+W7PlBVzwmj4HezXPLYSuZTeJHOnPkEJfKGlDpsDozQ6gFCgbTCk+g+6rTXOUiBDBsEFisEG+vcMimzmKdAnX5Gysnpapm2wzvUT5YnYDrfJguAFqKTGzxLfTsLH1uiUfvE/WN12wqnRUrXpiMt1+g3kH8nohU43UU9GQXvilkSa0UCwC/AXLkBUWkeCYKGIfLdGJuya+2wKmKwEp94rxRLPFlqNx6LCxWy+nYe+nq3/pXodLHcKuFrWGdYsORahaP+H2tDFkbZQq+3JYuo25fP17DIxoh8E3WGRUEfXfF3R6G0Jn4Z/eZvS9AOv/K8DOWWp34THXTCOJz6UVRYFSW+DLxhEc+VTogLfzNtEdWVP8iPYjWXyBMJ9ovV41rSMtjjnli0LQMrOIysH19xq5Vpf434ovc0v2nxUP9+HFruVvJc7wSSK2nChhouDtJ8Sh1StBvSt960N00NJvNm1PCVxV/DOXhfAqmomFiNq/nDzyMCdvw1Ycmz9TofPK7psgCbEaGnFJ6OF03VHunT1h0IMfGtWa6MqANkb5x8bLpv+oFHCspBX6kW3vb99t131NtPvbzxvQx1VOCdkYNK4Noqe0VUxaEyd2V6d9wRps+4Zd8WousGgmbJiHNHCyng0mk8nBYCdJ6YftlFEVuRZwF//NRQNudBSkb0JE1fkArWHrfOlkCFsWim3s5f1NqynKXaqMaVp7maBnEy+ankECBhJyb8BlSjDjHQ7Q676Q8lCgDy5XzGdQc+CnTmfZDGWBlYTNIMnSY134p0QVAQTUEIlN4gWqXSgO2E/2S6NHPHRf8W9dpeq12dbl0yBXFRo9LUJu+G43hSxTa+4/Cvy1Ks6fl6jczYzDVZxglbYX40M2rTRcxSsQmVwynnFRszYr3Xpv+gErQ +djZOLwu k2fI164FIRILhBB8x6semgeQVWwA5vygLbkgJCR/H9d5OyH+lIdYQwrXR/jFAmzjcqzR2axjLtVYAQY05m/tIqDNbaJE9L74OPsoKrZeG+Uamfz66wJl8g74yin+/LSvokXHxwtxwXpg4LqYJdAtuU711i6PMGIBCfJJRw5vZieqkSp5DtlzgAxy/Qn0xyzO/mFBwolc9Rizo6D+FZxUBAwDQug== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: early_pfn_to_nid() is called frequently in init_reserved_page(), it returns the node id of the PFN. These PFN are probably from the same memory region, they have the same node id. It's not necessary to call early_pfn_to_nid() for each PFN. Pass nid to eserve_bootmem_region() and drop the call to early_pfn_to_nid() in init_reserved_page(). The most beneficial function is memmap_init_reserved_pages() if define CONFIG_DEFERRED_STRUCT_PAGE_INIT. The following data was tested on x86 machine, it has 190GB RAM, before: memmap_init_reserved_pages() 67ms after: memmap_init_reserved_pages() 20ms Signed-off-by: Yajun Deng Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202306160145.juJMr3Bi-lkp@intel.com --- include/linux/mm.h | 3 ++- mm/memblock.c | 9 ++++++--- mm/mm_init.c | 31 +++++++++++++++++++------------ 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 17317b1673b0..39e72ca6bf22 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2964,7 +2964,8 @@ extern unsigned long free_reserved_area(void *start, void *end, extern void adjust_managed_page_count(struct page *page, long count); -extern void reserve_bootmem_region(phys_addr_t start, phys_addr_t end); +extern void reserve_bootmem_region(phys_addr_t start, + phys_addr_t end, int nid); /* Free the reserved page into the buddy system, so it gets managed. */ static inline void free_reserved_page(struct page *page) diff --git a/mm/memblock.c b/mm/memblock.c index ff0da1858778..6dc51dc845e5 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2091,18 +2091,21 @@ static void __init memmap_init_reserved_pages(void) { struct memblock_region *region; phys_addr_t start, end; + int nid; u64 i; /* initialize struct pages for the reserved regions */ - for_each_reserved_mem_range(i, &start, &end) - reserve_bootmem_region(start, end); + __for_each_mem_range(i, &memblock.reserved, NULL, NUMA_NO_NODE, + MEMBLOCK_NONE, &start, &end, &nid) + reserve_bootmem_region(start, end, nid); /* and also treat struct pages for the NOMAP regions as PageReserved */ for_each_mem_region(region) { if (memblock_is_nomap(region)) { start = region->base; end = start + region->size; - reserve_bootmem_region(start, end); + nid = memblock_get_region_node(region); + reserve_bootmem_region(start, end, nid); } } } diff --git a/mm/mm_init.c b/mm/mm_init.c index d393631599a7..1499efbebc6f 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -646,10 +646,8 @@ static inline void pgdat_set_deferred_range(pg_data_t *pgdat) } /* Returns true if the struct page for the pfn is initialised */ -static inline bool __meminit early_page_initialised(unsigned long pfn) +static inline bool __meminit early_page_initialised(unsigned long pfn, int nid) { - int nid = early_pfn_to_nid(pfn); - if (node_online(nid) && pfn >= NODE_DATA(nid)->first_deferred_pfn) return false; @@ -695,15 +693,14 @@ defer_init(int nid, unsigned long pfn, unsigned long end_pfn) return false; } -static void __meminit init_reserved_page(unsigned long pfn) +static void __meminit init_reserved_page(unsigned long pfn, int nid) { pg_data_t *pgdat; - int nid, zid; + int zid; - if (early_page_initialised(pfn)) + if (early_page_initialised(pfn, nid)) return; - nid = early_pfn_to_nid(pfn); pgdat = NODE_DATA(nid); for (zid = 0; zid < MAX_NR_ZONES; zid++) { @@ -717,7 +714,7 @@ static void __meminit init_reserved_page(unsigned long pfn) #else static inline void pgdat_set_deferred_range(pg_data_t *pgdat) {} -static inline bool early_page_initialised(unsigned long pfn) +static inline bool early_page_initialised(unsigned long pfn, int nid) { return true; } @@ -727,7 +724,7 @@ static inline bool defer_init(int nid, unsigned long pfn, unsigned long end_pfn) return false; } -static inline void init_reserved_page(unsigned long pfn) +static inline void init_reserved_page(unsigned long pfn, int nid) { } #endif /* CONFIG_DEFERRED_STRUCT_PAGE_INIT */ @@ -738,16 +735,20 @@ static inline void init_reserved_page(unsigned long pfn) * marks the pages PageReserved. The remaining valid pages are later * sent to the buddy page allocator. */ -void __meminit reserve_bootmem_region(phys_addr_t start, phys_addr_t end) +void __meminit reserve_bootmem_region(phys_addr_t start, + phys_addr_t end, int nid) { unsigned long start_pfn = PFN_DOWN(start); unsigned long end_pfn = PFN_UP(end); + if (nid == MAX_NUMNODES) + nid = first_online_node; + for (; start_pfn < end_pfn; start_pfn++) { if (pfn_valid(start_pfn)) { struct page *page = pfn_to_page(start_pfn); - init_reserved_page(start_pfn); + init_reserved_page(start_pfn, nid); /* Avoid false-positive PageTail() */ INIT_LIST_HEAD(&page->lru); @@ -2579,7 +2580,13 @@ void __init set_dma_reserve(unsigned long new_dma_reserve) void __init memblock_free_pages(struct page *page, unsigned long pfn, unsigned int order) { - if (!early_page_initialised(pfn)) + int nid = 0; + +#ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT + nid = early_pfn_to_nid(pfn); +#endif + + if (!early_page_initialised(pfn, nid)) return; if (!kmsan_memblock_free_pages(page, order)) { /* KMSAN will take care of these pages. */