JDK-8202116 : (fc) FileChannel.map should ensure mapped region is backed by disk space
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 9,10,11
  • Priority: P2
  • Status: Resolved
  • Resolution: Won't Fix
  • OS: linux
  • Submitted: 2018-04-22
  • Updated: 2018-05-31
  • Resolved: 2018-04-26
Related Reports
Relates :  
Relates :  
Description
JDK-8168628 needs to be re-implemented so that RandomAccessFile.setLength does does allocate disk space and FileChannel.map does the correct thing to ensure that the region to be mapped is backed by disk space.

More discussion on this topic here:
http://mail.openjdk.java.net/pipermail/nio-dev/2018-April/005008.html
Comments
On further examination, preallocating the space is not a good idea. Instead the changes for JDK-8168628 should be reverted (see JDK-8202261). JDK-8191278 tracks fixing Unsafe copyMemory so that it uses memory guards. Once that is fixed then bulk operations operations on MappedByteBuffers should not SIGBUS.
26-04-2018

I have a prototype of changes for JDK 11 that uses lseek(SEEK_HOLE) to identify if there is hole in the region to be mapped. If the FileChannel is opened for write access then fallocate64 is used to allocate the disk space supporting the region before it is mapped. If opened read-only, the method will fail.
22-04-2018