Proposal for adding O_DIRECT support into JDK 9

Lu, Yingqi at
Fri Aug 26 22:31:14 UTC 2016

Dear All,

This is a proposal for adding O_DIRECT support into JDK 9 for reading/writing from/to a file on Linux platform. O_DIRECT is a file-open flag to pass to OPEN (2). It tries to minimize cache effects of the I/O to and from this file. File I/O is done directly to/from user-space buffers. Please refer to for more details.

The advantage of this feature is to provide consistent and predictable IO throughput, bypassing the influence of Linux filesystem cache. It is useful for applications which already have their own caching layers, such as databases Apache HBase and Apache Cassandra. In addition, for applications like Apache Spark shuffle phase that have random file accesses and no access locality (read the file only once from a random location), this feature also helps performance by minimizing trashing the filesystem cache.

The proposal adds 4 API methods to java/io/, java/io/ to enable the feature. In addition, it add O_DIRECT with two more modes "ro" (read-only and direct) and "rwo" (read-write and direct) to java/io/

public FileInputStream(String name, boolean direct) throws FileNotFoundException

public FileInputStream(File file, boolean direct) throws FileNotFoundException

public FileOutputStream(String name, boolean append, boolean direct) throws FileNotFoundException

public FileOutputStream(File file, boolean append, boolean direct) throws FileNotFoundException

Many database applications written in C/C++ such as MySQL and MongoDB have already used O_DIRECT for certain DB operations. Many Java based BigData applications such as Cassandra are already using it from third party library named JNA. ( Our internal version of Hadoop Distributed File System (HDFS) that has O_DIRECT enabled via JNI functions also show significant throughput improvements.

We opened a JBS ticket at and the initial version of the JDK9 patch is available at By using this patch, we saw good results up to 1.8x improvement on random read throughput on a micro workload named IOMeter with both SATA SSDs and Intel PCIeSSDs. The workload is available at

Please review the patch and let us know your feedback.

Yingqi Lu (Lucy)

More information about the core-libs-dev mailing list