Re: [PATCH v2 1/2] of: reserved_mem: Try to keep range allocations contiguous

From: Rob Herring
Date: Tue Jun 20 2023 - 11:35:00 EST



On Wed, 14 Jun 2023 21:20:42 +0200, Stephan Gerhold wrote:
> Right now dynamic reserved memory regions are allocated either
> bottom-up or top-down, depending on the memblock setting of the
> architecture. This is fine when the address is arbitrary. However,
> when using "alloc-ranges" the regions are often placed somewhere
> in the middle of (free) RAM, even if the range starts or ends next
> to another (static) reservation.
>
> Try to detect this situation, and choose explicitly between bottom-up
> or top-down to allocate the memory close to the other reservations:
>
> 1. If the "alloc-range" starts at the end or inside an existing
> reservation, use bottom-up.
> 2. If the "alloc-range" ends at the start or inside an existing
> reservation, use top-down.
> 3. If both or none is the case, keep the current
> (architecture-specific) behavior.
>
> There are plenty of edge cases where only a more complex algorithm
> would help, but even this simple approach helps in many cases to keep
> the reserved memory (and therefore also the free memory) contiguous.
>
> Signed-off-by: Stephan Gerhold <stephan@xxxxxxxxxxx>
> ---
> drivers/of/of_reserved_mem.c | 55 ++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 53 insertions(+), 2 deletions(-)
>

Applied, thanks!