Closed Sunny-Island closed 2 years ago
@asonje Could you give me some advice about this proposal? I can contribute this part if it works.
This is an interesting proposal and we are thinking about how to support direct ByteBuffer
as a source for copying bytes to persistent memory in LLPL. Are you aware that from JDK 14 there is support for persistent MappedByteBuffer
? This means that you could write the bytes from the network directly to persistent memory via a MappedByteBuffer
. If all you need to do is store the network data in persistent memory then this is a good solution. If you need to manipulate the data with LLPL then you will need an efficient way to copy bytes from a direct ByteBuffer
to an LLPL heap.
@asonje Thank you for your reply! I have read JDK 14's support(jep-352), the best way is to use MappedByteBuffer
as buffer writing to pmem. But our project have used DirectByteBuffer
and updating JDK version seems unpossible. Are you groups working on DirectByteBuffer
supporting now?
@Sunny-Island please take a look at the copy methods added in PR #12 and let me know how it works
Ok!
I will try these methods in my project.
Hi! I just wonder why use native method to get address of DirectByteBuffer instead of DirectByteBuffer.address()? Which one can get the right address of array?
I used JNI to get the address of the DirectByteBuffer as it is the more straight forward approach and definitely gets the correct address. I have also just modified the PR to advance the buffer's position after a copyToByteBuffer.
Background: For I/O intensive java application, we usually use DirectByteBuffer to manage data flow from(to) network and file, Java.nio support using DirectBuffer and channels to avoid copy data into java heap. DirectByteBuffer is a common used byte buffer. When using pmem to accerate I/O with java application, we should avoid copying data into java heap, which will cause GC and latency. Therefore, llpl lib should support write from DirectByteBuffer to PMEM.
Details: DirectByteBuffer will hold a address(located out of Java heap), we could pass this address to PMDK copy_from_array function, and change DirectByteBuffer 's position after copy success.