lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20250508000801.178672-1-gshan@redhat.com>
Date: Thu,  8 May 2025 10:08:01 +1000
From: Gavin Shan <gshan@...hat.com>
To: linux-mm@...ck.org
Cc: linux-kernel@...r.kernel.org,
	david@...hat.com,
	osalvador@...e.de,
	gregkh@...uxfoundation.org,
	rafael@...nel.org,
	dakr@...nel.org
Subject: [PATCH] drivers/base/memory: Skip handled sections in memory_dev_init()

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@...e.de>
Signed-off-by: Gavin Shan <gshan@...hat.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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ