linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers/base/memory: Skip handled sections in memory_dev_init()
@ 2025-05-08  0:08 Gavin Shan
  0 siblings, 0 replies; only message in thread
From: Gavin Shan @ 2025-05-08  0:08 UTC (permalink / raw)
  To: linux-mm; +Cc: linux-kernel, david, osalvador, gregkh, rafael, dakr

It's unnecessary to iterate those sections and check their presence
states if their block has been handled. In this specific case, the
cursor of for_each_present_section_nr() can leap to the starting
section of next block to bypass those covered sections, resulting
in small performance gain. For example, the time consumed by the
function drops by 12us on a X86 system with 100GB memory as Oscar
tested.

Suggested-by: Oscar Salvador <osalvador@suse.de>
Signed-off-by: Gavin Shan <gshan@redhat.com>
---
 drivers/base/memory.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 19469e7f88c2..f612e43afe39 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -942,7 +942,7 @@ static const struct attribute_group *memory_root_attr_groups[] = {
 void __init memory_dev_init(void)
 {
 	int ret;
-	unsigned long block_sz, block_id, nr;
+	unsigned long block_sz, nr;
 
 	/* Validate the configured memory block size */
 	block_sz = memory_block_size_bytes();
@@ -956,22 +956,22 @@ void __init memory_dev_init(void)
 
 	/*
 	 * Create entries for memory sections that were found during boot
-	 * and have been initialized. Use @block_id to track the last
-	 * handled block and initialize it to an invalid value (ULONG_MAX)
-	 * to bypass the block ID matching check for the first present
-	 * block so that it can be covered.
+	 * and have been initialized.
 	 */
-	block_id = ULONG_MAX;
 	for_each_present_section_nr(0, nr) {
-		if (block_id != ULONG_MAX && memory_block_id(nr) == block_id)
-			continue;
-
-		block_id = memory_block_id(nr);
-		ret = add_memory_block(block_id, MEM_ONLINE, NULL, NULL);
+		ret = add_memory_block(memory_block_id(nr), MEM_ONLINE,
+				       NULL, NULL);
 		if (ret) {
 			panic("%s() failed to add memory block: %d\n",
 			      __func__, ret);
 		}
+
+		/*
+		 * Forward to the last section in this block so that we will
+		 * process the first section of the next block in the next
+		 * iteration.
+		 */
+		nr = ALIGN(nr + 1, sections_per_block) - 1;
 	}
 }
 
-- 
2.49.0



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2025-05-08  0:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-08  0:08 [PATCH] drivers/base/memory: Skip handled sections in memory_dev_init() Gavin Shan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).