mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Scott Cheloha <cheloha@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	David Hildenbrand <david@redhat.com>
Cc: nathanl@linux.ibm.com, ricklind@linux.vnet.ibm.com,
	Scott Cheloha <cheloha@linux.vnet.ibm.com>
Subject: [PATCH] drivers/base/memory.c: memory subsys init: skip search for missing blocks
Date: Fri,  1 Nov 2019 13:10:54 -0500	[thread overview]
Message-ID: <20191101181054.11521-1-cheloha@linux.vnet.ibm.com> (raw)

Add a flag to init_memory_block() to  enable/disable searching for a
matching block before creating a device for the block and adding it to
the memory subsystem's bus.

When the memory subsystem is being initialized there is no need to check
if a given block has already been added to its bus.  The bus is new, so the
block in question cannot yet have a corresponding device.

The search for a missing block is O(n) so this saves substantial time at
boot if there are many such blocks to add.

Signed-off-by: Scott Cheloha <cheloha@linux.vnet.ibm.com>
---
 drivers/base/memory.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 55907c27075b..1160df4a8feb 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -643,17 +643,21 @@ int register_memory(struct memory_block *memory)
 }
 
 static int init_memory_block(struct memory_block **memory,
-			     unsigned long block_id, unsigned long state)
+			     unsigned long block_id, unsigned long state,
+			     bool may_exist)
 {
 	struct memory_block *mem;
 	unsigned long start_pfn;
 	int ret = 0;
 
-	mem = find_memory_block_by_id(block_id);
-	if (mem) {
-		put_device(&mem->dev);
-		return -EEXIST;
+	if (may_exist) {
+		mem = find_memory_block_by_id(block_id);
+		if (mem) {
+			put_device(&mem->dev);
+			return -EEXIST;
+		}
 	}
+
 	mem = kzalloc(sizeof(*mem), GFP_KERNEL);
 	if (!mem)
 		return -ENOMEM;
@@ -684,7 +688,7 @@ static int add_memory_block(unsigned long base_section_nr)
 	if (section_count == 0)
 		return 0;
 	ret = init_memory_block(&mem, base_memory_block_id(base_section_nr),
-				MEM_ONLINE);
+				MEM_ONLINE, false);
 	if (ret)
 		return ret;
 	mem->section_count = section_count;
@@ -720,7 +724,7 @@ int create_memory_block_devices(unsigned long start, unsigned long size)
 
 	mutex_lock(&mem_sysfs_mutex);
 	for (block_id = start_block_id; block_id != end_block_id; block_id++) {
-		ret = init_memory_block(&mem, block_id, MEM_OFFLINE);
+		ret = init_memory_block(&mem, block_id, MEM_OFFLINE, true);
 		if (ret)
 			break;
 		mem->section_count = sections_per_block;
-- 
2.24.0.rc1


             reply	other threads:[~2019-11-01 18:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-01 18:10 Scott Cheloha [this message]
2019-11-01 19:00 ` David Hildenbrand
2019-11-01 19:20   ` David Hildenbrand
2019-11-01 22:32   ` Rick Lindsley
2019-11-01 22:47     ` David Hildenbrand
2019-11-02 19:43       ` Scott Cheloha
2019-11-02 20:18         ` David Hildenbrand

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=20191101181054.11521-1-cheloha@linux.vnet.ibm.com \
    --to=cheloha@linux.vnet.ibm.com \
    --cc=david@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nathanl@linux.ibm.com \
    --cc=rafael@kernel.org \
    --cc=ricklind@linux.vnet.ibm.com \
    /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

all inboxes | Powered by JetHome®