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