linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Reinstate "resource: avoid unnecessary lookups in find_next_iomem_res()"
@ 2025-11-24 16:53 Ilias Stamatis
  2025-11-24 16:58 ` Andrew Morton
  2025-11-25  8:09 ` David Hildenbrand (Red Hat)
  0 siblings, 2 replies; 14+ messages in thread
From: Ilias Stamatis @ 2025-11-24 16:53 UTC (permalink / raw)
  To: akpm, linux-kernel
  Cc: linux-mm, david, nadav.amit, huang.ying.caritas,
	andriy.shevchenko, bhe, nh-open-source, Ilias Stamatis

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 <ilstam@amazon.com>
---
 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, resource_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 = true;
 	struct resource *p;
 
 	if (!res)
@@ -351,7 +353,7 @@ static int find_next_iomem_res(resource_size_t start, resource_size_t end,
 
 	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_size_t start, resource_size_t end,
 		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;
-- 
2.43.0



^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2025-11-25 18:30 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-24 16:53 [PATCH] Reinstate "resource: avoid unnecessary lookups in find_next_iomem_res()" Ilias Stamatis
2025-11-24 16:58 ` Andrew Morton
2025-11-24 17:05   ` Andy Shevchenko
     [not found]   ` <c7411175b332f3befb5bebb6a75c7b91f2c1dbbc.camel@amazon.co.uk>
2025-11-24 18:55     ` andriy.shevchenko
2025-11-24 19:35       ` Stamatis, Ilias
2025-11-24 19:52         ` andriy.shevchenko
2025-11-24 23:30           ` Stamatis, Ilias
2025-11-25  6:50             ` andriy.shevchenko
2025-11-25  9:56               ` Stamatis, Ilias
2025-11-25 10:23                 ` andriy.shevchenko
2025-11-25 14:23                   ` Stamatis, Ilias
2025-11-25 18:30                     ` andriy.shevchenko
2025-11-25  8:09 ` David Hildenbrand (Red Hat)
2025-11-25  8:18   ` David Hildenbrand (Red Hat)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox