public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: David Hildenbrand <david@redhat.com>
Cc: Michal Hocko <mhocko@kernel.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	linux-kernel@vger.kernel.org,
	Scott Cheloha <cheloha@linux.vnet.ibm.com>,
	nathanl@linux.ibm.com, ricklind@linux.vnet.ibm.com,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH v3] drivers/base/memory.c: cache blocks in radix tree to accelerate lookup
Date: Thu, 9 Jan 2020 10:41:53 +0100	[thread overview]
Message-ID: <20200109094153.GA45666@kroah.com> (raw)
In-Reply-To: <4a0e4024-b4a1-f6aa-ae2b-7951a72b90aa@redhat.com>

On Thu, Jan 09, 2020 at 10:31:21AM +0100, David Hildenbrand wrote:
> On 09.01.20 10:19, Michal Hocko wrote:
> > On Thu 09-01-20 09:56:23, Greg KH wrote:
> >> On Thu, Jan 09, 2020 at 09:49:55AM +0100, Michal Hocko wrote:
> >>> On Tue 07-01-20 22:48:04, Michal Hocko wrote:
> >>>> [Cc Andrew]
> >>>>
> >>>> On Tue 17-12-19 13:32:38, Scott Cheloha wrote:
> >>>>> Searching for a particular memory block by id is slow because each block
> >>>>> device is kept in an unsorted linked list on the subsystem bus.
> >>>>
> >>>> Noting that this is O(N^2) would be useful.
> >>>>
> >>>>> Lookup is much faster if we cache the blocks in a radix tree.
> >>>>
> >>>> While this is really easy and straightforward, is there any reason why
> >>>> subsys_find_device_by_id has to use such a slow lookup? I suspect nobody
> >>>> simply needed a more optimized data structure for that purpose yet.
> >>>> Would it be too hard to use radix tree for all lookups rather than
> >>>> adding a shadow copy for memblocks?
> >>>
> >>> Greg, Rafael, this seems to be your domain. Do you have any opinion on
> >>> this?
> >>
> >> No one has cared about the speed of that call as it has never been on
> >> any "fast path" that I know of.  And it should just be O(N), isn't it
> >> just walking the list of devices in order?
> > 
> > Which means that if you have to call it N times then it is O(N^2) and
> > that is the case here because you are adding N memblocks. See
> > memory_dev_init
> >   for each memblock
> >     add_memory_block
> >       init_memory_block
> >         find_memory_block_by_id # checks all existing devices
> >         register_memory
> > 	  device_register # add new device
> >   
> > In this particular case find_memory_block_by_id is called mostly to make
> > sure we are no re-registering something multiple times which shouldn't
> > happen so it sucks to spend a lot of time on that. We might think of
> > removing that for boot time but who knows what kind of surprises we
> > might see from crazy HW setups.
> 
> Oh, and please note (as discussed in v1 or v2 of this patch as well)
> that the lookup is also performed in walk_memory_blocks() for each
> memory block in the range, e.g., via link_mem_sections() on system boot.
> There we have O(N^2) as well.

Ok, again self-inflicted, I suggest you all roll your own logic for this
highly accessed set of things :)

thanks,

greg k-h

  reply	other threads:[~2020-01-09  9:41 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-20 19:25 [PATCH] memory subsystem: cache memory blocks in radix tree to accelerate lookup Scott Cheloha
2019-11-21  9:34 ` David Hildenbrand
2019-11-21  9:35 ` David Hildenbrand
2019-11-21 19:59 ` [PATCH v2] drivers/base/memory.c: cache " Scott Cheloha
2019-11-25  6:36   ` kbuild test robot
2019-12-17 19:32   ` [PATCH v3] " Scott Cheloha
2019-12-18  9:00     ` David Hildenbrand
2019-12-19 17:33       ` Scott Cheloha
2019-12-20 10:50         ` David Hildenbrand
2019-12-19 18:09     ` Nathan Lynch
2020-01-07 21:48     ` Michal Hocko
2020-01-08 13:36       ` David Hildenbrand
2020-01-08 14:21         ` Michal Hocko
2020-01-08 15:23           ` David Hildenbrand
2020-01-09  8:49       ` Michal Hocko
2020-01-09  8:56         ` Greg Kroah-Hartman
2020-01-09  9:19           ` Michal Hocko
2020-01-09  9:24             ` David Hildenbrand
2020-01-09  9:31             ` David Hildenbrand
2020-01-09  9:41               ` Greg Kroah-Hartman [this message]
2020-01-09  9:33             ` Greg Kroah-Hartman
2020-01-09  9:50               ` Michal Hocko
2020-01-09  9:48     ` Michal Hocko

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=20200109094153.GA45666@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=cheloha@linux.vnet.ibm.com \
    --cc=david@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhocko@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