Re: [PATCH V2] mm/page_alloc: Add alloc_contig_pages()

From: Michal Hocko
Date: Thu Oct 17 2019 - 03:11:34 EST


On Thu 17-10-19 10:44:41, Anshuman Khandual wrote:
[...]
> Does this add-on documentation look okay ? Should we also mention about the
> possible reduction in chances of success during pfn block search for the
> non-power-of-two cases as the implicit alignment will probably turn out to
> be bigger than nr_pages itself ?
>
> * Requested nr_pages may or may not be power of two. The search for suitable
> * memory range in a zone happens in nr_pages aligned pfn blocks. But in case
> * when nr_pages is not power of two, an implicitly aligned pfn block search
> * will happen which in turn will impact allocated memory block's alignment.
> * In these cases, the size (i.e nr_pages) and the alignment of the allocated
> * memory will be different. This problem does not exist when nr_pages is power
> * of two where the size and the alignment of the allocated memory will always
> * be nr_pages.

I dunno, it sounds more complicated than really necessary IMHO. Callers
shouldn't really be bothered by memory blocks and other really deep
implementation details.. Wouldn't be the below sufficient?

The allocated memory is always aligned to a page boundary. If nr_pages
is a power of two then the alignement is guaranteed to be to the given
nr_pages (e.g. 1GB request would be aligned to 1GB).
--
Michal Hocko
SUSE Labs