From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73F8B2F547F for ; Tue, 25 Nov 2025 06:50:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764053427; cv=none; b=r/3JN3lYy8vCNGRroaWc4LLdMbuoQxJZs7+sVLHgJBeZZFLoOt6Jy7rtrj7+uwIGlCHNx1XDbOJeMaaX5tgNlJWzMA21RfdtXO298KYjAi4B/pjVz9X4C6/i+jTJsoJanam/qxmFLnw9aYOv6IAJ5l0i7upfZf5wHjzBo3U2Tn0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764053427; c=relaxed/simple; bh=GP5x2wXUEGliCLTfZ2baoJMi8TotIkX5B+6PzpiiFJQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=G3LQl/yVQJgTI2y75yrZWtEyH0asc3/BkGFmuNXHkNeAR7qQEkwkURy5zQ8ZdQleRkWtbD4a5pdjvBM73ganPf8ZrL1A3j0iuWpZPHfR7wDB64+x5inBMRDlfDjhiww+J0xuBbXOMIEbfa8FeliI4Y4R82XvplalaHun+ZuyL8M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=jCoWTqmz; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jCoWTqmz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1764053425; x=1795589425; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=GP5x2wXUEGliCLTfZ2baoJMi8TotIkX5B+6PzpiiFJQ=; b=jCoWTqmzGxTUbaW0gLWcLelr1DE2ri2y1yYhc/Z6zH5/8mc3FtPIT8vc XLetXDKVF98S0b3HGgMGvbxhZYJufY1sRhe77I9tIq1a55UksEVdVcvVo f5FgfE8a/aTD+94nN+P/kLvIGODhF4pMU8FcXrCyAM61PqJCurPZAjVcd Gzs6WeLNo/UYDXscYvE7uLmcoIkRkDdm0lRN4RLZiaib52AG7QUMyeIbG hdov62Xark0Myszypilk6vzfLpJxui3R39ZIpzk1x2Pvrt6207D5nofuC fxEM5vAjbFWRXk5MwfLsfd3vQapd4KRhB5N1p+0JD5k0bEuHhRmvRvkSY A==; X-CSE-ConnectionGUID: j9L0IFTpS36aQZIowZAH8w== X-CSE-MsgGUID: D/Br24tCQmm1PwHoCCbDYg== X-IronPort-AV: E=McAfee;i="6800,10657,11623"; a="66108062" X-IronPort-AV: E=Sophos;i="6.20,224,1758610800"; d="scan'208";a="66108062" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Nov 2025 22:50:24 -0800 X-CSE-ConnectionGUID: uP2AE0rCQQeN5wNC1WVE4Q== X-CSE-MsgGUID: qJcQNfFvQ2iZ0DZqQwfnSw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,224,1758610800"; d="scan'208";a="192361094" Received: from abityuts-desk.ger.corp.intel.com (HELO localhost) ([10.245.244.152]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Nov 2025 22:50:22 -0800 Date: Tue, 25 Nov 2025 08:50:20 +0200 From: "andriy.shevchenko@linux.intel.com" To: "Stamatis, Ilias" Cc: "nadav.amit@gmail.com" , "david@kernel.org" , "linux-mm@kvack.org" , "akpm@linux-foundation.org" , "linux-kernel@vger.kernel.org" , "huang.ying.caritas@gmail.com" , "bhe@redhat.com" , "nh-open-source@amazon.com" Subject: Re: [PATCH] Reinstate "resource: avoid unnecessary lookups in find_next_iomem_res()" Message-ID: References: <20251124165349.3377826-1-ilstam@amazon.com> <20251124085816.07dbf5a4ec6235b2943840a0@linux-foundation.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo On Mon, Nov 24, 2025 at 11:30:46PM +0000, Stamatis, Ilias wrote: > On Mon, 2025-11-24 at 21:52 +0200, andriy.shevchenko@linux.intel.com wrote: > > On Mon, Nov 24, 2025 at 07:35:31PM +0000, Stamatis, Ilias wrote: > > > On Mon, 2025-11-24 at 20:55 +0200, andriy.shevchenko@linux.intel.com wrote: > > > > On Mon, Nov 24, 2025 at 06:01:35PM +0000, Stamatis, Ilias wrote: > > > > > On Mon, 2025-11-24 at 08:58 -0800, Andrew Morton wrote: > > > > > > On Mon, 24 Nov 2025 16:53:49 +0000 Ilias Stamatis wrote: > > > > > > > > > > > > > Commit 97523a4edb7b ("kernel/resource: remove first_lvl / siblings_only > > > > > > > logic") removed an optimization introduced by commit 756398750e11 > > > > > > > ("resource: avoid unnecessary lookups in find_next_iomem_res()"). That > > > > > > > was not called out in the message of the first commit explicitly so it's > > > > > > > not entirely clear whether removing the optimization happened > > > > > > > inadvertently or not. > > > > > > > > > > > > > > As the original commit message of the optimization explains there is no > > > > > > > point considering the children of a subtree in find_next_iomem_res() if > > > > > > > the top level range does not match. Reinstating the optimization results > > > > > > > in significant performance improvements in systems with very large iomem > > > > > > > maps when mmaping /dev/mem. > > > > > > > > > > > > It would be great if we could quantify "significant performance > > > > > > improvements"? > > > > > > > > > > Hi Andrew and Andy, > > > > > > > > > > You are right to call that out and apologies for leaving it vague. > > > > > > > > > > I've done my testing with older kernel versions in systems where `wc -l > > > > > /proc/iomem` can return ~5k. In that environment I see mmaping parts of > > > > > /dev/mem taking 700-1500μs without the optimisation and 10-50μs with the > > > > > optimisation. > > > > > > > > > > The real-world use case we care about is hypervisor live update where having to > > > > > do lots of these mmaps() serially can significantly affect the guest downtime > > > > > if the cost is 20-30x. > > > > > > > > Thanks for providing this information. > > > > > > > > > > It also would be good to know which exact function(s) is a bottleneck. > > > > > > > > > > Perf tracing shows that ~95% of CPU time is spent in find_next_iomem_res(), > > > > > > > > Have you investigated possibility to return that check directly into > > > > the culprit? > > > > > > I'm sorry, I don't understand this. Could you please clarify what you mean? > > > What do you consider to be the culprit and which check do you refer to? > > > > The mentioned patch removed the check for siblings from next_resource(). > > The function that your test case complains about is find_next_iomem_res(). > > Hence, have you tried to reinstantiate the (removed) check from next_resource() > > in find_next_iomem_res() and see if it helps? > > next_resource() does accept a 'skip_children' parameter in the latest kernel > today which is equivalent to the 'sibling_only' parameter in the older > kernels. It used to be if (sibling_only) return p->sibling; if (p->child) return p->child; ... and become (in the latest kernels) if (!skip_children && p->child) return p->child; ... Can you elaborate how are they interoperable? TL;DR: I don't think it's an equivalent. > And the for_each_resource() macro currently used in find_next_iomem_res() > calls next_resource(). > > Hope that makes sense. -- With Best Regards, Andy Shevchenko