1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun============== 4*4882a593SmuzhiyunFuse I/O Modes 5*4882a593Smuzhiyun============== 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunFuse supports the following I/O modes: 8*4882a593Smuzhiyun 9*4882a593Smuzhiyun- direct-io 10*4882a593Smuzhiyun- cached 11*4882a593Smuzhiyun + write-through 12*4882a593Smuzhiyun + writeback-cache 13*4882a593Smuzhiyun 14*4882a593SmuzhiyunThe direct-io mode can be selected with the FOPEN_DIRECT_IO flag in the 15*4882a593SmuzhiyunFUSE_OPEN reply. 16*4882a593Smuzhiyun 17*4882a593SmuzhiyunIn direct-io mode the page cache is completely bypassed for reads and writes. 18*4882a593SmuzhiyunNo read-ahead takes place. Shared mmap is disabled. 19*4882a593Smuzhiyun 20*4882a593SmuzhiyunIn cached mode reads may be satisfied from the page cache, and data may be 21*4882a593Smuzhiyunread-ahead by the kernel to fill the cache. The cache is always kept consistent 22*4882a593Smuzhiyunafter any writes to the file. All mmap modes are supported. 23*4882a593Smuzhiyun 24*4882a593SmuzhiyunThe cached mode has two sub modes controlling how writes are handled. The 25*4882a593Smuzhiyunwrite-through mode is the default and is supported on all kernels. The 26*4882a593Smuzhiyunwriteback-cache mode may be selected by the FUSE_WRITEBACK_CACHE flag in the 27*4882a593SmuzhiyunFUSE_INIT reply. 28*4882a593Smuzhiyun 29*4882a593SmuzhiyunIn write-through mode each write is immediately sent to userspace as one or more 30*4882a593SmuzhiyunWRITE requests, as well as updating any cached pages (and caching previously 31*4882a593Smuzhiyununcached, but fully written pages). No READ requests are ever sent for writes, 32*4882a593Smuzhiyunso when an uncached page is partially written, the page is discarded. 33*4882a593Smuzhiyun 34*4882a593SmuzhiyunIn writeback-cache mode (enabled by the FUSE_WRITEBACK_CACHE flag) writes go to 35*4882a593Smuzhiyunthe cache only, which means that the write(2) syscall can often complete very 36*4882a593Smuzhiyunfast. Dirty pages are written back implicitly (background writeback or page 37*4882a593Smuzhiyunreclaim on memory pressure) or explicitly (invoked by close(2), fsync(2) and 38*4882a593Smuzhiyunwhen the last ref to the file is being released on munmap(2)). This mode 39*4882a593Smuzhiyunassumes that all changes to the filesystem go through the FUSE kernel module 40*4882a593Smuzhiyun(size and atime/ctime/mtime attributes are kept up-to-date by the kernel), so 41*4882a593Smuzhiyunit's generally not suitable for network filesystems. If a partial page is 42*4882a593Smuzhiyunwritten, then the page needs to be first read from userspace. This means, that 43*4882a593Smuzhiyuneven for files opened for O_WRONLY it is possible that READ requests will be 44*4882a593Smuzhiyungenerated by the kernel. 45