deno icon indicating copy to clipboard operation
deno copied to clipboard

`Deno.open()` does not support O_DIRECT for performing Direct I/O

Open GavinRay97 opened this issue 2 years ago • 0 comments

Direct I/O is important for disabling the kernel block-cache, in the event your application manages such caching itself. Without O_DIRECT, you wind up with double-buffering.

       O_DIRECT (since Linux 2.4.10)
              Try to minimize cache effects of the I/O to and from this
              file.  In general this will degrade performance, but it is
              useful in special situations, such as when applications do
              their own caching.  File I/O is done directly to/from
              user-space buffers.  The O_DIRECT flag on its own makes an
              effort to transfer data synchronously, but does not give
              the guarantees of the O_SYNC flag that data and necessary
              metadata are transferred.  To guarantee synchronous I/O,
              O_SYNC must be used in addition to O_DIRECT.  See NOTES
              below for further discussion.

              A semantically similar (but deprecated) interface for
              block devices is described in raw(8).

I propose adding a new flag to Deno.OpenOptions, named direct.

On Linux, this should apply the O_DIRECT flag. On Windows, this should apply FILE_FLAG_WRITE_THROUGH + FILE_FLAG_NO_BUFFERING:

  • https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#caching_behavior

The flags FILE_FLAG_WRITE_THROUGH and FILE_FLAG_NO_BUFFERING are independent and may be combined.

If FILE_FLAG_WRITE_THROUGH is used but FILE_FLAG_NO_BUFFERING is not also specified, so that system caching is in effect, then the data is written to the system cache but is flushed to disk without delay.

If FILE_FLAG_WRITE_THROUGH and FILE_FLAG_NO_BUFFERING are both specified, so that system caching is not in effect, then the data is immediately flushed to disk without going through the Windows system cache. The operating system also requests a write-through of the hard disk's local hardware cache to persistent media.

GavinRay97 avatar Dec 21 '23 22:12 GavinRay97