The patch titled Subject: resource: re-factor page_is_ram() has been added to the -mm mm-nonmm-unstable branch. Its filename is resource-re-factor-page_is_ram.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/resource-re-factor-page_is_ram.patch This patch will later appear in the mm-nonmm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Vaibhav Jain <vaibhav@xxxxxxxxxxxxx> Subject: resource: re-factor page_is_ram() Date: Wed, 1 Jun 2022 22:02:43 +0530 Presently page_is_ram() relies on walk_system_ram_range() that performs a walk on kernel iomem resources hierarchy with a dummy callback __is_ram(). Before calling find_next_iomem_res(), walk_system_ram_range() does some book-keeping which can be avoided for page_is_ram() use-case. Hence this patch proposes to update page_is_ram() to directly call find_next_iomem_res() with minimal book-keeping needed. To avoid allocating a 'struct resource' the patch also updates find_next_iomem_res() to not return -EINVAL in case 'res == NULL'. Instead our 'struct resource *res' is only populated when its not NULL. Link: https://lkml.kernel.org/r/20220601163243.3806231-1-vaibhav@xxxxxxxxxxxxx Signed-off-by: Vaibhav Jain <vaibhav@xxxxxxxxxxxxx> Cc: Vaibhav Jain <vaibhav@xxxxxxxxxxxxx> Cc: "Aneesh Kumar K . V" <aneesh.kumar@xxxxxxxxxxxxx> Cc: David Hildenbrand <david@xxxxxxxxxx> Cc: Dan Williams <dan.j.williams@xxxxxxxxx> Cc: Miaohe Lin <linmiaohe@xxxxxxxxxx> Cc: Muchun Song <songmuchun@xxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- kernel/resource.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) --- a/kernel/resource.c~resource-re-factor-page_is_ram +++ a/kernel/resource.c @@ -311,7 +311,7 @@ EXPORT_SYMBOL(release_resource); * * If a resource is found, returns 0 and @*res is overwritten with the part * of the resource that's within [@start..@end]; if none is found, returns - * -ENODEV. Returns -EINVAL for invalid parameters. + * -ENODEV. * * @start: start address of the resource searched for * @end: end address of same resource @@ -328,9 +328,6 @@ static int find_next_iomem_res(resource_ { struct resource *p; - if (!res) - return -EINVAL; - if (start >= end) return -EINVAL; @@ -356,7 +353,7 @@ static int find_next_iomem_res(resource_ break; } - if (p) { + if (p && res) { /* copy data */ *res = (struct resource) { .start = max(start, p->start), @@ -474,18 +471,18 @@ int walk_system_ram_range(unsigned long return ret; } -static int __is_ram(unsigned long pfn, unsigned long nr_pages, void *arg) -{ - return 1; -} - /* * This generic page_is_ram() returns true if specified address is * registered as System RAM in iomem_resource list. */ int __weak page_is_ram(unsigned long pfn) { - return walk_system_ram_range(pfn, 1, NULL, __is_ram) == 1; + const resource_size_t pfn_res = PFN_PHYS(pfn); + + return find_next_iomem_res(pfn_res, + pfn_res + 1, + IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY, + IORES_DESC_NONE, NULL) == 0; } EXPORT_SYMBOL_GPL(page_is_ram); _ Patches currently in -mm which might be from vaibhav@xxxxxxxxxxxxx are resource-re-factor-page_is_ram.patch