Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2528441ybl; Thu, 9 Jan 2020 14:29:11 -0800 (PST) X-Google-Smtp-Source: APXvYqwasu5q4bCoBt/u6E0p37+kZ9aWVvnQcyDbYlsMtklFdmycmI3T4J51Sf91KlVah7u1mLrs X-Received: by 2002:a54:4f8d:: with SMTP id g13mr4831941oiy.43.1578608951377; Thu, 09 Jan 2020 14:29:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578608951; cv=none; d=google.com; s=arc-20160816; b=XT5rtYx3o1jPepJylgglP9VzTz94Bkv+nORfdNWd5/tdy2ejg0RJc+SklLIia7AOCj ZXiAS1JUNgmdk1wh9WxgwgSelZLvrfKEQ8eUk2tiDzGbbsk2E0kf+QD/xAlqVBef3AW3 fVAnZDX09JB2nQKBEyIahQ+xHc3rtXVoxz7E+YPSIs2NfmAtj+nFLqiIYlo1Pn+yNUVK +BEt0AYCFx0mZPgnbavbmmwRgB/mRjr4yf1A3xBMsvY6EAjYwYsyT4rhNRNeqCAOtu3x 4z1QdsJqw7OEub4JBqRBunak6N8rz3918sUwulDFVTtDvzlaYS514cs0n9yK+L7KCW5K rrug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=/jk1ELWTZdi3cKhmGQ0OFvTPjdJz2sI0Lzn0CLjr/E4=; b=IcQkjsuSZsnaDjaFgHd6dN/XmntqyswlwfyVxRoPYjoOSrR/imYoa3UQeIaT7UrsaS tFP06ZTowVeKVcGTMFOqH44p5ydXlKStMF21HUaxu1whC4q8Z7V7VdsJ5z34UA7jFKHK 2QgwEQAOyI6RcoA6npPyA8L2fDCxJ9bitzE5ny2iJXb9ZepcKl1D6S/Z/ujN6dHuPNFI JIPmT7DgU50WZgnmbxhqnktfdSdESiEQW2oGh7ttPr/Oo25bDGr0mel5qdkpXHJky4iR woBgb6vY9G+GNU8kljMX6U61bIzdW9WC1G1Bs9cWQasycWrEfKwC4g3uPBhv/QPffUVp S/vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="z1/mxcQb"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a12si4411602oie.87.2020.01.09.14.28.59; Thu, 09 Jan 2020 14:29:11 -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=@kernel.org header.s=default header.b="z1/mxcQb"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727876AbgAIW17 (ORCPT + 99 others); Thu, 9 Jan 2020 17:27:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:47576 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725807AbgAIW17 (ORCPT ); Thu, 9 Jan 2020 17:27:59 -0500 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AB2CF20721; Thu, 9 Jan 2020 22:27:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578608879; bh=TxbIGR36dvOlKfNVHdzDzkWYnXZTHkmv3nkio2YU/DY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=z1/mxcQb8o1oxfKd+2AaQ24Z6XwN7xjdpxSzkptPtP70tSOu7PxwfSjyepRoSAvMS mnAeT1A9zkE9kFL8wv5+4rag7hw+aj534gCLcsUTtP+xUGe8VShhMKUBOiK0E3aEGQ 6lsp0pVZeMXjMw5WDIYr0jDETmazl6LYTDXr4fAA= Date: Thu, 9 Jan 2020 14:27:58 -0800 From: Andrew Morton To: David Hildenbrand Cc: 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 Subject: Re: [PATCH v4] drivers/base/memory.c: cache blocks in radix tree to accelerate lookup Message-Id: <20200109142758.659c1545cb8df2d05f299a4a@linux-foundation.org> In-Reply-To: References: <20200109140004.d5e6dc581b62d6e078dcca4c@linux-foundation.org> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 9 Jan 2020 23:17:09 +0100 David Hildenbrand wrote: > > > > Am 09.01.2020 um 23:00 schrieb Andrew Morton : > > > > On Thu, 9 Jan 2020 15:25:16 -0600 Scott Cheloha wrote: > > > >> 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. > >> > >> 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. > >> > >> ... > >> > >> @@ -56,6 +57,13 @@ static struct bus_type memory_subsys = { > >> .offline = memory_subsys_offline, > >> }; > >> > >> +/* > >> + * 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); > > > > What protects this tree from racy accesses? > > I think the device hotplug lock currently (except during boot where no races can happen). > So this? --- a/drivers/base/memory.c~drivers-base-memoryc-cache-blocks-in-radix-tree-to-accelerate-lookup-fix +++ a/drivers/base/memory.c @@ -61,6 +61,9 @@ static struct bus_type memory_subsys = { * 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 guaranteed + * single-threadness at boot time. */ static RADIX_TREE(memory_blocks, GFP_KERNEL); But are we sure this is all true?