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

Please madvise re: buffer alignment #197

Closed
dstuebe opened this issue Nov 18, 2019 · 1 comment
Closed

Please madvise re: buffer alignment #197

dstuebe opened this issue Nov 18, 2019 · 1 comment

Comments

@dstuebe
Copy link

dstuebe commented Nov 18, 2019

Trying to call madvise on a MappedByteBuffer via JNR-FFI.

According to the man page, both the pointer address and the size need to be page aligned but I am not sure how to do that using FFI? I can call long address = MemoryIO.getInstance().getDirectBufferAddress(buffer); but unsure how to use it in my interface to madvise how do I pass a long as a void pointer?

I can validate that my method fails if I hard code a negative size, but I am having a hard time parsing what FFI is doing to get the buffer address and whether it is already aligned the way I would do it in c?

@dstuebe
Copy link
Author

dstuebe commented Nov 19, 2019

It just works!

public interface NativeC {
    int madvise(@size_t long address, @size_t long size, int advice);
    int getpagesize();
}
...
long address = MemoryIO.getInstance().getDirectBufferAddress(buffer);
long alignedAddress = alignedAddress(address);
long alignedSize = alignedSize(alignedAddress, buffer.capacity());
int val = nativeC.madvise(alignedAddress, alignedSize, advice.value);

Will comment and close - thank you for this!

@dstuebe dstuebe closed this as completed Nov 19, 2019
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

No branches or pull requests

1 participant