Skip to content

Fix cmpctmalloc crash for large aligned allocations.#112

Merged
floitsch merged 2 commits intopatch-head-5.4.2from
floitsch/patch-head-5.4.2.cmpctmalloc
Mar 18, 2026
Merged

Fix cmpctmalloc crash for large aligned allocations.#112
floitsch merged 2 commits intopatch-head-5.4.2from
floitsch/patch-head-5.4.2.cmpctmalloc

Conversation

@floitsch
Copy link
Copy Markdown
Member

The aligned alloc path didn't check size before entering the bucket allocator. On ESP32-P4, cache alignment requirements (64 bytes) put large allocations (e.g. 32KB DMA pool) into the bucket path instead of page_alloc, causing a fatal in size_to_index_helper.

The aligned alloc path didn't check size before entering the bucket allocator.
On ESP32-P4, cache alignment requirements (64 bytes) put large allocations (e.g.
32KB DMA pool) into the bucket path instead of page_alloc, causing a fatal in
size_to_index_helper.
@floitsch floitsch requested a review from kasperl March 15, 2026 19:59
Copy link
Copy Markdown

@erikcorry erikcorry Mar 15, 2026

Choose a reason for hiding this comment

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

Just add " || size >= PAGE_SIZE / 4 * 3" here

The obvious choice of using SMALL_ALLOCATION_LIMIT has some issues because aligned allocations get rounded up a bit later and could hit the limit. This is a safe choice, but you could also copy the limit from the regular unaligned path, which is designed to avoid fragmentation.

if (size < ALMOST_FULL_PAGE ||
    (PAGE_SIZE < size && size <= PAGE_AND_A_HALF)) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done.

@floitsch floitsch merged commit ffde5ce into patch-head-5.4.2 Mar 18, 2026
1 of 2 checks passed
@floitsch floitsch deleted the floitsch/patch-head-5.4.2.cmpctmalloc branch March 18, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants