You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
7.9 KiB

  1. # caching
  2. ## cache.files
  3. Controls how [page caching](https://en.wikipedia.org/wiki/Page_cache)
  4. works for mergerfs itself. Not the underlying filesystems.
  5. * `cache.files=off`: Disables page caching for mergerfs.
  6. * `cache.files=partial`: Enables page caching. Files are cached
  7. while open.
  8. * `cache.files=full`: Enables page caching. Files are cached across
  9. opens.
  10. * `cache.files=auto-full`: Enables page caching. Files are cached
  11. across opens if mtime and size are unchanged since previous open.
  12. * `cache.files=per-process`: Enable page caching (equivalent to
  13. `cache.files=partial`) only for processes whose 'comm' name matches
  14. one of the values defined in cache.files.process-names. If the name
  15. does not match the file open is equivalent to `cache.files=off`.
  16. Generally, enabling the page cache actually *harms*
  17. performance[^1]. In part because it can lead to buffer bloat due to
  18. the kernel caching both the underlying filesystem's file content as
  19. well as the file through mergerfs. However, if you want to confirm
  20. performance differences it is recommended that you perform some
  21. benchmark to confirm which option works best for your setup.
  22. Why then would you want to enable page caching if it consumes ~2x the
  23. RAM as normal and is on average slower? Because it is the only way to
  24. support
  25. [mmap](https://man7.org/linux/man-pages/man2/mmap.2.html). `mmap` is a
  26. way for programs to treat a file as if it is a contiguous RAM buffer
  27. which is regularly used by a number of programs such as those that
  28. leverage **sqlite3**. Despite `mmap` not being supported by all
  29. filesystems it is unfortunately common for software to not have an
  30. option to use regular file IO instead of `mmap`.
  31. The good thing is that in Linux v6.6[^2] and above FUSE can now
  32. transparently enable page caching when mmap is requested. This means
  33. it should be safe to set `cache.files=off`. However, on Linux v6.5 and
  34. below you will need to configure `cache.files` as you need.
  35. [^1]: This is not unique to mergerfs and affects all FUSE
  36. filesystems. It is something that the FUSE community hopes to
  37. investigate at some point but as of early 2025 there are a number
  38. of major reworking going on with FUSE which needs to be finished
  39. first.
  40. [^2]: [https://kernelnewbies.org/Linux_6.6#FUSE](https://kernelnewbies.org/Linux_6.6#FUSE)
  41. ## cache.entry
  42. * `cache.entry=UINT`: Sets the number of seconds to cache
  43. entry queries. Defaults to `1`.
  44. The kernel must ask mergerfs about the existence of files. The entry
  45. cache caches that those details which limits the number of requests
  46. sent to mergerfs.
  47. The risk of setting this value, as with most any cache, is related to
  48. [out-of-band](https://en.wikipedia.org/wiki/Out-of-band) changes. If
  49. the filesystems are changed outside mergerfs there is a risk of files
  50. which have been removed continuing to show as available. It will fail
  51. gracefully if a phantom file is actioned on in some way so there is
  52. little risk in setting the value much higher. Especially if there are
  53. no out-of-band changes.
  54. ## cache.negative_entry
  55. * `cache.negative_entry=UINT`: Sets the number of seconds to cache
  56. negative entry queries. Defaults to `1`.
  57. This is a cache for negative entry query responses. Such as when a
  58. file which does not exist is referenced.
  59. The risk of setting this value, as with most any cache, is related to
  60. [out-of-band](https://en.wikipedia.org/wiki/Out-of-band) changes. If
  61. the filesystems are changed outside mergerfs there is a risk of files
  62. which have been added outside mergerfs not appearing correctly till
  63. the cache entry times out if there had been a request for the same
  64. name within mergerfs which didn't exist. This is mostly an
  65. inconvenience.
  66. ## cache.attr
  67. * `cache.attr=UINT`: Sets the number of seconds to cache file
  68. attributes. Defaults to `1`.
  69. This is a cache for file attributes and metadata such as that which is
  70. collected by the
  71. [stat](https://man7.org/linux/man-pages/man2/stat.2.html) system call
  72. which is used when you run commands such as `find` or `ls -lh`.
  73. As with other caches the risk of enabling the attribute cache is if
  74. changes are made to the file out-of-band there could be
  75. inconsistencies between the actual file and the cached details which
  76. could result in different issues depending on how the data is used. If
  77. the simultaneous writing of a file from inside and outside is unlikely
  78. then you should be safe. That said any simultaneous, uncoordinated
  79. manipulation of a file can lead to unexpected results.
  80. ## cache.statfs
  81. * `cache.statfs=UINT`: Sets the number of seconds to cache `statfs`
  82. calls used by policies. Defaults to `0`.
  83. A number of policies require looking up the available space of the
  84. branches being considered. This is accomplished by calling
  85. [statfs](https://man7.org/linux/man-pages/man2/statfs.2.html). This
  86. call however is a bit expensive so this cache reduces the overhead by
  87. limiting how often the calls are actually made.
  88. This will mean that if the available space of branches changed
  89. somewhat rapidly there is a risk of `create` or `mkdir` calls made
  90. within the timeout period ending up on the same branch. This however
  91. should even itself out over time.
  92. ## cache.symlinks
  93. * `cache.symlinks=BOOL`: Enable kernel caching of symlink
  94. values. Defaults to `false`.
  95. As of Linux v4.20 there is an ability to cache the value of symlinks
  96. so that the kernel does not need to make a request to mergerfs every
  97. single time a
  98. [readlink](https://man7.org/linux/man-pages/man2/readlink.2.html)
  99. request is made. While not a common usage pattern, if software very
  100. regularly queries symlink values, the use of this cache could
  101. significantly improve performance.
  102. mergerfs will not error if the kernel used does not support symlink
  103. caching.
  104. As with other caches the main risk in enabling it is if you are
  105. manipulating symlinks from both within and without the mergerfs
  106. mount. Should the value be changed outside of mergerfs then it will
  107. not be reflected in the mergerfs mount till the cached value is
  108. invalidated.
  109. ## cache.readdir
  110. * `cache.readdir=BOOL`: Enable kernel caching of readdir
  111. results. Defaults to `false`.
  112. As of Linux v4.20 it supports readdir caching. This can have a
  113. significant impact on directory traversal. Especially when combined
  114. with entry (`cache.entry`) and attribute (`cache.attr`) caching. If
  115. the kernel doesn't support readdir caching setting the option to true
  116. has no effect. This option is configurable at runtime via xattr
  117. user.mergerfs.cache.readdir.
  118. ## cache.writeback
  119. * `cache.writeback=BOOL`: Enable writeback cache. Defaults to `false`.
  120. When `cache.files` is enabled the default is for it to perform
  121. writethrough caching. This behavior won't help improve performance as
  122. each write still goes one for one through the filesystem. By enabling
  123. the FUSE writeback cache small writes *may* be aggregated by the
  124. kernel and then sent to mergerfs as one larger request. This can
  125. greatly improve the throughput for apps which write to files
  126. inefficiently. The amount the kernel can aggregate is limited by the
  127. size of a FUSE message. Read the fuse_msg_size section for more
  128. details.
  129. There is a side effect as a result of enabling writeback
  130. caching. Underlying files won't ever be opened with O_APPEND or
  131. O_WRONLY. The former because the kernel then manages append mode and
  132. the latter because the kernel may request file data from mergerfs to
  133. populate the write cache. The O_APPEND change means that if a file is
  134. changed outside of mergerfs it could lead to corruption as the kernel
  135. won't know the end of the file has changed. That said any time you use
  136. caching you should keep from writing to the same file outside of
  137. mergerfs at the same time.
  138. Note that if an application is properly sizing writes then writeback
  139. caching will have little or no effect. It will only help with writes
  140. of sizes below the FUSE message size (128K on older kernels, 1M on
  141. newer). Even then its effectiveness might not be great. Given the side
  142. effects of enabling this feature it is recommended that its benefits
  143. be proved out with benchmarks.