1*6be0ddb2SBagas Sanjaya.. SPDX-License-Identifier: GPL-2.0 2*6be0ddb2SBagas Sanjaya 3*6be0ddb2SBagas Sanjaya============== 4*6be0ddb2SBagas SanjayaFUSE I/O Modes 5*6be0ddb2SBagas Sanjaya============== 6*6be0ddb2SBagas Sanjaya 7*6be0ddb2SBagas SanjayaFuse supports the following I/O modes: 8*6be0ddb2SBagas Sanjaya 9*6be0ddb2SBagas Sanjaya- direct-io 10*6be0ddb2SBagas Sanjaya- cached 11*6be0ddb2SBagas Sanjaya + write-through 12*6be0ddb2SBagas Sanjaya + writeback-cache 13*6be0ddb2SBagas Sanjaya 14*6be0ddb2SBagas SanjayaThe direct-io mode can be selected with the FOPEN_DIRECT_IO flag in the 15*6be0ddb2SBagas SanjayaFUSE_OPEN reply. 16*6be0ddb2SBagas Sanjaya 17*6be0ddb2SBagas SanjayaIn direct-io mode the page cache is completely bypassed for reads and writes. 18*6be0ddb2SBagas SanjayaNo read-ahead takes place. Shared mmap is disabled by default. To allow shared 19*6be0ddb2SBagas Sanjayammap, the FUSE_DIRECT_IO_ALLOW_MMAP flag may be enabled in the FUSE_INIT reply. 20*6be0ddb2SBagas Sanjaya 21*6be0ddb2SBagas SanjayaIn cached mode reads may be satisfied from the page cache, and data may be 22*6be0ddb2SBagas Sanjayaread-ahead by the kernel to fill the cache. The cache is always kept consistent 23*6be0ddb2SBagas Sanjayaafter any writes to the file. All mmap modes are supported. 24*6be0ddb2SBagas Sanjaya 25*6be0ddb2SBagas SanjayaThe cached mode has two sub modes controlling how writes are handled. The 26*6be0ddb2SBagas Sanjayawrite-through mode is the default and is supported on all kernels. The 27*6be0ddb2SBagas Sanjayawriteback-cache mode may be selected by the FUSE_WRITEBACK_CACHE flag in the 28*6be0ddb2SBagas SanjayaFUSE_INIT reply. 29*6be0ddb2SBagas Sanjaya 30*6be0ddb2SBagas SanjayaIn write-through mode each write is immediately sent to userspace as one or more 31*6be0ddb2SBagas SanjayaWRITE requests, as well as updating any cached pages (and caching previously 32*6be0ddb2SBagas Sanjayauncached, but fully written pages). No READ requests are ever sent for writes, 33*6be0ddb2SBagas Sanjayaso when an uncached page is partially written, the page is discarded. 34*6be0ddb2SBagas Sanjaya 35*6be0ddb2SBagas SanjayaIn writeback-cache mode (enabled by the FUSE_WRITEBACK_CACHE flag) writes go to 36*6be0ddb2SBagas Sanjayathe cache only, which means that the write(2) syscall can often complete very 37*6be0ddb2SBagas Sanjayafast. Dirty pages are written back implicitly (background writeback or page 38*6be0ddb2SBagas Sanjayareclaim on memory pressure) or explicitly (invoked by close(2), fsync(2) and 39*6be0ddb2SBagas Sanjayawhen the last ref to the file is being released on munmap(2)). This mode 40*6be0ddb2SBagas Sanjayaassumes that all changes to the filesystem go through the FUSE kernel module 41*6be0ddb2SBagas Sanjaya(size and atime/ctime/mtime attributes are kept up-to-date by the kernel), so 42*6be0ddb2SBagas Sanjayait's generally not suitable for network filesystems. If a partial page is 43*6be0ddb2SBagas Sanjayawritten, then the page needs to be first read from userspace. This means, that 44*6be0ddb2SBagas Sanjayaeven for files opened for O_WRONLY it is possible that READ requests will be 45*6be0ddb2SBagas Sanjayagenerated by the kernel. 46