linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Scott Cheloha <cheloha@linux.vnet.ibm.com>,
	linux-kernel@vger.kernel.org,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: nathanl@linux.ibm.com, ricklind@linux.vnet.ibm.com
Subject: Re: [PATCH] drivers/base/memory.c: memory subsys init: skip search for missing blocks
Date: Fri, 1 Nov 2019 20:20:40 +0100	[thread overview]
Message-ID: <8e769009-b69c-8a2f-a7b3-46e1ce0fe8be@redhat.com> (raw)
In-Reply-To: <c702b775-4a38-bc97-c67f-83f986bbe5fa@redhat.com>

On 01.11.19 20:00, David Hildenbrand wrote:
> On 01.11.19 19:10, Scott Cheloha wrote:
>> 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;
>> +		}
> 
> No, I don't really like that. Can we please speed up the lookup via a
> radix tree as noted in the comment of "find_memory_block()".
> 
> /*
>    * For now, we have a linear search to go find the appropriate
>    * memory_block corresponding to a particular phys_index. If
>    * this gets to be a real problem, we can always use a radix
>    * tree or something here.
>    *
>    * This could be made generic for all device subsystems.
>    */
> 
> This will speed up all users of walk_memory_blocks() similarly.
> Especially, it will also speed up link_mem_sections() used during boot,
> which relies on walk_memory_blocks().
> 

Also, I think this check that I added back than should not happen in the 
wild. If we care, we could turn that into a 
VM_BUG_ON(find_memory_block_by_id(block_id)).

-- 

Thanks,

David / dhildenb


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

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-01 18:10 [PATCH] drivers/base/memory.c: memory subsys init: skip search for missing blocks Scott Cheloha
2019-11-01 19:00 ` David Hildenbrand
2019-11-01 19:20   ` David Hildenbrand [this message]
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=8e769009-b69c-8a2f-a7b3-46e1ce0fe8be@redhat.com \
    --to=david@redhat.com \
    --cc=cheloha@linux.vnet.ibm.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;
as well as URLs for NNTP newsgroup(s).