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

[Java] Memory allocation alignment #36400

Open
viirya opened this issue Jun 29, 2023 · 5 comments
Open

[Java] Memory allocation alignment #36400

viirya opened this issue Jun 29, 2023 · 5 comments

Comments

@viirya
Copy link
Member

viirya commented Jun 29, 2023

Describe the bug, including details regarding any error messages, version, and platform.

We see memory alignment error when passing arrays allocated using Java arrow to Rust arrow. This is due to strict memory alignment requirement (apache/arrow-rs#4431) at Rust side. I have described the issue there.

So as it looks like it is impossible to access unaligned memory pointers at Rust side. I'm wondering if we could change Java arrow on memory allocation? Could we allocate memory with alignment for arrays in Java arrow so it could be safely sent to other arrow ecosystems?

Component(s)

Java

@lidavidm
Copy link
Member

I think it'd be possible & reasonable to (add a mode where) over-allocate by 64 bytes and then use the aligned subset of the buffer. That's what Arrow C++ actually does when using libc malloc.

I'd have to look more deeply into Netty to see what it does though.

Was your Java application using the Netty allocator or the "unsafe" allocator?

@viirya
Copy link
Member Author

viirya commented Jun 29, 2023

We use arrow-memory-unsafe so it is unsafe allocator.

@lidavidm
Copy link
Member

lidavidm commented Jul 3, 2023

CC @davisusanibar

@viirya
Copy link
Member Author

viirya commented Aug 23, 2023

Note that we will probably rely on new arrow-rs API to do re-align for unaligned buffers imported from Java Arrow. So this might be not a blocker for us anymore. But as there will be some overhead when re-aligning buffers, ideally I think it would be great if Java Arrow can do memory alignment.

@lidavidm
Copy link
Member

Ping @davisusanibar

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