Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2534678ybl; Thu, 9 Jan 2020 14:36:56 -0800 (PST) X-Google-Smtp-Source: APXvYqxSOrj8qYUX/az3GOf+NUKskKFn8eLyUfeSGXC5FrVfNv2iuI4xBNkNOS24aLCfE0olglXm X-Received: by 2002:aca:3909:: with SMTP id g9mr4905245oia.118.1578609416449; Thu, 09 Jan 2020 14:36:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578609416; cv=none; d=google.com; s=arc-20160816; b=f5f7F8d+g/VScXisqX3B/e5+ARDi2zdDF4+NX8ixK3acqCMtunisPFLuoLBwfhn+/Y FykuZr27XPs9QsGbaie3XogA2gHuyVuoKvxq/kgiVIt+LCH0tyVQMtFFlxPLlvO0BpOd wmNm8Ob6AosHTvMdAUQkq3kMigB+7TdCKozz47GZs6DbxHSB3OrZR+xke42uDeBDwZfA TDx6kIFLHK/2RjF0vSsytaV5GYln6vkHzuvjmeY0dYq0ltMjZwdYbon1AscQL+VaMyWS ZHwRPaRz3B/jw3dX7u8WJPQqXF94xZUfb/B2XM4amn86Zyp0wuL8L5VM87c7gSHCU2+E ltOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:in-reply-to:cc:references:message-id :date:subject:mime-version:from:content-transfer-encoding :dkim-signature; bh=L6Tk6NXbKeintPhmiO4q8CGSHf8p5iQXCoANZ85vxp8=; b=t26ZZv/6Hn4AZDTP7dYafR/b4BfTnqPkahYtNRxBAEGL/romFT76cX2eE+ugk1kk8n /F7S4QBHkrjIj2eklUjs/g8YwUAHxD/Oxg3E3h3EAHmF5rurNR6gE4RqTzxTuksSKhrc SCf3fB2C4IUH4CmQLT8JLhszkdIBWGQL7SiTIgXFBvQRc8YGJXfiVyz2dSMZQ5ehwZqS qaq0WgRCyg7G/odC5U1pPClMGak0yMCkDGuA7jO+NT8kUa0uq3dS78DeW0cQK6EH+pbd XudF2UL5p2PVVErF81TYFGgFGABdJzp3g6tPM81Ef8khr9GQcGRvXXQg53eCKokEZxZL AZ7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TbMwvfM4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u188si4652036oia.80.2020.01.09.14.36.43; Thu, 09 Jan 2020 14:36:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TbMwvfM4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727749AbgAIWfd (ORCPT + 99 others); Thu, 9 Jan 2020 17:35:33 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:34144 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725807AbgAIWfd (ORCPT ); Thu, 9 Jan 2020 17:35:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578609331; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L6Tk6NXbKeintPhmiO4q8CGSHf8p5iQXCoANZ85vxp8=; b=TbMwvfM4oOwKIPUdqNomcwNPHJF5cFzGlSI0X78+qMQWlaW549jtYyblhkMbgEpTwj2c7Y JYR1VuvEFi2EoShkCWoybWRkKcIK8+UtcMwBSrpNxXhrNECZvrB2E2wx+Wyh/iHhnEKXSZ ndnb7DVrmUmvHFLMNv2neP9+H6u/0JY= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-432-3r4EzD79P_mWB-fLxCMtWA-1; Thu, 09 Jan 2020 17:35:30 -0500 X-MC-Unique: 3r4EzD79P_mWB-fLxCMtWA-1 Received: by mail-wr1-f70.google.com with SMTP id c6so6120wrm.18 for ; Thu, 09 Jan 2020 14:35:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:content-transfer-encoding:from:mime-version :subject:date:message-id:references:cc:in-reply-to:to; bh=L6Tk6NXbKeintPhmiO4q8CGSHf8p5iQXCoANZ85vxp8=; b=HBsSESbOMtiEC5Nk3GK8PnJk2vfyVMlXf/cECkEwjd9b30a15D44JFMV1sg47kdKDm pZYq3AN5BppXUHCC/5Vph9Cpxgk1nCEPJ6IsowTsY0YFbzdIdjDtHs4bzZARZIJg6KfM 4vLKA2JvhWCfDzJMFNa38JZmo4XEf3YHRS5WTs/IoR3UNHIWyYDl2hF20nBYnKG8k+uN YlObJtI+fI4cbsk673Dn9r3wPvZzTN/QLcWhNbnBl3H5F1NKqbAJuqU6lFuwZBlTqBFI jRzOSzFP9PyJGZWuEfu+Z8ZsG0jcGfWczgI+MDdrAk1nZYJJPcDIeH1lmlMnNNhXqKay SgGA== X-Gm-Message-State: APjAAAWcrBpqz4qn7shKUGUNM0iEmfs+gm3ltKTPbpVNVDbxXxAEC1lH yRBbTPZwMm/owRGMDHhuxvkM7Hpq0VuJ2meSsB07p2x5tq5pAySsighvPfsR5/Xyd8h2mXxd+az +cYqz6M+f//faTa990WTY2SE3 X-Received: by 2002:adf:f311:: with SMTP id i17mr60432wro.81.1578609329576; Thu, 09 Jan 2020 14:35:29 -0800 (PST) X-Received: by 2002:adf:f311:: with SMTP id i17mr60417wro.81.1578609329396; Thu, 09 Jan 2020 14:35:29 -0800 (PST) Received: from [192.168.3.122] (p5B0C6BE2.dip0.t-ipconnect.de. [91.12.107.226]) by smtp.gmail.com with ESMTPSA id d12sm10031475wrp.62.2020.01.09.14.35.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Jan 2020 14:35:28 -0800 (PST) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: David Hildenbrand Mime-Version: 1.0 (1.0) Subject: Re: [PATCH v4] drivers/base/memory.c: cache blocks in radix tree to accelerate lookup Date: Thu, 9 Jan 2020 23:35:28 +0100 Message-Id: References: <20200109142758.659c1545cb8df2d05f299a4a@linux-foundation.org> Cc: David Hildenbrand , Scott Cheloha , linux-kernel@vger.kernel.org, "Rafael J. Wysocki" , Greg Kroah-Hartman , nathanl@linux.ibm.com, ricklind@linux.vnet.ibm.com, mhocko@suse.com, Scott Cheloha In-Reply-To: <20200109142758.659c1545cb8df2d05f299a4a@linux-foundation.org> To: Andrew Morton X-Mailer: iPhone Mail (17C54) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > Am 09.01.2020 um 23:28 schrieb Andrew Morton : >=20 > =EF=BB=BFOn Thu, 9 Jan 2020 23:17:09 +0100 David Hildenbrand wrote: >=20 >>=20 >>=20 >>>> Am 09.01.2020 um 23:00 schrieb Andrew Morton : >>>=20 >>> =EF=BB=BFOn Thu, 9 Jan 2020 15:25:16 -0600 Scott Cheloha wrote: >>>=20 >>>> Searching for a particular memory block by id is an O(n) operation >>>> because each memory block's underlying device is kept in an unsorted >>>> linked list on the subsystem bus. >>>>=20 >>>> We can cut the lookup cost to O(log n) if we cache the memory blocks in= >>>> a radix tree. With a radix tree cache in place both memory subsystem >>>> initialization and memory hotplug run palpably faster on systems with a= >>>> large number of memory blocks. >>>>=20 >>>> ... >>>>=20 >>>> @@ -56,6 +57,13 @@ static struct bus_type memory_subsys =3D { >>>> .offline =3D memory_subsys_offline, >>>> }; >>>>=20 >>>> +/* >>>> + * Memory blocks are cached in a local radix tree to avoid >>>> + * a costly linear search for the corresponding device on >>>> + * the subsystem bus. >>>> + */ >>>> +static RADIX_TREE(memory_blocks, GFP_KERNEL); >>>=20 >>> What protects this tree from racy accesses? >>=20 >> I think the device hotplug lock currently (except during boot where no ra= ces can happen). >>=20 >=20 > So this? >=20 > --- a/drivers/base/memory.c~drivers-base-memoryc-cache-blocks-in-radix-tre= e-to-accelerate-lookup-fix > +++ a/drivers/base/memory.c > @@ -61,6 +61,9 @@ static struct bus_type memory_subsys =3D { > * Memory blocks are cached in a local radix tree to avoid > * a costly linear search for the corresponding device on > * the subsystem bus. > + * > + * Protected by mem_hotplug_lock in mem_hotplug_begin(), and by the guara= nteed > + * single-threadness at boot time. > */ > static RADIX_TREE(memory_blocks, GFP_KERNEL); >=20 >=20 > But are we sure this is all true? I think the device hotplug lock, not the memory hotplug lock. Will double ch= eck later. >=20