Re: [PATCH 2/4] mm/memblock: introduce memblock_search_pfn_regions()

From: Daniel Vacek
Date: Wed Mar 21 2018 - 06:15:02 EST


On Wed, Mar 21, 2018 at 9:09 AM, Jia He <hejianet@xxxxxxxxx> wrote:
> This api is the preparation for further optimizing early_pfn_valid
>
> Signed-off-by: Jia He <jia.he@xxxxxxxxxxxxxxxx>
> ---
> include/linux/memblock.h | 2 ++
> mm/memblock.c | 12 ++++++++++++
> 2 files changed, 14 insertions(+)
>
> diff --git a/include/linux/memblock.h b/include/linux/memblock.h
> index 9471db4..5f46956 100644
> --- a/include/linux/memblock.h
> +++ b/include/linux/memblock.h
> @@ -203,6 +203,8 @@ void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn,
> i >= 0; __next_mem_pfn_range(&i, nid, p_start, p_end, p_nid))
> #endif /* CONFIG_HAVE_MEMBLOCK_NODE_MAP */
>
> +int memblock_search_pfn_regions(unsigned long pfn);
> +
> unsigned long memblock_next_valid_pfn(unsigned long pfn, int *last_idx);
> /**
> * for_each_free_mem_range - iterate through free memblock areas
> diff --git a/mm/memblock.c b/mm/memblock.c
> index a9e8da4..f50fe5b 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -1659,6 +1659,18 @@ static int __init_memblock memblock_search(struct memblock_type *type, phys_addr
> return -1;
> }
>
> +/* search memblock with the input pfn, return the region idx */
> +int __init_memblock memblock_search_pfn_regions(unsigned long pfn)
> +{
> + struct memblock_type *type = &memblock.memory;
> + int mid = memblock_search(type, PFN_PHYS(pfn));
> +
> + if (mid == -1)
> + return -1;

Why this?

> + return mid;
> +}
> +
> bool __init memblock_is_reserved(phys_addr_t addr)
> {
> return memblock_search(&memblock.reserved, addr) != -1;
> --
> 2.7.4
>