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