From nobody Tue Dec 2 00:26:26 2025 Received: from fra-out-012.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-012.esa.eu-central-1.outbound.mail-perimeter.amazon.com [52.57.120.243]) (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 7C918313E24 for ; Mon, 24 Nov 2025 16:55:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.57.120.243 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764003360; cv=none; b=mTGPxLAN+cGA2vykAnda48QdSdpn4WVT4AIOiSSIql1fzvwPP2YGvoLG2Hrs5UnxGtIxPQgKWrMD8ZwxpUItzpJCru3JGvCsvUV8Y6znqaFSX8G1PjUj7Wc/kxvV0sJ5yEGKx/gkrReOmVWh6w9xJ5UHiiwhtz0wCgdesQtRY3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764003360; c=relaxed/simple; bh=yx1mRPUSjm8NrK+taTNsXp6qVeTkBYd5KL+ObWl9vPs=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=LIeXol5RaprmOXtCB20sp/fOpMrpsubtAj1VdP7bGdct1jBoy7EgtSmyBnFdnMIEEGSmvgWvv1FxRnW3DKzjlvc1qF0PI8K1eta/G/PI+/82cIYv1iQOFHyNG9EvQ6cLMMwUMqD5RQMbQe3KG16UIPm+L3lrsIc+/zT6SivLuT4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.uk; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b=O8CUk7DG; arc=none smtp.client-ip=52.57.120.243 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b="O8CUk7DG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1764003358; x=1795539358; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=DklLliY6AN74AT2WZnGYkOlsNBTypcLntoZnCtS2gcM=; b=O8CUk7DGEX9jmPy4J3J5D6clQ91LQMqFrj+IDSeb5VubtUM4Qt795hyt YU05gdGo5ENgVYNm9Dej0d2WCnuwZlRKVo//v3y8nY+gXGjKNnri0IQIu rEjFSqt3D2YQdoPz3mSs5M4tUV2Q33BudkDdQD19vovV+feDxh/jngOKm ZdRBHqbWiWfQ9qZjmFEdAvXfS4waznjHpxIU4gaSxGmavubjg/oinTBkg TirTuzbHzMRImjNCkOu3xTgqRm97soa25T9QXhW6LsgsNFF/iNYU0p4oB ovvZm454wHXI+Y9N0iGLFENwynNbalv93Aaqh0yGBI9IHCtVAlJoxLHcC g==; X-CSE-ConnectionGUID: fNPqlkkKQJOLXpzGeulCWw== X-CSE-MsgGUID: DKuq2tyGQxya5blLXf9mXg== X-IronPort-AV: E=Sophos;i="6.20,223,1758585600"; d="scan'208";a="5619651" Received: from ip-10-6-3-216.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.3.216]) by internal-fra-out-012.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Nov 2025 16:55:40 +0000 Received: from EX19MTAEUA001.ant.amazon.com [54.240.197.233:14173] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.46.211:2525] with esmtp (Farcaster) id c81b9fde-5d51-4f49-8f6b-6dee1e1c9ec9; Mon, 24 Nov 2025 16:55:40 +0000 (UTC) X-Farcaster-Flow-ID: c81b9fde-5d51-4f49-8f6b-6dee1e1c9ec9 Received: from EX19D018EUA002.ant.amazon.com (10.252.50.146) by EX19MTAEUA001.ant.amazon.com (10.252.50.192) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.29; Mon, 24 Nov 2025 16:55:35 +0000 Received: from u94b036d6357a55.ant.amazon.com.com (10.106.83.8) by EX19D018EUA002.ant.amazon.com (10.252.50.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.29; Mon, 24 Nov 2025 16:55:31 +0000 From: Ilias Stamatis To: , CC: , , , , , , , Ilias Stamatis Subject: [PATCH] Reinstate "resource: avoid unnecessary lookups in find_next_iomem_res()" Date: Mon, 24 Nov 2025 16:53:49 +0000 Message-ID: <20251124165349.3377826-1-ilstam@amazon.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: EX19D039UWA002.ant.amazon.com (10.13.139.32) To EX19D018EUA002.ant.amazon.com (10.252.50.146) Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Ilias Stamatis Acked-by: David Hildenbrand (Red Hat) --- kernel/resource.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kernel/resource.c b/kernel/resource.c index b9fa2a4ce089..e4e9bac12e6e 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -341,6 +341,8 @@ static int find_next_iomem_res(resource_size_t start, r= esource_size_t end, unsigned long flags, unsigned long desc, struct resource *res) { + /* Skip children until we find a top level range that matches */ + bool skip_children =3D true; struct resource *p; =20 if (!res) @@ -351,7 +353,7 @@ static int find_next_iomem_res(resource_size_t start, r= esource_size_t end, =20 read_lock(&resource_lock); =20 - for_each_resource(&iomem_resource, p, false) { + for_each_resource(&iomem_resource, p, skip_children) { /* If we passed the resource we are looking for, stop */ if (p->start > end) { p =3D NULL; @@ -362,6 +364,12 @@ static int find_next_iomem_res(resource_size_t start, = resource_size_t end, if (p->end < start) continue; =20 + /* + * We found a top level range that matches what we are looking + * for. Time to start checking children too. + */ + skip_children =3D false; + /* Found a match, break */ if (is_type_match(p, flags, desc)) break; --=20 2.43.0