MemoryMappedBuffer flushing

Bobrowski, Maciej Maciej.Bobrowski at morganstanley.com
Tue Sep 23 15:28:39 UTC 2014


Thank you very much Alan for your prompt reply. I understand that force flushes all the dirty pages, but that does not answer my question. Let me give a more verbose example:

http://psy-lob-saw.blogspot.co.uk/2013/02/alignment-concurrency-and-torture-x86.html - firstly I went through this article, which describes concurrent access to direct memory, which even for putInt/Long might not be guaranteed (even for aligned accesses). This sounds quite scary to me tbh.

Now, let's think more in the case of MappedByteBuffer and IPC. Let's assume I put 100 bytes on each call to put i.e. place 100 bytes in the memory mapped file in Process A. Given the above, do I have any guarantees, that the page synchronozation will not  happen half way through my process writing to the page, so that the underlying file will reflect an update of 50 bytes only? This is especially crucial if you assume there is another process, periodically reading in the same page and acting upon it, seeing partial write per se.

My gut feeling tells me there is no such guarantees and the O/S can synch at any point in time. So, shrinking down the window of potential disaster, does a single putInt brings any atomicity guarantees, such that O/S synch will either happen before putInt or after?

Thanks,
Maciej

From: Alan Bateman [mailto:Alan.Bateman at oracle.com]
Sent: 23 September 2014 12:51
To: Bobrowski, Maciej (ICT); nio-dev at openjdk.java.net
Subject: Re: MemoryMappedBuffer flushing

On 23/09/2014 11:02, Bobrowski, Maciej wrote:
Hi All,


Given that I am using a memory-mapped file, with an underlying O/S page sie of e.g. 4KB, are there any guarantees about when the flush (page synch) will be performed with respect to writes?

No, you'll need to use the force method to ensure that the underlying pages are written back to the file system.

-Alan


________________________________

NOTICE: Morgan Stanley is not acting as a municipal advisor and the opinions or views contained herein are not intended to be, and do not constitute, advice within the meaning of Section 975 of the Dodd-Frank Wall Street Reform and Consumer Protection Act. If you have received this communication in error, please destroy all electronic and paper copies and notify the sender immediately. Mistransmission is not intended to waive confidentiality or privilege. Morgan Stanley reserves the right, to the extent permitted under applicable law, to monitor electronic communications. This message is subject to terms available at the following link: http://www.morganstanley.com/disclaimers If you cannot access these links, please notify us by reply message and we will send the contents to you. By messaging with Morgan Stanley you consent to the foregoing.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20140923/399e4001/attachment.html>


More information about the nio-dev mailing list