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

From: Wei Yang
Date: Thu Aug 08 2024 - 10:24:34 EST


On Thu, Aug 08, 2024 at 12:06:38PM +0200, Alexander Gordeev wrote:
>On Thu, Aug 08, 2024 at 12:14:13AM +0000, Wei Yang wrote:
>
>Hi Wei,
>
>...
>> + * Return:
>> + * 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?

>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?

>
>> +#define PHYS_PFN(x) ((unsigned long)((x) >> PAGE_SHIFT))
>
>Thanks!

--
Wei Yang
Help you, Help me