From patchwork Wed Jun 5 07:13:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13686251 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 E1295C25B76 for ; Wed, 5 Jun 2024 07:13:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 66CE56B009B; Wed, 5 Jun 2024 03:13:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 61E7A6B009C; Wed, 5 Jun 2024 03:13:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 449E16B009D; Wed, 5 Jun 2024 03:13:56 -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 1172F6B009B for ; Wed, 5 Jun 2024 03:13:56 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D103D810A7 for ; Wed, 5 Jun 2024 07:13:55 +0000 (UTC) X-FDA: 82195970430.20.1E05A15 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) by imf23.hostedemail.com (Postfix) with ESMTP id 0D01214000E for ; Wed, 5 Jun 2024 07:13:53 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PqrDB+cw; spf=pass (imf23.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.43 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717571634; 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=/ZhubvrjOrd+neq1ixpki3J5siuGrNaURm4tNFASJmU=; b=5LyBRGUHh3iT+Imtu4nn7/4oeeUaGmxF7AmZnS8zVcAZfjsA6f8L1ETY/zNXt44fsnbfel chJqdgZDMgIVwccFdgsUOdQq/W6snD57ZczUXrGktuiTKft3flQ49mWuipGlC5m+sb7ktB XO46Oxic4oV00hcFI/QmtNaF0WfzHSY= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PqrDB+cw; spf=pass (imf23.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.43 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717571634; a=rsa-sha256; cv=none; b=CWlpfIT/yBdO7RU3c2wep1ZC/ppCGVHCGu0ReR1KuKRwKlDSqeM0WMzLKbGFjC01rr0jrz 4Cq07EO0Em4lOXMc7QsROfzVyQgpxsxLs+8yFKy8ef+TS7kFbzY2yjdpkFhLxFn+07RRmg LBfcATww4mCraig4kkUZi+ypGiXku/c= Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-57a85cc2d96so1733358a12.2 for ; Wed, 05 Jun 2024 00:13:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717571632; x=1718176432; 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=/ZhubvrjOrd+neq1ixpki3J5siuGrNaURm4tNFASJmU=; b=PqrDB+cwhkOA1Z/CmYn12Dgu3c12CnNrksq/hHZjdo0ZTIuIwBCFDRxxq2oUkw06nY gm5/yT+mzO6AY30j/xd151OdMnWJqJhDm8sk/d/53w8l/gPbGsOHqwPQM2toKC/PdFSD TteIRqHXbxotl0oYQdu73HPgu0dWKHlUdvwJGumXD+Xu8l5ePZr1lpGAzawVaHaOuW6u /r9lE0OQkRvWDoITkC49x7BubuPXEpI1I/HUk8hAdTPksfezGqeAEDU5YX/1gOYjThO0 RB5m7wksY2ynrlGkinNCSmMvdXW5Ex7ie+KmJvh0bPwNw1BCY1U4SJ47CDtr4JxQbqc6 0f4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717571632; x=1718176432; 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=/ZhubvrjOrd+neq1ixpki3J5siuGrNaURm4tNFASJmU=; b=tB9Yq3LCyPIGkeUuf+tFAyQQBS8qmPhcfkp0J4Ivl+xJD0JRNRRguymLrUKekkd2Nw 6dsfMTzj+2A6djwRS0r2Z+W1uc88fP2qaJ9KHcOabq3DH4ty7kikY1V7t78dL7sHDn8b sQ296nTGDEHy/D/9GfE19LjAVFkgmsVJzHc8Xawtwo5kdNwsqMU9yM3xkaZfUnje8z/V 7lOTcsyjx+TXGT4uPEuf6mcXtJqBj2Wz1WdgHttV+9Kww3FTMLJdHsM9MDyogEwJGlGI cgrtKCEt0EUlBFdsq8ul8JpEmymRmN2fPQAPhhqS4nTgqiO9OOqwzOg9QLRb+8JAA5HJ hbLw== X-Gm-Message-State: AOJu0YwQZGilLkrb8nAXD2py8WdETm+MFhh7xYeMlS2fSgLqJ8TChAUs yz3W38ak/2sDVFvCHAVrmsXiQHZIgwPxHNoZNizQNYziEWRObL34av+WTw== X-Google-Smtp-Source: AGHT+IEuHDdxlkpY6TA0RZ/jt4/4oTi8idliiMfC1ShpZiTBs6KdvccaXIy0LsbLIV1zNG9Lgux7gg== X-Received: by 2002:a17:906:4694:b0:a5a:2d30:b8c1 with SMTP id a640c23a62f3a-a699f680d76mr98649766b.14.1717571632032; Wed, 05 Jun 2024 00:13:52 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a687cc4e903sm683702466b.216.2024.06.05.00.13.51 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jun 2024 00:13:51 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Wei Yang Subject: [PATCH v2 3/3] mm/mm_init.c: not always search next deferred_init_pfn from very beginning Date: Wed, 5 Jun 2024 07:13:39 +0000 Message-Id: <20240605071339.15330-3-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20240605071339.15330-1-richard.weiyang@gmail.com> References: <20240605071339.15330-1-richard.weiyang@gmail.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 0D01214000E X-Stat-Signature: cqufzmo5ctcghpxdx7ff8ma9x117yppm X-Rspam-User: X-HE-Tag: 1717571633-56527 X-HE-Meta: U2FsdGVkX1+6H9g3TqHw4o9tGRrZHlDBpvXnU7kAtVmT2u+8GAB17D+lGHENlOAGec0jaJUHbkQalqIG7JAOzyh1jGUQ3U5A6NcJ+dWMXpgoM1V/dYGK9JY0JcxK0rqGoMlmhWhnwW4/Ol5qIdZFOOGm8lunMTukt+tdXe+yD3bBwjmb7XmFYOn4qMIlIpR+JeAhT5dvpowXWfwMFxCwMRyVru+CVxA7z65TAl9efZjlH4FrzTCbx8ZdvicYzn5YhGVw2TbVWSZpQHFTj6hqpBi5j/a/ZlXoEvxkmtDTUV5oe4KRsN83+6wLWW+Ev/B7XY9bFp94rlzVVcVakxv3JYvhRGd3yB3SReWQA+NMqPQU5GLDu+MxzUaGD7q8G7OtESnGpWc6va6IovWZZM9orqF9Hrr+GXzVmurS0bDbmYHi3zZngSyk56Gn7m6iuT0QMkxMbNfGYyQDzZjb894GyKchdnIpi2U9dOLSjBf+q3PTR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ity=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. [rppt refine the comment] Signed-off-by: Wei Yang --- v2: update comment instead of rename function name --- include/linux/memblock.h | 19 ------------------- mm/mm_init.c | 23 ++++++++++++++--------- 2 files changed, 14 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..c152c60eca3d 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -2017,24 +2017,29 @@ static unsigned long __init deferred_init_pages(struct zone *zone, } /* - * This function is meant to pre-load the iterator for the zone init. - * Specifically it walks through the ranges until we are caught up to the - * first_init_pfn value and exits there. If we never encounter the value we - * return false indicating there are no valid ranges left. + * This function is meant to pre-load the iterator for the zone init from + * a given point. + * Specifically it walks through the ranges starting with initial index + * passed to it until we are caught up to the first_init_pfn value and + * exits there. If we never encounter the value we return false indicating + * there are no valid ranges left. */ static bool __init deferred_init_mem_pfn_range_in_zone(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,7 +2111,7 @@ 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); @@ -2137,7 +2142,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)) @@ -2212,7 +2217,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))