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 0CB792D24BF for ; Mon, 24 Nov 2025 18:55:36 +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=1764010538; cv=none; b=CUYJIN8YmEdaBdwnjVlou9TUrBj5mbD7tToXDmKu7Y4egfJQ3hLUg6daZO7iRue5NGUM4z0U9x3Cw6lr2GZWXZBy3LD7A1L0scpNcBCd0EzJOheXy+J+U+kq3/Yp44YNVQZZzVgsdnaVnO1OhowlZ4i0xQ/uM/XP1Ty+cLg+uT4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764010538; c=relaxed/simple; bh=3SE0/Et2OPNoa15k/OwfzwLXqIFiCevqJfyTaPRhQ9c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XMm4EAqPmYj3gH/HzjC5JGFyLWFBvNoeRJoH3z36KmJ3I/RUCfXno3woBx+FaFxu2PB0iSaELhTklRclMiCynaExuLzGfOP9WrVFSGxz4OAc23vgIqm0xY5JNXIP1La/r3gzMPteDQrLDpR1iMTLNkbSULhAqRGNvkhwypCsxpE= 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=nBm5f1U1; 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="nBm5f1U1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1764010537; x=1795546537; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=3SE0/Et2OPNoa15k/OwfzwLXqIFiCevqJfyTaPRhQ9c=; b=nBm5f1U1fAEE7LDHUu6HyGpuAa0hQ0RoMUhZ7X1RLoExjaR1kXdnLAPg aVryqIaj/1jjxRg5/nuEHLuRJUHceuRooDnClvowMS5bbTwD74wMs2nsX 14AO4I/pnITB2mnV7ycUcv8FuAVuOoibnoDAsBdaXdUK/vsFkKeTdJyWr mrj/hAzatphpUVeYWKgMIdeOsawna51xnh1VS4a1aic/4teRYMxCFia5u WWRtrA+ELzj6pi0JUatyRzPGG7WLyx59+f76Spiw2IDGZVtfS4Gi7BExP +KAHj+11FIOb3k47q8zEp0WUk44DpC24Zo52HEpOPKEoB1z1icsJtDLuQ w==; X-CSE-ConnectionGUID: 1ZqYOi8WTB6Oswjjg2m5FA== X-CSE-MsgGUID: pFVfiiuHSLSgfzoZzxaDNw== X-IronPort-AV: E=McAfee;i="6800,10657,11623"; a="66058551" X-IronPort-AV: E=Sophos;i="6.20,223,1758610800"; d="scan'208";a="66058551" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Nov 2025 10:55:36 -0800 X-CSE-ConnectionGUID: G4rRd8piQeig9kvf1h1sEQ== X-CSE-MsgGUID: 7GI5Jl49QNujECSNvV7rRg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,223,1758610800"; d="scan'208";a="191676686" Received: from egrumbac-mobl6.ger.corp.intel.com (HELO localhost) ([10.245.244.5]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Nov 2025 10:55:34 -0800 Date: Mon, 24 Nov 2025 20:55:31 +0200 From: "andriy.shevchenko@linux.intel.com" To: "Stamatis, Ilias" Cc: "akpm@linux-foundation.org" , "nadav.amit@gmail.com" , "david@kernel.org" , "linux-mm@kvack.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 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? > the full call stack being: > > find_next_iomem_res+0x3b ([kernel.kallsyms]) > walk_system_ram_range+0x98 ([kernel.kallsyms]) > pat_pagerange_is_ram+0x6e ([kernel.kallsyms]) > reserve_pfn_range+0x47 ([kernel.kallsyms]) > track_pfn_remap+0xb6 ([kernel.kallsyms]) > remap_pfn_range+0x3b ([kernel.kallsyms]) > mmap_mem+0x9e ([kernel.kallsyms]) > mm_struct_mmap_region+0x1f3 ([kernel.kallsyms]) > mmap_region+0xa3 ([kernel.kallsyms]) -- With Best Regards, Andy Shevchenko