Re: [PATCH v6 1/3] mm/memblock: introduce a new helper memblock_estimated_nr_free_pages()

Alexander Gordeev
2024-08-08T16:10:49Z

On Thu, Aug 08, 2024 at 02:24:05PM +0000, Wei Yang wrote:
> >> + * An estimated number of free pages from memblock point of view.
> >> + */
> >> +unsigned long __init memblock_estimated_nr_free_pages(void)
> >> +{
> >> + return PHYS_PFN(memblock_phys_mem_size() - memblock_reserved_size());
> >> +}
> >
> >This could possibly be short on up to two pages due to lack of alignment.
> >The current uses are okay, but since you make it generic it probably matters.
> >
>
> I don't follow, would you mind giving more detail?

memblock_estimated_nr_free_pages() returns number of pages, not bytes.
Yet, both memblock_phys_mem_size() and memblock_reserved_size() return
a value which is not aligned on PAGE_SIZE. Therefore, the result of
PHYS_PFN() applied to the difference between the two functions might
be short on one (two?) page(s).

> >Also, the returned value is not an estimation. Meaning the function name
> >is rather unfortunate AFAICT.
>
> From my point of view, this is an estimation for two reasons:
>
> * value from memblock_xxx is not page size aligned
> * reserved memory maybe released during boot stage
>
> It is not that easy to get the exact number of free pages here. Do I miss
> something?

No, with this reasoning it makes sense to me.

> --
> Wei Yang
> Help you, Help me

Thank you for the clarification!