Skip to contentSkip to conversation

reinstate-resource-avoid-unnecessary-lookups-in-find_next_iomem_res.patch removed from -mm tree

merged mm-nonmm-stable Andrew Morton 1 participant 1 message Nov 27, 2025

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: Reinstate "resource: avoid unnecessary lookups in find_next_iomem_res()"
has been removed from the -mm tree. Its filename was
reinstate-resource-avoid-unnecessary-lookups-in-find_next_iomem_res.patch

This patch was dropped because it was merged into the mm-nonmm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Ilias Stamatis <[email protected]>
Subject: Reinstate "resource: avoid unnecessary lookups in find_next_iomem_res()"
Date: Mon, 24 Nov 2025 16:53:49 +0000

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 performance improvements in systems where /proc/iomem is ~5k lines long. Calling mmap() on /dev/mem in such platforms takes 700-1500μs without the optimisation and 10-50μs with the optimisation.

Note that even though commit 97523a4edb7b removed the 'sibling_only' parameter from next_resource(), newer kernels have basically reinstated it under the name 'skip_children'.

Fixes 97523a4edb7b ("kernel/resource: remove first_lvl / siblings_only logic")
Cc Andriy Shevchenko <[email protected]>
Cc Baoquan He <[email protected]>
Cc "Huang, Ying" <[email protected]>
Cc Nadav Amit <[email protected]>

---

 kernel/resource.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
kernel/resource.c renamed from kernel/resource.c~reinstate-resource-avoid-unnecessary-lookups-in-find_next_iomem_res +9 -1
@@ -341,6 +341,8 @@ static int find_next_iomem_res(resource_
 			       unsigned long flags, unsigned long desc,
 			       struct resource *res)
 {
+	/* Skip children until we find a top level range that matches */
+	bool skip_children = true;
 	struct resource *p;
 
 	if (!res)
@@ -351,7 +353,7 @@ static int find_next_iomem_res(resource_
 
 	read_lock(&resource_lock);
 
-	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 = NULL;
@@ -362,6 +364,12 @@ static int find_next_iomem_res(resource_
 		if (p->end < start)
 			continue;
 
+		/*
+		 * We found a top level range that matches what we are looking
+		 * for. Time to start checking children too.
+		 */
+		skip_children = false;
+
 		/* Found a match, break */
 		if (is_type_match(p, flags, desc))
 			break;

_

Patches currently in -mm which might be from [email protected] are