linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Qiang Liu <liuq131@chinatelecom.cn>
To: rppt@kernel.org, akpm@linux-foundation.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Qiang Liu <liuq131@chinatelecom.cn>
Subject: [PATCH] mm/mm_init.c: add zidcache to the init_reserved_page function
Date: Wed,  4 Sep 2024 19:55:41 +0800	[thread overview]
Message-ID: <20240904115541.6519-1-liuq131@chinatelecom.cn> (raw)

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 <liuq131@chinatelecom.cn>
---
 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) {}
-- 
2.27.0



             reply	other threads:[~2024-09-04 11:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-04 11:55 Qiang Liu [this message]
2024-09-04 20:41 ` Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240904115541.6519-1-liuq131@chinatelecom.cn \
    --to=liuq131@chinatelecom.cn \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rppt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox