Skip to content

xtensa: Use default malloc alignment of 8 #5

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Sep 10, 2021

Conversation

stephanosio
Copy link
Member

The current malloc implementation has a bug in which the first malloc
call may fail if MALLOC_ALIGNMENT is 16 and the requested block size is
such that malloc invokes sbrk with the heap expansion size that causes
the resulting heap address to fall on a page boundary.

sys/config.h was defining the minimum MALLOC_ALIGNMENT for the Xtensa
architecture as 16, and this caused the first malloc call to fail on
the Xtensa platforms in some rare cases that satisfy the conditions
described above (see zephyrproject-rtos/zephyr#38258).

Since the Xtensa architecture in itself does not require the malloc
alignment of 16, remove MALLOC_ALIGNMENT definition and use the default
alignment of 8 for all Xtensa platforms.

Signed-off-by: Stephanos Ioannidis root@stephanos.io

The current malloc implementation has a bug in which the first malloc
call may fail if MALLOC_ALIGNMENT is 16 and the requested block size is
such that malloc invokes sbrk with the heap expansion size that causes
the resulting heap address to fall on a page boundary.

sys/config.h was defining the minimum MALLOC_ALIGNMENT for the Xtensa
architecture as 16, and this caused the first malloc call to fail on
the Xtensa platforms in some rare cases that satisfy the conditions
described above (see zephyrproject-rtos/zephyr#38258).

Since the Xtensa architecture in itself does not require the malloc
alignment of 16, remove MALLOC_ALIGNMENT definition and use the default
alignment of 8 for all Xtensa platforms.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
@@ -195,7 +195,6 @@

#ifdef __XTENSA__
#include <xtensa/config/core-isa.h>
#define MALLOC_ALIGNMENT ((XCHAL_DATA_WIDTH) < 16 ? 16 : (XCHAL_DATA_WIDTH))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, looks like imx sets XCHAL_DATA_WIDTH to 16. So wonder if this should be
#define MALLOC_ALIGNMENT XCHAL_DATA_WIDTH

Guessing that will still cause issues on xtensa for i.mx?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guessing that will still cause issues on xtensa for i.mx?

@galak Yes, this issue will persist as long as MALLOC_ALIGNMENT is 16 (and maybe others except 8 too) since we are not fixing the root cause here.

While it would be nice to fix the malloc itself, I do not have bandwidth to debug and fix it at the moment.

As for the i.MX with XCHAL_DATA_WIDTH of 16, I do not think there will be any issues using the MALLOC_ALIGNMENT of 8 other than some minor performance penalties for the conventional un-optimised code.

@galak galak merged commit 2893dbb into zephyr-newlib-3.3.0 Sep 10, 2021
@stephanosio stephanosio deleted the zephyr-newlib-3.3.0-test branch March 18, 2022 16:43
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants