OSDN Git Service

of: reserved_mem: Try to keep range allocations contiguous
authorStephan Gerhold <stephan@gerhold.net>
Wed, 14 Jun 2023 19:20:42 +0000 (21:20 +0200)
committerRob Herring <robh@kernel.org>
Tue, 20 Jun 2023 15:34:47 +0000 (09:34 -0600)
commit83ba7361e168cd7b24aa95d2aefb4e31e3cc6cd0
treef7b0218e6a6a215479e2c3710675963882a1ede4
parent02478c98f2c2da448e2cb3fd95b209a84850e09b
of: reserved_mem: Try to keep range allocations contiguous

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@gerhold.net>
Link: https://lore.kernel.org/r/20230510-dt-resv-bottom-up-v2-1-aeb2afc8ac25@gerhold.net
Signed-off-by: Rob Herring <robh@kernel.org>
drivers/of/of_reserved_mem.c