Skip to content

Commit 6fb3acd

Browse files
ilstamakpm00
authored andcommitted
Reinstate "resource: avoid unnecessary lookups in find_next_iomem_res()"
Commit 97523a4 ("kernel/resource: remove first_lvl / siblings_only logic") removed an optimization introduced by commit 7563987 ("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 97523a4 removed the 'sibling_only' parameter from next_resource(), newer kernels have basically reinstated it under the name 'skip_children'. Link: https://lore.kernel.org/all/20251124165349.3377826-1-ilstam@amazon.com/T/#u Fixes: 97523a4 ("kernel/resource: remove first_lvl / siblings_only logic") Signed-off-by: Ilias Stamatis <ilstam@amazon.com> Acked-by: David Hildenbrand (Red Hat) <david@kernel.org> Cc: Andriy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: Baoquan He <bhe@redhat.com> Cc: "Huang, Ying" <huang.ying.caritas@gmail.com> Cc: Nadav Amit <nadav.amit@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 3fa805c commit 6fb3acd

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

kernel/resource.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ static int find_next_iomem_res(resource_size_t start, resource_size_t end,
341341
unsigned long flags, unsigned long desc,
342342
struct resource *res)
343343
{
344+
/* Skip children until we find a top level range that matches */
345+
bool skip_children = true;
344346
struct resource *p;
345347

346348
if (!res)
@@ -351,7 +353,7 @@ static int find_next_iomem_res(resource_size_t start, resource_size_t end,
351353

352354
read_lock(&resource_lock);
353355

354-
for_each_resource(&iomem_resource, p, false) {
356+
for_each_resource(&iomem_resource, p, skip_children) {
355357
/* If we passed the resource we are looking for, stop */
356358
if (p->start > end) {
357359
p = NULL;
@@ -362,6 +364,12 @@ static int find_next_iomem_res(resource_size_t start, resource_size_t end,
362364
if (p->end < start)
363365
continue;
364366

367+
/*
368+
* We found a top level range that matches what we are looking
369+
* for. Time to start checking children too.
370+
*/
371+
skip_children = false;
372+
365373
/* Found a match, break */
366374
if (is_type_match(p, flags, desc))
367375
break;

0 commit comments

Comments
 (0)