Clarification of code comments and reality in malloc.h
Hi Devs,
I've been doing some deep code diving and I seem to have found a discrepancy between code comments and reality. This difference could hint at a bug or performance degradation, but I doubt it. I thought to ask to get clarification.
In malloc.h, the comments and definition for arena_header, ARENA_PADDING and free_arena_header are:
https://github.com/geneC/syslinux/blob/2ea44cbedb297bd6b409d5c1e0402d5f89592be4/core/mem/malloc.h#L41-L74
In my environment, the size of int and pointer are both 32-bits (x86 32-bits). When compiled with DEBUG_MALLOC undefined; I get
sizeof(arena_header) == 16 sizeof(free_arena_header) == 56
Which disagrees with the comments. The comments do make a lot of sense to ensure good alignment. To make the code agree with the comments (the easier option); the definition of ARENA_PADDING needs to be altered to:
#define ARENA_PADDING (((2 * sizeof(struct arena_header)) - \
(sizeof(struct arena_header) + \
sizeof(struct free_arena_header *) + \
sizeof(struct free_arena_header *))) / sizeof(size_t))
This includes a reduction in the size of the padding by the unit size of the padding, i.e sizeof(size_t). Given that this is the memory sub-system, this small change could have a significant impact.
What are your thoughts?
Feedback most welcome, Brett