Re: lib/genalloc

From: Daniel Mentz
Date: Fri Nov 02 2018 - 15:17:26 EST


On Thu, Nov 1, 2018 at 10:07 AM Alexey Skidanov
<alexey.skidanov@xxxxxxxxx> wrote:
> On 11/1/18 18:48, Stephen Bates wrote:
> >> I use gen_pool_first_fit_align() as pool allocation algorithm allocating
> >> buffers with requested alignment. But if a chunk base address is not
> >> aligned to the requested alignment(from some reason), the returned
> >> address is not aligned too.
> >
> > Alexey
> >
> > Can you try using gen_pool_first_fit_order_align()? Will that give you the alignment you need?
> >
> > Stephen
> >
> >
> I think it will not help me. Let's assume that the chunk base address is
> 0x2F400000 and I want to allocate 16MB aligned buffer. I get back the
> 0x2F400000. I think it happens because of this string in the
> gen_pool_alloc_algo():
>
> addr = chunk->start_addr + ((unsigned long)start_bit << order);
>
> and the gen_pool_first_fit_align() implementation that doesn't take into
> account the "incorrect" chunk base alignment.

gen_pool_first_fit_align() has no information about the chunk base
alignment. Hence, it can't take it into account.

How do you request the alignment in your code?

I agree with your analysis that gen_pool_first_fit_align() performs
alignment only with respect to the start of the chunk not the memory
address that gen_pool_alloc_algo() returns. I guess a solution would
be to only add chunks that satisfy all your alignment requirements. In
your case, you must only add chunks that are 16MB aligned.
I am unsure whether this is by design, but I believe it's the way that
the code currently works.