From patchwork Fri May 31 00:26:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13680971 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 B7A47C25B74 for ; Fri, 31 May 2024 00:26:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 142D36B0099; Thu, 30 May 2024 20:26:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0CDF76B009A; Thu, 30 May 2024 20:26:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E39786B009B; Thu, 30 May 2024 20:26:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BE0466B0099 for ; Thu, 30 May 2024 20:26:38 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 701501C1E43 for ; Fri, 31 May 2024 00:26:38 +0000 (UTC) X-FDA: 82176800076.13.AF17244 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by imf17.hostedemail.com (Postfix) with ESMTP id ABA324000E for ; Fri, 31 May 2024 00:26:36 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BZ+7uJsh; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.52 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717115196; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=MZBE41AChCp0m8HAgfoBpLE+uoE/yknDqU4N2DO/2Os=; b=w+U6X/+YS0UUttOJYrjLqThelunSVgH3YM3oxDX5o3QoCT0UUPro8b76XY5yiGaEsZhzdj ohGcUUGJDBfzF4be9jdI5ByK6BCbIXj+h2KdPbbvLKb7yfEuRRCTJJBLHHkW7sJ6hebiNj fYz/SbvNrzBM1IJuhMgfoqWow/Rfxas= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BZ+7uJsh; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.52 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717115196; a=rsa-sha256; cv=none; b=wsPsIhSMtifWZs191sNlx7lV9fEa/5WXp/e8TaD7TcQIbmobTnk5GED9VR/f+73oD3yxuh kbgvhCl8NJ7C6Xh6RakkpCsWpHD/qfPqO9bB3lk5WKcum7W2pIxd9OBJELlZggx+Q8+MuA BhK8KGdMWk1KmfrHw3gGU18A0ihtFVo= Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a62db0c8c9cso146671066b.2 for ; Thu, 30 May 2024 17:26:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717115195; x=1717719995; darn=kvack.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=MZBE41AChCp0m8HAgfoBpLE+uoE/yknDqU4N2DO/2Os=; b=BZ+7uJshi5rRZ/jAARKOZaB/w4aWxEIETxxwCdkq7B1MVcAFKSMjXYv7ceUlFZ7PKF F8CSbNmLGTUbu6hRBQgwXvXtrogsBWlV1UorWZ53mln0twnZW3mqn3IdJT4k97YcAt1J X+IGEs8VykIty//dS9452GpVBQREm9WanrYwEy6CxFeHYWIHularVvDFjKI57aOlD7E0 952PvscZO6LWIeILgDQ2KxPOCibs0Uzrz/5Z4wqhpk8vEbplzG6nj17bZTm4erCgPhG2 7vZSA++Z7nX05jecjj5htUcNgTX/TDkdlwaKuJSk4/CRVbjvk7c88TYzep2o/q5pPYRw bmow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717115195; x=1717719995; h=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=MZBE41AChCp0m8HAgfoBpLE+uoE/yknDqU4N2DO/2Os=; b=GE0SFD3dxd3B/iOZKV2E0scnzeW0lMt4lyeO46LHkdnCRI7u4xbTXf4yRsgV871CK3 hc1Ji7TpjeE91uZ9fnLdmAjAMW9+sXwmbvMqnY7NrTh/ThtPqmzTnHeXFGbZLr+F0g3N 1nBJsct26uO0PrzyZE04aFH8oPdqQoDDB60xCMZSgRtTz+FTPOEhvS6EpgTjkv4Nx1ih QzrO/xPXSURLOSjNP3S9aXnlOGnMTlCcdLzstR3ikUmYr7BsN1G2rrGfvfSuzRzdydu4 O/Sobfju8JvR4O8cJ41ov3MUTHMwD4lECNr+3S3QIXAjuodzGD0Ymx/OI0twtpM72XYy eS8A== X-Gm-Message-State: AOJu0YxlnTErSrS3c/O5PEYldUvvg+IBtMHmK10vhVGhfS8wTA5W2AiW C0zAHxrHEAlTbgUxbCAuOMJsV/Bs08lHc6AlFbIZ29jqM+jkkAZT X-Google-Smtp-Source: AGHT+IGpmSdbdFUNJHYiOkwm2eAOghZCZ6bPZb4wH7CNYr6cx7s8fjnBQMvxxMM5Gr99XIwnAHA/6g== X-Received: by 2002:a17:906:1e12:b0:a62:c238:b229 with SMTP id a640c23a62f3a-a682234b700mr25526366b.74.1717115194940; Thu, 30 May 2024 17:26:34 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a67e6f030f7sm29807666b.10.2024.05.30.17.26.33 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 May 2024 17:26:33 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Wei Yang Subject: [PATCH 3/3] mm/mm_init.c: not always search next deferred_init_pfn from very beginning Date: Fri, 31 May 2024 00:26:13 +0000 Message-Id: <20240531002613.5231-3-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20240531002613.5231-1-richard.weiyang@gmail.com> References: <20240531002613.5231-1-richard.weiyang@gmail.com> X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: ABA324000E X-Stat-Signature: jrxisu1e5sznimkng16ixwniw1uqomdp X-HE-Tag: 1717115196-454382 X-HE-Meta: U2FsdGVkX18HgFO85nSXcUxFdG9aIH5kE1VO5Qmja4kIiRs9mgtg8lxuqrw1BlBYrmYL2Rh72TqYl+cjYy1LDcNARNl1WhQWHPI81JPdPmpV7vFRsOOUXjpTH9YKbY6siPhLN2NI+s3Got1G4TOSHhFsjfirBUwqHIajVnBbWu2chG5ESe18dCyY+Zu4WW+3T9jIEqnj+IlJImv04nhtt2w05/lT2Qyw7kaQma/px8VUSvTDXMz9E30a4OkOIilClhANrIL0Hy9V0OPhwMjx7Plll3KXLp4Z4E3ONb89IoKeHVjA6njsgSLpVfJz/cKsmfc/VUcHf4vNZHwbfcS5qv6VqurdSraaJc/wmMvOy0ZiIuYJ58AP1Yk6XjNt8Fo3/noKWB1R3AUw7FjxNwjoULd7j1cDFpk8q0e3GXWtJOKzlCsabRjyZ5JlmRp6hJiEBLjt3wq4/C5PnZOaIBF0XuOI6rF812Kj4FTxlLLvdtzSLsf49A8ARbD8NcvXuARvBdR9GE7stnykuNCIUf0ZBV3E1XhPwgWNLktb7mgTK2RMwNPLsmCm5B6Q8Ae72eKd6+6hSnzQo3OAd+Vwe+JFLYY0ko0oJQYmRHGuaYMDaTnLLgI7YV4R+Z6F2LfvrAYJYoec3923IxFgEIWHpVx8crNxmxWAy2L0aQAPRYXSBrRY0wokfrmJLfVJEn8AQPUxlvn547EJKEq22OdcTCBdpelx8aRGDJsIPbF58UiGp8VVUgy069Ljd+jJiPxMxBgyuQCEP5m9RuFozB8HYqnpAFJAiNfF+MdNlvg/bGVfYQFosiv6YXna+TcNFsbdArbgxqhFXeVwQZiU9V0gswflDBtw9B/PGWdiotNAp0Y32rZG+uGpOcyZejcEmm+GHn8txHL+ZhAohTwSbk1AnnhDNhjmn6Kb8mnQSA2tIkq7dAEEQcEVb0ojOuVQgTtUlJNsWofLB2uDB9iETKtRr5+ TWT4QSm6 vL3Da7ANed1B81k2WYv+8RvxWlzzZi9fGKOLR5+aOXhZzRRPF5j9PskRRd1MLL916gRTQYpYZumjWXaYZebtXdcoZiYJEt8btwnL50kMruEkVK5glLl9Wc6tKAui+oZ8PYvbr/RqKCdllj+zFFwDSZXH+7gGhLV0eNPpM7VIqQISDHQp/FFrGIjOJDUFImdpb3ICvlSZWi7PyyWPzgry7QFzby/bioSWldqk3sGI8P0o56g1OKQIJB6fSAlSF6qnSIaeb9PqKFNrdIgHEfiIoT24fumL8v1DCDx3iZ8dXkVLe/0gs5enMQVraFaDCPe8TeD9ZsoJnohcMMcVyZSxkdgDU5EEignNmsD802s7tb34HcdR49vT6BmngQXBuah/SdGoAH34PpZl5CK7qPjSwo2IO5KfT2CsvkLDSKAzQEw+GNttL2IHA0JZkd5eb33Or2pH/uDAACkeSHYrdTGDwX85RQqgRXmjYyu5xyU0luwdntR9Sgnpbg+pvctfgVbN5iZk0s2KG8TCp56567foIf3GgPnnB74LfPyfgjHR4Fo2nS0E= 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: List-Subscribe: List-Unsubscribe: In function deferred_init_memmap(), we call deferred_init_mem_pfn_range_in_zone() to get the next deferred_init_pfn. But we always search it from the very beginning. Since we save the index in i, we can leverage this to search from i next time. Signed-off-by: Wei Yang --- include/linux/memblock.h | 19 ------------------- mm/mm_init.c | 21 ++++++++++++--------- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 6cf18dc2b4d0..45cac33334c8 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -299,25 +299,6 @@ void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn, void __next_mem_pfn_range_in_zone(u64 *idx, struct zone *zone, unsigned long *out_spfn, unsigned long *out_epfn); -/** - * for_each_free_mem_pfn_range_in_zone - iterate through zone specific free - * memblock areas - * @i: u64 used as loop variable - * @zone: zone in which all of the memory blocks reside - * @p_start: ptr to phys_addr_t for start address of the range, can be %NULL - * @p_end: ptr to phys_addr_t for end address of the range, can be %NULL - * - * Walks over free (memory && !reserved) areas of memblock in a specific - * zone. Available once memblock and an empty zone is initialized. The main - * assumption is that the zone start, end, and pgdat have been associated. - * This way we can use the zone to determine NUMA node, and if a given part - * of the memblock is valid for the zone. - */ -#define for_each_free_mem_pfn_range_in_zone(i, zone, p_start, p_end) \ - for (i = 0, \ - __next_mem_pfn_range_in_zone(&i, zone, p_start, p_end); \ - i != U64_MAX; \ - __next_mem_pfn_range_in_zone(&i, zone, p_start, p_end)) /** * for_each_free_mem_pfn_range_in_zone_from - iterate through zone specific diff --git a/mm/mm_init.c b/mm/mm_init.c index d05a4c38310f..ec17bf93f946 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -2023,18 +2023,21 @@ static unsigned long __init deferred_init_pages(struct zone *zone, * return false indicating there are no valid ranges left. */ static bool __init -deferred_init_mem_pfn_range_in_zone(u64 *i, struct zone *zone, +deferred_init_mem_pfn_range_in_zone_from(u64 *i, struct zone *zone, unsigned long *spfn, unsigned long *epfn, unsigned long first_init_pfn) { - u64 j; + u64 j = *i; + + if (j == 0) + __next_mem_pfn_range_in_zone(&j, zone, spfn, epfn); /* * Start out by walking through the ranges in this zone that have * already been initialized. We don't need to do anything with them * so we just need to flush them out of the system. */ - for_each_free_mem_pfn_range_in_zone(j, zone, spfn, epfn) { + for_each_free_mem_pfn_range_in_zone_from(j, zone, spfn, epfn) { if (*epfn <= first_init_pfn) continue; if (*spfn < first_init_pfn) @@ -2106,9 +2109,9 @@ deferred_init_memmap_chunk(unsigned long start_pfn, unsigned long end_pfn, { unsigned long spfn, epfn; struct zone *zone = arg; - u64 i; + u64 i = 0; - deferred_init_mem_pfn_range_in_zone(&i, zone, &spfn, &epfn, start_pfn); + deferred_init_mem_pfn_range_in_zone_from(&i, zone, &spfn, &epfn, start_pfn); /* * Initialize and free pages in MAX_PAGE_ORDER sized increments so that @@ -2137,7 +2140,7 @@ static int __init deferred_init_memmap(void *data) unsigned long start = jiffies; struct zone *zone; int max_threads; - u64 i; + u64 i = 0; /* Bind memory initialisation thread to a local node if possible */ if (!cpumask_empty(cpumask)) @@ -2168,7 +2171,7 @@ static int __init deferred_init_memmap(void *data) max_threads = deferred_page_init_max_threads(cpumask); - while (deferred_init_mem_pfn_range_in_zone(&i, zone, &spfn, &epfn, first_init_pfn)) { + while (deferred_init_mem_pfn_range_in_zone_from(&i, zone, &spfn, &epfn, first_init_pfn)) { first_init_pfn = ALIGN(epfn, PAGES_PER_SECTION); struct padata_mt_job job = { .thread_fn = deferred_init_memmap_chunk, @@ -2212,7 +2215,7 @@ bool __init deferred_grow_zone(struct zone *zone, unsigned int order) unsigned long first_deferred_pfn = pgdat->first_deferred_pfn; unsigned long spfn, epfn, flags; unsigned long nr_pages = 0; - u64 i; + u64 i = 0; /* Only the last zone may have deferred pages */ if (zone_end_pfn(zone) != pgdat_end_pfn(pgdat)) @@ -2230,7 +2233,7 @@ bool __init deferred_grow_zone(struct zone *zone, unsigned int order) } /* If the zone is empty somebody else may have cleared out the zone */ - if (!deferred_init_mem_pfn_range_in_zone(&i, zone, &spfn, &epfn, + if (!deferred_init_mem_pfn_range_in_zone_from(&i, zone, &spfn, &epfn, first_deferred_pfn)) { pgdat->first_deferred_pfn = ULONG_MAX; pgdat_resize_unlock(pgdat, &flags);