Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

posix_memalign fails when size and alignment is large #1304

Open
Meandres opened this issue Mar 6, 2024 · 1 comment
Open

posix_memalign fails when size and alignment is large #1304

Meandres opened this issue Mar 6, 2024 · 1 comment

Comments

@Meandres
Copy link
Contributor

Meandres commented Mar 6, 2024

posix_memalign() fails at the assertion that checks if the memory is aligned when calling it with an alignment bigger than the page size and a size bigger than 2088961.
I found out about this when trying to run https://github.com/ssvb/tinymembench, which, during the latency benchmark, allocates a 64MB region aligned to 4MB.
I managed to make this allocation work by changing the continuous flag to true in https://github.com/cloudius-systems/osv/blob/master/core/mempool.cc#L1854

Of course, posix_memalign does not have this problem on Linux. It might be quite a niche problem.

@nyh
Copy link
Contributor

nyh commented Mar 6, 2024

The bug is that malloc_large() when size is bigger than mmu::huge_page_size (2MB) and contiguous is not requested, calls mapped_malloc_large(size, offset) - this completely ignores the alignment parameter, and you always get a single-page (4KB) alignment - so the assertion in posix_memalign that it got the right alignment can fail.

By the way, the same call that ignores alignment is also used at the end of malloc_large() if attempting a continugous allocation failed.

I guess the best way to fix this bug would be to add an alignment parameter (which will need to be more than one page) to map_anon, and basically to allocate() in core/mmu.cc and find_hole(). I think it's not hard, but will be a bit ugly to do all these changes for such an obscure edge case :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants