[PATCH v3 3/3] lib: sbi: Implement aligned memory allocators

Jessica Clarke jrtc27 at jrtc27.com
Thu Aug 8 10:49:47 PDT 2024


On 8 Aug 2024, at 18:47, Gregor Haas <gregorhaas1997 at gmail.com> wrote:
> 
> Hi Anup,
> 
>> On Aug 7, 2024, at 10:33 PM, Anup Patel <anup at brainfault.org> wrote:
>> 
>> On Wed, Aug 7, 2024 at 11:47 PM Gregor Haas <gregorhaas1997 at gmail.com> wrote:
>>> 
>>> This change adds a simple implementation of sbi_memalign(), for future use in
>>> allocating aligned memory for SMMTT tables.
>>> 
>>> Signed-off-by: Gregor Haas <gregorhaas1997 at gmail.com>
>>> ---
>>> include/sbi/sbi_heap.h |  9 +++++
>>> lib/sbi/sbi_heap.c     | 81 ++++++++++++++++++++++++++++++++++++++----
>>> 2 files changed, 84 insertions(+), 6 deletions(-)
>>> 
>>> diff --git a/include/sbi/sbi_heap.h b/include/sbi/sbi_heap.h
>>> index 9a67090..2103aef 100644
>>> --- a/include/sbi/sbi_heap.h
>>> +++ b/include/sbi/sbi_heap.h
>>> @@ -31,6 +31,15 @@ static inline void *sbi_malloc(size_t size)
>>>       return sbi_malloc_from(&global_hpctrl, size);
>>> }
>>> 
>>> +/** Allocate aligned from heap area */
>>> +void *sbi_memalign_from(struct sbi_heap_control *hpctrl, size_t alignment,
>>> +                       size_t size);
>>> +
>>> +static inline void *sbi_memalign(size_t alignment, size_t size)
>>> +{
>>> +       return sbi_memalign_from(&global_hpctrl, alignment, size);
>>> +}
>> 
>> The term "memalign" does not imply it is a memory allocation function.
>> 
>> I suggest the following names instead:
>> sbi_malloc_aligned_from()
>> sbi_malloc_aligned()
> 
> I took this function prototype from POSIX’s memalign, which is a standard allocation
> function. I can definitely rename this, but thought I would give my justification.
> 
> For all other comments below, agreed — I can integrate these changes. Do you want
> me to send a whole new v4 patch series (including the two earlier commits you’ve
> reviewed already)? Or send a new version of just this commit?

I would suggest instead trying to look like ISO C11’s aligned_alloc as
a broader standard function.

Jess




More information about the opensbi mailing list