Re: [PATCH] mm/sparse: Make sparse_init_one_section void and remove check

From: Michal Hocko
Date: Mon Jul 02 2018 - 12:05:20 EST


On Mon 02-07-18 17:43:25, osalvador@xxxxxxxxxxxxxxxxxx wrote:
> From: Oscar Salvador <osalvador@xxxxxxx>
>
> sparse_init_one_section() is being called from two sites:
> sparse_init() and sparse_add_one_section().
> The former calls it from a for_each_present_section_nr() loop,
> and the latter marks the section as present before calling it.
> This means that when sparse_init_one_section() gets called, we already know
> that the section is present.
> So there is no point to double check that in the function.
>
> This removes the check and makes the function void.

Looks good.

> Signed-off-by: Oscar Salvador <osalvador@xxxxxxx>

Acked-by: Michal Hocko <mhocko@xxxxxxxx>

> ---
> mm/sparse.c | 12 +++---------
> 1 file changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/mm/sparse.c b/mm/sparse.c
> index b2848cc6e32a..f55e79fda03e 100644
> --- a/mm/sparse.c
> +++ b/mm/sparse.c
> @@ -264,19 +264,14 @@ struct page *sparse_decode_mem_map(unsigned long coded_mem_map, unsigned long pn
> return ((struct page *)coded_mem_map) + section_nr_to_pfn(pnum);
> }
>
> -static int __meminit sparse_init_one_section(struct mem_section *ms,
> +static void __meminit sparse_init_one_section(struct mem_section *ms,
> unsigned long pnum, struct page *mem_map,
> unsigned long *pageblock_bitmap)
> {
> - if (!present_section(ms))
> - return -EINVAL;
> -
> ms->section_mem_map &= ~SECTION_MAP_MASK;
> ms->section_mem_map |= sparse_encode_mem_map(mem_map, pnum) |
> SECTION_HAS_MEM_MAP;
> ms->pageblock_flags = pageblock_bitmap;
> -
> - return 1;
> }
>
> unsigned long usemap_size(void)
> @@ -801,12 +796,11 @@ int __meminit sparse_add_one_section(struct pglist_data *pgdat,
> #endif
>
> section_mark_present(ms);
> -
> - ret = sparse_init_one_section(ms, section_nr, memmap, usemap);
> + sparse_init_one_section(ms, section_nr, memmap, usemap);
>
> out:
> pgdat_resize_unlock(pgdat, &flags);
> - if (ret <= 0) {
> + if (ret < 0) {
> kfree(usemap);
> __kfree_section_memmap(memmap, altmap);
> }
> --
> 2.13.6
>

--
Michal Hocko
SUSE Labs