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.

2943 lines
107 KiB

8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
3 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
6 years ago
6 years ago
6 years ago
6 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
6 years ago
9 years ago
9 years ago
9 years ago
9 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
3 years ago
5 years ago
5 years ago
9 years ago
5 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
  1. .\"t
  2. .\" Automatically generated by Pandoc 2.9.2.1
  3. .\"
  4. .TH "mergerfs" "1" "" "mergerfs user manual" ""
  5. .hy
  6. .SH NAME
  7. .PP
  8. mergerfs - a featureful union filesystem
  9. .SH SYNOPSIS
  10. .PP
  11. mergerfs -o<options> <branches> <mountpoint>
  12. .SH DESCRIPTION
  13. .PP
  14. \f[B]mergerfs\f[R] is a union filesystem geared towards simplifying
  15. storage and management of files across numerous commodity storage
  16. devices.
  17. It is similar to \f[B]mhddfs\f[R], \f[B]unionfs\f[R], and
  18. \f[B]aufs\f[R].
  19. .SH FEATURES
  20. .IP \[bu] 2
  21. Configurable behaviors / file placement
  22. .IP \[bu] 2
  23. Ability to add or remove filesystems at will
  24. .IP \[bu] 2
  25. Resistance to individual filesystem failure
  26. .IP \[bu] 2
  27. Support for extended attributes (xattrs)
  28. .IP \[bu] 2
  29. Support for file attributes (chattr)
  30. .IP \[bu] 2
  31. Runtime configurable (via xattrs)
  32. .IP \[bu] 2
  33. Works with heterogeneous filesystem types
  34. .IP \[bu] 2
  35. Moving of file when filesystem runs out of space while writing
  36. .IP \[bu] 2
  37. Ignore read-only filesystems when creating files
  38. .IP \[bu] 2
  39. Turn read-only files into symlinks to underlying file
  40. .IP \[bu] 2
  41. Hard link copy-on-write / CoW
  42. .IP \[bu] 2
  43. Support for POSIX ACLs
  44. .IP \[bu] 2
  45. Misc other things
  46. .SH HOW IT WORKS
  47. .PP
  48. mergerfs logically merges multiple paths together.
  49. Think a union of sets.
  50. The file/s or directory/s acted on or presented through mergerfs are
  51. based on the policy chosen for that particular action.
  52. Read more about policies below.
  53. .IP
  54. .nf
  55. \f[C]
  56. A + B = C
  57. /disk1 /disk2 /merged
  58. | | |
  59. +-- /dir1 +-- /dir1 +-- /dir1
  60. | | | | | |
  61. | +-- file1 | +-- file2 | +-- file1
  62. | | +-- file3 | +-- file2
  63. +-- /dir2 | | +-- file3
  64. | | +-- /dir3 |
  65. | +-- file4 | +-- /dir2
  66. | +-- file5 | |
  67. +-- file6 | +-- file4
  68. |
  69. +-- /dir3
  70. | |
  71. | +-- file5
  72. |
  73. +-- file6
  74. \f[R]
  75. .fi
  76. .PP
  77. mergerfs does \f[B]not\f[R] support the copy-on-write (CoW) or whiteout
  78. behaviors found in \f[B]aufs\f[R] and \f[B]overlayfs\f[R].
  79. You can \f[B]not\f[R] mount a read-only filesystem and write to it.
  80. However, mergerfs will ignore read-only drives when creating new files
  81. so you can mix read-write and read-only drives.
  82. It also does \f[B]not\f[R] split data across drives.
  83. It is not RAID0 / striping.
  84. It is simply a union of other filesystems.
  85. .SH TERMINOLOGY
  86. .IP \[bu] 2
  87. branch: A base path used in the pool.
  88. .IP \[bu] 2
  89. pool: The mergerfs mount.
  90. The union of the branches.
  91. .IP \[bu] 2
  92. relative path: The path in the pool relative to the branch and mount.
  93. .IP \[bu] 2
  94. function: A filesystem call (open, unlink, create, getattr, rmdir, etc.)
  95. .IP \[bu] 2
  96. category: A collection of functions based on basic behavior (action,
  97. create, search).
  98. .IP \[bu] 2
  99. policy: The algorithm used to select a file when performing a function.
  100. .IP \[bu] 2
  101. path preservation: Aspect of some policies which includes checking the
  102. path for which a file would be created.
  103. .SH BASIC SETUP
  104. .PP
  105. If you don\[cq]t already know that you have a special use case then just
  106. start with one of the following option sets.
  107. .SS You need \f[C]mmap\f[R] (used by rtorrent and many sqlite3 base software)
  108. .PP
  109. \f[C]cache.files=partial,dropcacheonclose=true,category.create=mfs\f[R]
  110. .SS You don\[cq]t need \f[C]mmap\f[R]
  111. .PP
  112. \f[C]cache.files=off,dropcacheonclose=true,category.create=mfs\f[R]
  113. .SS Command Line
  114. .PP
  115. \f[C]mergerfs -o create.files=partial,dropcacheonclose=true,category.create=mfs /mnt/hdd0:/mnt/hdd1 /media\f[R]
  116. .SS /etc/fstab
  117. .PP
  118. \f[C]/mnt/hdd0:/mnt/hdd1 /media fuse.mergerfs create.files=partial,dropcacheonclose=true,category.create=mfs 0 0\f[R]
  119. .SS systemd mount
  120. .PP
  121. https://github.com/trapexit/mergerfs/wiki/systemd
  122. .IP
  123. .nf
  124. \f[C]
  125. [Unit]
  126. Description=mergerfs service
  127. [Service]
  128. Type=simple
  129. KillMode=none
  130. ExecStart=/usr/bin/mergerfs \[rs]
  131. -f \[rs]
  132. -o create.files=partial \[rs]
  133. -o dropcacheonclose=true \[rs]
  134. -o category.create=mfs \[rs]
  135. /mnt/hdd0:/mnt/hdd1 \[rs]
  136. /media
  137. ExecStop=/bin/fusermount -uz /media
  138. Restart=on-failure
  139. [Install]
  140. WantedBy=default.target
  141. \f[R]
  142. .fi
  143. .PP
  144. See the mergerfs wiki for real world
  145. deployments (https://github.com/trapexit/mergerfs/wiki/Real-World-Deployments)
  146. for comparisons / ideas.
  147. .SH OPTIONS
  148. .PP
  149. These options are the same regardless of whether you use them with the
  150. \f[C]mergerfs\f[R] commandline program, in fstab, or in a config file.
  151. .SS mount options
  152. .IP \[bu] 2
  153. \f[B]config\f[R]: Path to a config file.
  154. Same arguments as below in key=val / ini style format.
  155. .IP \[bu] 2
  156. \f[B]branches\f[R]: Colon delimited list of branches.
  157. .IP \[bu] 2
  158. \f[B]minfreespace=SIZE\f[R]: The minimum space value used for creation
  159. policies.
  160. Can be overridden by branch specific option.
  161. Understands `K', `M', and `G' to represent kilobyte, megabyte, and
  162. gigabyte respectively.
  163. (default: 4G)
  164. .IP \[bu] 2
  165. \f[B]moveonenospc=BOOL|POLICY\f[R]: When enabled if a \f[B]write\f[R]
  166. fails with \f[B]ENOSPC\f[R] (no space left on device) or
  167. \f[B]EDQUOT\f[R] (disk quota exceeded) the policy selected will run to
  168. find a new location for the file.
  169. An attempt to move the file to that branch will occur (keeping all
  170. metadata possible) and if successful the original is unlinked and the
  171. write retried.
  172. (default: false, true = mfs)
  173. .IP \[bu] 2
  174. \f[B]inodecalc=passthrough|path-hash|devino-hash|hybrid-hash\f[R]:
  175. Selects the inode calculation algorithm.
  176. (default: hybrid-hash)
  177. .IP \[bu] 2
  178. \f[B]dropcacheonclose=BOOL\f[R]: When a file is requested to be closed
  179. call \f[C]posix_fadvise\f[R] on it first to instruct the kernel that we
  180. no longer need the data and it can drop its cache.
  181. Recommended when
  182. \f[B]cache.files=partial|full|auto-full|per-process\f[R] to limit double
  183. caching.
  184. (default: false)
  185. .IP \[bu] 2
  186. \f[B]symlinkify=BOOL\f[R]: When enabled and a file is not writable and
  187. its mtime or ctime is older than \f[B]symlinkify_timeout\f[R] files will
  188. be reported as symlinks to the original files.
  189. Please read more below before using.
  190. (default: false)
  191. .IP \[bu] 2
  192. \f[B]symlinkify_timeout=UINT\f[R]: Time to wait, in seconds, to activate
  193. the \f[B]symlinkify\f[R] behavior.
  194. (default: 3600)
  195. .IP \[bu] 2
  196. \f[B]nullrw=BOOL\f[R]: Turns reads and writes into no-ops.
  197. The request will succeed but do nothing.
  198. Useful for benchmarking mergerfs.
  199. (default: false)
  200. .IP \[bu] 2
  201. \f[B]lazy-umount-mountpoint=BOOL\f[R]: mergerfs will attempt to
  202. \[lq]lazy umount\[rq] the mountpoint before mounting itself.
  203. Useful when performing live upgrades of mergerfs.
  204. (default: false)
  205. .IP \[bu] 2
  206. \f[B]ignorepponrename=BOOL\f[R]: Ignore path preserving on rename.
  207. Typically rename and link act differently depending on the policy of
  208. \f[C]create\f[R] (read below).
  209. Enabling this will cause rename and link to always use the non-path
  210. preserving behavior.
  211. This means files, when renamed or linked, will stay on the same drive.
  212. (default: false)
  213. .IP \[bu] 2
  214. \f[B]security_capability=BOOL\f[R]: If false return ENOATTR when xattr
  215. security.capability is queried.
  216. (default: true)
  217. .IP \[bu] 2
  218. \f[B]xattr=passthrough|noattr|nosys\f[R]: Runtime control of xattrs.
  219. Default is to passthrough xattr requests.
  220. `noattr' will short circuit as if nothing exists.
  221. `nosys' will respond with ENOSYS as if xattrs are not supported or
  222. disabled.
  223. (default: passthrough)
  224. .IP \[bu] 2
  225. \f[B]link_cow=BOOL\f[R]: When enabled if a regular file is opened which
  226. has a link count > 1 it will copy the file to a temporary file and
  227. rename over the original.
  228. Breaking the link and providing a basic copy-on-write function similar
  229. to cow-shell.
  230. (default: false)
  231. .IP \[bu] 2
  232. \f[B]statfs=base|full\f[R]: Controls how statfs works.
  233. `base' means it will always use all branches in statfs calculations.
  234. `full' is in effect path preserving and only includes drives where the
  235. path exists.
  236. (default: base)
  237. .IP \[bu] 2
  238. \f[B]statfs_ignore=none|ro|nc\f[R]: `ro' will cause statfs calculations
  239. to ignore available space for branches mounted or tagged as `read-only'
  240. or `no create'.
  241. `nc' will ignore available space for branches tagged as `no create'.
  242. (default: none)
  243. .IP \[bu] 2
  244. \f[B]nfsopenhack=off|git|all\f[R]: A workaround for exporting mergerfs
  245. over NFS where there are issues with creating files for write while
  246. setting the mode to read-only.
  247. (default: off)
  248. .IP \[bu] 2
  249. \f[B]branches-mount-timeout=UINT\f[R]: Number of seconds to wait at
  250. startup for branches to be a mount other than the mountpoint\[cq]s
  251. filesystem.
  252. (default: 0)
  253. .IP \[bu] 2
  254. \f[B]follow-symlinks=never|directory|regular|all\f[R]: Turns symlinks
  255. into what they point to.
  256. (default: never)
  257. .IP \[bu] 2
  258. \f[B]link-exdev=passthrough|rel-symlink|abs-base-symlink|abs-pool-symlink\f[R]:
  259. When a link fails with EXDEV optionally create a symlink to the file
  260. instead.
  261. .IP \[bu] 2
  262. \f[B]rename-exdev=passthrough|rel-symlink|abs-symlink\f[R]: When a
  263. rename fails with EXDEV optionally move the file to a special directory
  264. and symlink to it.
  265. .IP \[bu] 2
  266. \f[B]posix_acl=BOOL\f[R]: Enable POSIX ACL support (if supported by
  267. kernel and underlying filesystem).
  268. (default: false)
  269. .IP \[bu] 2
  270. \f[B]async_read=BOOL\f[R]: Perform reads asynchronously.
  271. If disabled or unavailable the kernel will ensure there is at most one
  272. pending read request per file handle and will attempt to order requests
  273. by offset.
  274. (default: true)
  275. .IP \[bu] 2
  276. \f[B]fuse_msg_size=UINT\f[R]: Set the max number of pages per FUSE
  277. message.
  278. Only available on Linux >= 4.20 and ignored otherwise.
  279. (min: 1; max: 256; default: 256)
  280. .IP \[bu] 2
  281. \f[B]threads=INT\f[R]: Number of threads to use.
  282. When used alone (\f[C]process-thread-count=-1\f[R]) it sets the number
  283. of threads reading and processing FUSE messages.
  284. When used together it sets the number of threads reading from FUSE.
  285. When set to zero it will attempt to discover and use the number of
  286. logical cores.
  287. If the thread count is set negative it will look up the number of cores
  288. then divide by the absolute value.
  289. ie.
  290. threads=-2 on an 8 core machine will result in 8 / 2 = 4 threads.
  291. There will always be at least 1 thread.
  292. If set to -1 in combination with \f[C]process-thread-count\f[R] then it
  293. will try to pick reasonable values based on CPU thread count.
  294. NOTE: higher number of threads increases parallelism but usually
  295. decreases throughput.
  296. (default: 0)
  297. .IP \[bu] 2
  298. \f[B]read-thread-count=INT\f[R]: Alias for \f[C]threads\f[R].
  299. .IP \[bu] 2
  300. \f[B]process-thread-count=INT\f[R]: Enables separate thread pool to
  301. asynchronously process FUSE requests.
  302. In this mode \f[C]read-thread-count\f[R] refers to the number of threads
  303. reading FUSE messages which are dispatched to process threads.
  304. -1 means disabled otherwise acts like \f[C]read-thread-count\f[R].
  305. (default: -1)
  306. .IP \[bu] 2
  307. \f[B]pin-threads=STR\f[R]: Selects a strategy to pin threads to CPUs
  308. (default: unset)
  309. .IP \[bu] 2
  310. \f[B]scheduling-priority=INT\f[R]: Set mergerfs\[cq] scheduling
  311. priority.
  312. Valid values range from -20 to 19.
  313. See \f[C]setpriority\f[R] man page for more details.
  314. (default: -10)
  315. .IP \[bu] 2
  316. \f[B]fsname=STR\f[R]: Sets the name of the filesystem as seen in
  317. \f[B]mount\f[R], \f[B]df\f[R], etc.
  318. Defaults to a list of the source paths concatenated together with the
  319. longest common prefix removed.
  320. .IP \[bu] 2
  321. \f[B]func.FUNC=POLICY\f[R]: Sets the specific FUSE function\[cq]s
  322. policy.
  323. See below for the list of value types.
  324. Example: \f[B]func.getattr=newest\f[R]
  325. .IP \[bu] 2
  326. \f[B]category.action=POLICY\f[R]: Sets policy of all FUSE functions in
  327. the action category.
  328. (default: epall)
  329. .IP \[bu] 2
  330. \f[B]category.create=POLICY\f[R]: Sets policy of all FUSE functions in
  331. the create category.
  332. (default: epmfs)
  333. .IP \[bu] 2
  334. \f[B]category.search=POLICY\f[R]: Sets policy of all FUSE functions in
  335. the search category.
  336. (default: ff)
  337. .IP \[bu] 2
  338. \f[B]cache.open=UINT\f[R]: `open' policy cache timeout in seconds.
  339. (default: 0)
  340. .IP \[bu] 2
  341. \f[B]cache.statfs=UINT\f[R]: `statfs' cache timeout in seconds.
  342. (default:
  343. .RS 2
  344. .RE
  345. .IP \[bu] 2
  346. \f[B]cache.attr=UINT\f[R]: File attribute cache timeout in seconds.
  347. (default: 1)
  348. .IP \[bu] 2
  349. \f[B]cache.entry=UINT\f[R]: File name lookup cache timeout in seconds.
  350. (default: 1)
  351. .IP \[bu] 2
  352. \f[B]cache.negative_entry=UINT\f[R]: Negative file name lookup cache
  353. timeout in seconds.
  354. (default: 0)
  355. .IP \[bu] 2
  356. \f[B]cache.files=libfuse|off|partial|full|auto-full|per-process\f[R]:
  357. File page caching mode (default: libfuse)
  358. .IP \[bu] 2
  359. \f[B]cache.files.process-names=LIST\f[R]: A pipe | delimited list of
  360. process comm (https://man7.org/linux/man-pages/man5/proc.5.html) names
  361. to enable page caching for when \f[C]cache.files=per-process\f[R].
  362. (default: \[lq]rtorrent|qbittorrent-nox\[rq])
  363. .IP \[bu] 2
  364. \f[B]cache.writeback=BOOL\f[R]: Enable kernel writeback caching
  365. (default: false)
  366. .IP \[bu] 2
  367. \f[B]cache.symlinks=BOOL\f[R]: Cache symlinks (if supported by kernel)
  368. (default: false)
  369. .IP \[bu] 2
  370. \f[B]cache.readdir=BOOL\f[R]: Cache readdir (if supported by kernel)
  371. (default: false)
  372. .IP \[bu] 2
  373. \f[B]direct_io\f[R]: deprecated - Bypass page cache.
  374. Use \f[C]cache.files=off\f[R] instead.
  375. (default: false)
  376. .IP \[bu] 2
  377. \f[B]kernel_cache\f[R]: deprecated - Do not invalidate data cache on
  378. file open.
  379. Use \f[C]cache.files=full\f[R] instead.
  380. (default: false)
  381. .IP \[bu] 2
  382. \f[B]auto_cache\f[R]: deprecated - Invalidate data cache if file mtime
  383. or size change.
  384. Use \f[C]cache.files=auto-full\f[R] instead.
  385. (default: false)
  386. .IP \[bu] 2
  387. \f[B]async_read\f[R]: deprecated - Perform reads asynchronously.
  388. Use \f[C]async_read=true\f[R] instead.
  389. .IP \[bu] 2
  390. \f[B]sync_read\f[R]: deprecated - Perform reads synchronously.
  391. Use \f[C]async_read=false\f[R] instead.
  392. .IP \[bu] 2
  393. \f[B]use_ino\f[R]: deprecated - Always enabled.
  394. .IP \[bu] 2
  395. \f[B]allow_other\f[R]: deprecated - Always enabled.
  396. .IP \[bu] 2
  397. \f[B]splice_read\f[R]: deprecated - Does nothing.
  398. .IP \[bu] 2
  399. \f[B]splice_write\f[R]: deprecated - Does nothing.
  400. .IP \[bu] 2
  401. \f[B]splice_move\f[R]: deprecated - Does nothing.
  402. .IP \[bu] 2
  403. \f[B]allow_other\f[R]: deprecated - mergerfs always sets this FUSE
  404. option as normal permissions can be used to limit access.
  405. .IP \[bu] 2
  406. \f[B]use_ino\f[R]: deprecated - mergerfs should always control inode
  407. calculation so this is enabled all the time.
  408. .PP
  409. \f[B]NOTE:\f[R] Options are evaluated in the order listed so if the
  410. options are \f[B]func.rmdir=rand,category.action=ff\f[R] the
  411. \f[B]action\f[R] category setting will override the \f[B]rmdir\f[R]
  412. setting.
  413. .PP
  414. \f[B]NOTE:\f[R] Always look at the documentation for the version of
  415. mergerfs you\[cq]re using.
  416. Not all features are available in older releases.
  417. Use \f[C]man mergerfs\f[R] or find the docs as linked in the release.
  418. .SS Value Types
  419. .IP \[bu] 2
  420. BOOL = `true' | `false'
  421. .IP \[bu] 2
  422. INT = [MIN_INT,MAX_INT]
  423. .IP \[bu] 2
  424. UINT = [0,MAX_INT]
  425. .IP \[bu] 2
  426. SIZE = `NNM'; NN = INT, M = `K' | `M' | `G' | `T'
  427. .IP \[bu] 2
  428. STR = string (may refer to an enumerated value, see details of argument)
  429. .IP \[bu] 2
  430. FUNC = filesystem function
  431. .IP \[bu] 2
  432. CATEGORY = function category
  433. .IP \[bu] 2
  434. POLICY = mergerfs function policy
  435. .SS branches
  436. .PP
  437. The `branches' argument is a colon (`:') delimited list of paths to be
  438. pooled together.
  439. It does not matter if the paths are on the same or different drives nor
  440. does it matter the filesystem (within reason).
  441. Used and available space will not be duplicated for paths on the same
  442. device and any features which aren\[cq]t supported by the underlying
  443. filesystem (such as file attributes or extended attributes) will return
  444. the appropriate errors.
  445. .PP
  446. Branches currently have two options which can be set.
  447. A type which impacts whether or not the branch is included in a policy
  448. calculation and a individual minfreespace value.
  449. The values are set by prepending an \f[C]=\f[R] at the end of a branch
  450. designation and using commas as delimiters.
  451. Example: /mnt/drive=RW,1234
  452. .SS branch mode
  453. .IP \[bu] 2
  454. RW: (read/write) - Default behavior.
  455. Will be eligible in all policy categories.
  456. .IP \[bu] 2
  457. RO: (read-only) - Will be excluded from \f[C]create\f[R] and
  458. \f[C]action\f[R] policies.
  459. Same as a read-only mounted filesystem would be (though faster to
  460. process).
  461. .IP \[bu] 2
  462. NC: (no-create) - Will be excluded from \f[C]create\f[R] policies.
  463. You can\[cq]t create on that branch but you can change or delete.
  464. .SS minfreespace
  465. .PP
  466. Same purpose and syntax as the global option but specific to the branch.
  467. If not set the global value is used.
  468. .SS globbing
  469. .PP
  470. To make it easier to include multiple branches mergerfs supports
  471. globbing (http://linux.die.net/man/7/glob).
  472. \f[B]The globbing tokens MUST be escaped when using via the shell else
  473. the shell itself will apply the glob itself.\f[R]
  474. .IP
  475. .nf
  476. \f[C]
  477. # mergerfs /mnt/hdd\[rs]*:/mnt/ssd /media
  478. \f[R]
  479. .fi
  480. .PP
  481. The above line will use all mount points in /mnt prefixed with
  482. \f[B]hdd\f[R] and \f[B]ssd\f[R].
  483. .PP
  484. To have the pool mounted at boot or otherwise accessible from related
  485. tools use \f[B]/etc/fstab\f[R].
  486. .IP
  487. .nf
  488. \f[C]
  489. # <file system> <mount point> <type> <options> <dump> <pass>
  490. /mnt/hdd*:/mnt/ssd /media fuse.mergerfs minfreespace=16G 0 0
  491. \f[R]
  492. .fi
  493. .PP
  494. \f[B]NOTE:\f[R] the globbing is done at mount or when updated using the
  495. runtime API.
  496. If a new directory is added matching the glob after the fact it will not
  497. be automatically included.
  498. .PP
  499. \f[B]NOTE:\f[R] for mounting via \f[B]fstab\f[R] to work you must have
  500. \f[B]mount.fuse\f[R] installed.
  501. For Ubuntu/Debian it is included in the \f[B]fuse\f[R] package.
  502. .SS inodecalc
  503. .PP
  504. Inodes (st_ino) are unique identifiers within a filesystem.
  505. Each mounted filesystem has device ID (st_dev) as well and together they
  506. can uniquely identify a file on the whole of the system.
  507. Entries on the same device with the same inode are in fact references to
  508. the same underlying file.
  509. It is a many to one relationship between names and an inode.
  510. Directories, however, do not have multiple links on most systems due to
  511. the complexity they add.
  512. .PP
  513. FUSE allows the server (mergerfs) to set inode values but not device
  514. IDs.
  515. Creating an inode value is somewhat complex in mergerfs\[cq] case as
  516. files aren\[cq]t really in its control.
  517. If a policy changes what directory or file is to be selected or
  518. something changes out of band it becomes unclear what value should be
  519. used.
  520. Most software does not to care what the values are but those that do
  521. often break if a value changes unexpectedly.
  522. The tool \f[C]find\f[R] will abort a directory walk if it sees a
  523. directory inode change.
  524. NFS will return stale handle errors if the inode changes out of band.
  525. File dedup tools will usually leverage device ids and inodes as a
  526. shortcut in searching for duplicate files and would resort to full file
  527. comparisons should it find different inode values.
  528. .PP
  529. mergerfs offers multiple ways to calculate the inode in hopes of
  530. covering different usecases.
  531. .IP \[bu] 2
  532. passthrough: Passes through the underlying inode value.
  533. Mostly intended for testing as using this does not address any of the
  534. problems mentioned above and could confuse file deduplication software
  535. as inodes from different filesystems can be the same.
  536. .IP \[bu] 2
  537. path-hash: Hashes the relative path of the entry in question.
  538. The underlying file\[cq]s values are completely ignored.
  539. This means the inode value will always be the same for that file path.
  540. This is useful when using NFS and you make changes out of band such as
  541. copy data between branches.
  542. This also means that entries that do point to the same file will not be
  543. recognizable via inodes.
  544. That \f[B]does not\f[R] mean hard links don\[cq]t work.
  545. They will.
  546. .IP \[bu] 2
  547. path-hash32: 32bit version of path-hash.
  548. .IP \[bu] 2
  549. devino-hash: Hashes the device id and inode of the underlying entry.
  550. This won\[cq]t prevent issues with NFS should the policy pick a
  551. different file or files move out of band but will present the same inode
  552. for underlying files that do too.
  553. .IP \[bu] 2
  554. devino-hash32: 32bit version of devino-hash.
  555. .IP \[bu] 2
  556. hybrid-hash: Performs \f[C]path-hash\f[R] on directories and
  557. \f[C]devino-hash\f[R] on other file types.
  558. Since directories can\[cq]t have hard links the static value won\[cq]t
  559. make a difference and the files will get values useful for finding
  560. duplicates.
  561. Probably the best to use if not using NFS.
  562. As such it is the default.
  563. .IP \[bu] 2
  564. hybrid-hash32: 32bit version of hybrid-hash.
  565. .PP
  566. 32bit versions are provided as there is some software which does not
  567. handle 64bit inodes well.
  568. .PP
  569. While there is a risk of hash collision in tests of a couple million
  570. entries there were zero collisions.
  571. Unlike a typical filesystem FUSE filesystems can reuse inodes and not
  572. refer to the same entry.
  573. The internal identifier used to reference a file in FUSE is different
  574. from the inode value presented.
  575. The former is the \f[C]nodeid\f[R] and is actually a tuple of 2 64bit
  576. values: \f[C]nodeid\f[R] and \f[C]generation\f[R].
  577. This tuple is not client facing.
  578. The inode that is presented to the client is passed through the kernel
  579. uninterpreted.
  580. .PP
  581. From FUSE docs for \f[C]use_ino\f[R]:
  582. .IP
  583. .nf
  584. \f[C]
  585. Honor the st_ino field in the functions getattr() and
  586. fill_dir(). This value is used to fill in the st_ino field
  587. in the stat(2), lstat(2), fstat(2) functions and the d_ino
  588. field in the readdir(2) function. The filesystem does not
  589. have to guarantee uniqueness, however some applications
  590. rely on this value being unique for the whole filesystem.
  591. Note that this does *not* affect the inode that libfuse
  592. and the kernel use internally (also called the \[dq]nodeid\[dq]).
  593. \f[R]
  594. .fi
  595. .PP
  596. As of version 2.35.0 the \f[C]use_ino\f[R] option has been removed.
  597. mergerfs should always be managing inode values.
  598. .SS pin-threads
  599. .PP
  600. Simple strategies for pinning read and/or process threads.
  601. If process threads are not enabled than the strategy simply works on the
  602. read threads.
  603. Invalid values are ignored.
  604. .IP \[bu] 2
  605. R1L: All read threads pinned to a single logical CPU.
  606. .IP \[bu] 2
  607. R1P: All read threads pinned to a single physical CPU.
  608. .IP \[bu] 2
  609. RP1L: All read and process threads pinned to a single logical CPU.
  610. .IP \[bu] 2
  611. RP1P: All read and process threads pinned to a single physical CPU.
  612. .IP \[bu] 2
  613. R1LP1L: All read threads pinned to a single logical CPU, all process
  614. threads pinned to a (if possible) different logical CPU.
  615. .IP \[bu] 2
  616. R1PP1P: All read threads pinned to a single physical CPU, all process
  617. threads pinned to a (if possible) different logical CPU.
  618. .IP \[bu] 2
  619. RPSL: All read and process threads are spread across all logical CPUs.
  620. .IP \[bu] 2
  621. RPSP: All read and process threads are spread across all physical CPUs.
  622. .IP \[bu] 2
  623. R1PPSP: All read threads are pinned to a single physical CPU while
  624. process threads are spread across all other phsycial CPUs.
  625. .SS fuse_msg_size
  626. .PP
  627. FUSE applications communicate with the kernel over a special character
  628. device: \f[C]/dev/fuse\f[R].
  629. A large portion of the overhead associated with FUSE is the cost of
  630. going back and forth from user space and kernel space over that device.
  631. Generally speaking the fewer trips needed the better the performance
  632. will be.
  633. Reducing the number of trips can be done a number of ways.
  634. Kernel level caching and increasing message sizes being two significant
  635. ones.
  636. When it comes to reads and writes if the message size is doubled the
  637. number of trips are approximately halved.
  638. .PP
  639. In Linux 4.20 a new feature was added allowing the negotiation of the
  640. max message size.
  641. Since the size is in multiples of
  642. pages (https://en.wikipedia.org/wiki/Page_(computer_memory)) the feature
  643. is called \f[C]max_pages\f[R].
  644. There is a maximum \f[C]max_pages\f[R] value of 256 (1MiB) and minimum
  645. of 1 (4KiB).
  646. The default used by Linux >=4.20, and hardcoded value used before 4.20,
  647. is 32 (128KiB).
  648. In mergerfs its referred to as \f[C]fuse_msg_size\f[R] to make it clear
  649. what it impacts and provide some abstraction.
  650. .PP
  651. Since there should be no downsides to increasing \f[C]fuse_msg_size\f[R]
  652. / \f[C]max_pages\f[R], outside a minor bump in RAM usage due to larger
  653. message buffers, mergerfs defaults the value to 256.
  654. On kernels before 4.20 the value has no effect.
  655. The reason the value is configurable is to enable experimentation and
  656. benchmarking.
  657. See the BENCHMARKING section for examples.
  658. .SS follow-symlinks
  659. .PP
  660. This feature, when enabled, will cause symlinks to be interpreted by
  661. mergerfs as their target (depending on the mode).
  662. .PP
  663. When there is a getattr/stat request for a file mergerfs will check if
  664. the file is a symlink and depending on the \f[C]follow-symlinks\f[R]
  665. setting will replace the information about the symlink with that of that
  666. which it points to.
  667. .PP
  668. When unlink\[cq]ing or rmdir\[cq]ing the followed symlink it will remove
  669. the symlink itself and not that which it points to.
  670. .IP \[bu] 2
  671. never: Behave as normal.
  672. Symlinks are treated as such.
  673. .IP \[bu] 2
  674. directory: Resolve symlinks only which point to directories.
  675. .IP \[bu] 2
  676. regular: Resolve symlinks only which point to regular files.
  677. .IP \[bu] 2
  678. all: Resolve all symlinks to that which they point to.
  679. .PP
  680. Symlinks which do not point to anything are left as is.
  681. .PP
  682. WARNING: This feature works but there might be edge cases yet found.
  683. If you find any odd behaviors please file a ticket on
  684. github (https://github.com/trapexit/mergerfs/issues).
  685. .SS link-exdev
  686. .PP
  687. If using path preservation and a \f[C]link\f[R] fails with EXDEV make a
  688. call to \f[C]symlink\f[R] where the \f[C]target\f[R] is the
  689. \f[C]oldlink\f[R] and the \f[C]linkpath\f[R] is the \f[C]newpath\f[R].
  690. The \f[C]target\f[R] value is determined by the value of
  691. \f[C]link-exdev\f[R].
  692. .IP \[bu] 2
  693. passthrough: Return EXDEV as normal.
  694. .IP \[bu] 2
  695. rel-symlink: A relative path from the \f[C]newpath\f[R].
  696. .IP \[bu] 2
  697. abs-base-symlink: A absolute value using the underlying branch.
  698. .IP \[bu] 2
  699. abs-pool-symlink: A absolute value using the mergerfs mount point.
  700. .PP
  701. NOTE: It is possible that some applications check the file they link.
  702. In those cases it is possible it will error or complain.
  703. .SS rename-exdev
  704. .PP
  705. If using path preservation and a \f[C]rename\f[R] fails with EXDEV:
  706. .IP "1." 3
  707. Move file from \f[B]/branch/a/b/c\f[R] to
  708. \f[B]/branch/.mergerfs_rename_exdev/a/b/c\f[R].
  709. .IP "2." 3
  710. symlink the rename\[cq]s \f[C]newpath\f[R] to the moved file.
  711. .PP
  712. The \f[C]target\f[R] value is determined by the value of
  713. \f[C]rename-exdev\f[R].
  714. .IP \[bu] 2
  715. passthrough: Return EXDEV as normal.
  716. .IP \[bu] 2
  717. rel-symlink: A relative path from the \f[C]newpath\f[R].
  718. .IP \[bu] 2
  719. abs-symlink: A absolute value using the mergerfs mount point.
  720. .PP
  721. NOTE: It is possible that some applications check the file they rename.
  722. In those cases it is possible it will error or complain.
  723. .PP
  724. NOTE: The reason \f[C]abs-symlink\f[R] is not split into two like
  725. \f[C]link-exdev\f[R] is due to the complexities in managing absolute
  726. base symlinks when multiple \f[C]oldpaths\f[R] exist.
  727. .SS symlinkify
  728. .PP
  729. Due to the levels of indirection introduced by mergerfs and the
  730. underlying technology FUSE there can be varying levels of performance
  731. degradation.
  732. This feature will turn non-directories which are not writable into
  733. symlinks to the original file found by the \f[C]readlink\f[R] policy
  734. after the mtime and ctime are older than the timeout.
  735. .PP
  736. \f[B]WARNING:\f[R] The current implementation has a known issue in which
  737. if the file is open and being used when the file is converted to a
  738. symlink then the application which has that file open will receive an
  739. error when using it.
  740. This is unlikely to occur in practice but is something to keep in mind.
  741. .PP
  742. \f[B]WARNING:\f[R] Some backup solutions, such as CrashPlan, do not
  743. backup the target of a symlink.
  744. If using this feature it will be necessary to point any backup software
  745. to the original drives or configure the software to follow symlinks if
  746. such an option is available.
  747. Alternatively create two mounts.
  748. One for backup and one for general consumption.
  749. .SS nullrw
  750. .PP
  751. Due to how FUSE works there is an overhead to all requests made to a
  752. FUSE filesystem that wouldn\[cq]t exist for an in kernel one.
  753. Meaning that even a simple passthrough will have some slowdown.
  754. However, generally the overhead is minimal in comparison to the cost of
  755. the underlying I/O.
  756. By disabling the underlying I/O we can test the theoretical performance
  757. boundaries.
  758. .PP
  759. By enabling \f[C]nullrw\f[R] mergerfs will work as it always does
  760. \f[B]except\f[R] that all reads and writes will be no-ops.
  761. A write will succeed (the size of the write will be returned as if it
  762. were successful) but mergerfs does nothing with the data it was given.
  763. Similarly a read will return the size requested but won\[cq]t touch the
  764. buffer.
  765. .PP
  766. See the BENCHMARKING section for suggestions on how to test.
  767. .SS xattr
  768. .PP
  769. Runtime extended attribute support can be managed via the
  770. \f[C]xattr\f[R] option.
  771. By default it will passthrough any xattr calls.
  772. Given xattr support is rarely used and can have significant performance
  773. implications mergerfs allows it to be disabled at runtime.
  774. The performance problems mostly comes when file caching is enabled.
  775. The kernel will send a \f[C]getxattr\f[R] for
  776. \f[C]security.capability\f[R] \f[I]before every single write\f[R].
  777. It doesn\[cq]t cache the responses to any \f[C]getxattr\f[R].
  778. This might be addressed in the future but for now mergerfs can really
  779. only offer the following workarounds.
  780. .PP
  781. \f[C]noattr\f[R] will cause mergerfs to short circuit all xattr calls
  782. and return ENOATTR where appropriate.
  783. mergerfs still gets all the requests but they will not be forwarded on
  784. to the underlying filesystems.
  785. The runtime control will still function in this mode.
  786. .PP
  787. \f[C]nosys\f[R] will cause mergerfs to return ENOSYS for any xattr call.
  788. The difference with \f[C]noattr\f[R] is that the kernel will cache this
  789. fact and itself short circuit future calls.
  790. This is more efficient than \f[C]noattr\f[R] but will cause
  791. mergerfs\[cq] runtime control via the hidden file to stop working.
  792. .SS nfsopenhack
  793. .PP
  794. NFS is not fully POSIX compliant and historically certain behaviors,
  795. such as opening files with O_EXCL, are not or not well supported.
  796. When mergerfs (or any FUSE filesystem) is exported over NFS some of
  797. these issues come up due to how NFS and FUSE interact.
  798. .PP
  799. This hack addresses the issue where the creation of a file with a
  800. read-only mode but with a read/write or write only flag.
  801. Normally this is perfectly valid but NFS chops the one open call into
  802. multiple calls.
  803. Exactly how it is translated depends on the configuration and versions
  804. of the NFS server and clients but it results in a permission error
  805. because a normal user is not allowed to open a read-only file as
  806. writable.
  807. .PP
  808. Even though it\[cq]s a more niche situation this hack breaks normal
  809. security and behavior and as such is \f[C]off\f[R] by default.
  810. If set to \f[C]git\f[R] it will only perform the hack when the path in
  811. question includes \f[C]/.git/\f[R].
  812. \f[C]all\f[R] will result it applying anytime a readonly file which is
  813. empty is opened for writing.
  814. .SH FUNCTIONS, CATEGORIES and POLICIES
  815. .PP
  816. The POSIX filesystem API is made up of a number of functions.
  817. \f[B]creat\f[R], \f[B]stat\f[R], \f[B]chown\f[R], etc.
  818. For ease of configuration in mergerfs most of the core functions are
  819. grouped into 3 categories: \f[B]action\f[R], \f[B]create\f[R], and
  820. \f[B]search\f[R].
  821. These functions and categories can be assigned a policy which dictates
  822. which branch is chosen when performing that function.
  823. .PP
  824. Some functions, listed in the category \f[C]N/A\f[R] below, can not be
  825. assigned the normal policies.
  826. These functions work with file handles, rather than file paths, which
  827. were created by \f[C]open\f[R] or \f[C]create\f[R].
  828. That said many times the current FUSE kernel driver will not always
  829. provide the file handle when a client calls \f[C]fgetattr\f[R],
  830. \f[C]fchown\f[R], \f[C]fchmod\f[R], \f[C]futimens\f[R],
  831. \f[C]ftruncate\f[R], etc.
  832. This means it will call the regular, path based, versions.
  833. \f[C]readdir\f[R] has no real need for a policy given the purpose is
  834. merely to return a list of entries in a directory.
  835. \f[C]statfs\f[R]\[cq]s behavior can be modified via other options.
  836. .PP
  837. When using policies which are based on a branch\[cq]s available space
  838. the base path provided is used.
  839. Not the full path to the file in question.
  840. Meaning that mounts in the branch won\[cq]t be considered in the space
  841. calculations.
  842. The reason is that it doesn\[cq]t really work for non-path preserving
  843. policies and can lead to non-obvious behaviors.
  844. .PP
  845. NOTE: While any policy can be assigned to a function or category though
  846. some may not be very useful in practice.
  847. For instance: \f[B]rand\f[R] (random) may be useful for file creation
  848. (create) but could lead to very odd behavior if used for \f[C]chmod\f[R]
  849. if there were more than one copy of the file.
  850. .SS Functions and their Category classifications
  851. .PP
  852. .TS
  853. tab(@);
  854. lw(7.4n) lw(62.6n).
  855. T{
  856. Category
  857. T}@T{
  858. FUSE Functions
  859. T}
  860. _
  861. T{
  862. action
  863. T}@T{
  864. chmod, chown, link, removexattr, rename, rmdir, setxattr, truncate,
  865. unlink, utimens
  866. T}
  867. T{
  868. create
  869. T}@T{
  870. create, mkdir, mknod, symlink
  871. T}
  872. T{
  873. search
  874. T}@T{
  875. access, getattr, getxattr, ioctl (directories), listxattr, open,
  876. readlink
  877. T}
  878. T{
  879. N/A
  880. T}@T{
  881. fchmod, fchown, futimens, ftruncate, fallocate, fgetattr, fsync, ioctl
  882. (files), read, readdir, release, statfs, write, copy_file_range
  883. T}
  884. .TE
  885. .PP
  886. In cases where something may be searched for (such as a path to clone)
  887. \f[B]getattr\f[R] will usually be used.
  888. .SS Policies
  889. .PP
  890. A policy is the algorithm used to choose a branch or branches for a
  891. function to work on.
  892. Think of them as ways to filter and sort branches.
  893. .PP
  894. Any function in the \f[C]create\f[R] category will clone the relative
  895. path if needed.
  896. Some other functions (\f[C]rename\f[R],\f[C]link\f[R],\f[C]ioctl\f[R])
  897. have special requirements or behaviors which you can read more about
  898. below.
  899. .SS Filtering
  900. .PP
  901. Policies basically search branches and create a list of files / paths
  902. for functions to work on.
  903. The policy is responsible for filtering and sorting the branches.
  904. Filters include \f[B]minfreespace\f[R], whether or not a branch is
  905. mounted read-only, and the branch tagging (RO,NC,RW).
  906. These filters are applied across all policies unless otherwise noted.
  907. .IP \[bu] 2
  908. No \f[B]search\f[R] function policies filter.
  909. .IP \[bu] 2
  910. All \f[B]action\f[R] function policies filter out branches which are
  911. mounted \f[B]read-only\f[R] or tagged as \f[B]RO (read-only)\f[R].
  912. .IP \[bu] 2
  913. All \f[B]create\f[R] function policies filter out branches which are
  914. mounted \f[B]read-only\f[R], tagged \f[B]RO (read-only)\f[R] or \f[B]NC
  915. (no create)\f[R], or has available space less than
  916. \f[C]minfreespace\f[R].
  917. .PP
  918. Policies may have their own additional filtering such as those that
  919. require existing paths to be present.
  920. .PP
  921. If all branches are filtered an error will be returned.
  922. Typically \f[B]EROFS\f[R] (read-only filesystem) or \f[B]ENOSPC\f[R] (no
  923. space left on device) depending on the most recent reason for filtering
  924. a branch.
  925. \f[B]ENOENT\f[R] will be returned if no eligible branch is found.
  926. .SS Path Preservation
  927. .PP
  928. Policies, as described below, are of two basic classifications.
  929. \f[C]path preserving\f[R] and \f[C]non-path preserving\f[R].
  930. .PP
  931. All policies which start with \f[C]ep\f[R] (\f[B]epff\f[R],
  932. \f[B]eplfs\f[R], \f[B]eplus\f[R], \f[B]epmfs\f[R], \f[B]eprand\f[R]) are
  933. \f[C]path preserving\f[R].
  934. \f[C]ep\f[R] stands for \f[C]existing path\f[R].
  935. .PP
  936. A path preserving policy will only consider drives where the relative
  937. path being accessed already exists.
  938. .PP
  939. When using non-path preserving policies paths will be cloned to target
  940. drives as necessary.
  941. .PP
  942. With the \f[C]msp\f[R] or \f[C]most shared path\f[R] policies they are
  943. defined as \f[C]path preserving\f[R] for the purpose of controlling
  944. \f[C]link\f[R] and \f[C]rename\f[R]\[cq]s behaviors since
  945. \f[C]ignorepponrename\f[R] is available to disable that behavior.
  946. .SS Policy descriptions
  947. .PP
  948. A policy\[cq]s behavior differs, as mentioned above, based on the
  949. function it is used with.
  950. Sometimes it really might not make sense to even offer certain policies
  951. because they are literally the same as others but it makes things a bit
  952. more uniform.
  953. .PP
  954. .TS
  955. tab(@);
  956. lw(16.2n) lw(53.8n).
  957. T{
  958. Policy
  959. T}@T{
  960. Description
  961. T}
  962. _
  963. T{
  964. all
  965. T}@T{
  966. Search: For \f[B]mkdir\f[R], \f[B]mknod\f[R], and \f[B]symlink\f[R] it
  967. will apply to all branches.
  968. \f[B]create\f[R] works like \f[B]ff\f[R].
  969. T}
  970. T{
  971. epall (existing path, all)
  972. T}@T{
  973. For \f[B]mkdir\f[R], \f[B]mknod\f[R], and \f[B]symlink\f[R] it will
  974. apply to all found.
  975. \f[B]create\f[R] works like \f[B]epff\f[R] (but more expensive because
  976. it doesn\[cq]t stop after finding a valid branch).
  977. T}
  978. T{
  979. epff (existing path, first found)
  980. T}@T{
  981. Given the order of the branches, as defined at mount time or configured
  982. at runtime, act on the first one found where the relative path exists.
  983. T}
  984. T{
  985. eplfs (existing path, least free space)
  986. T}@T{
  987. Of all the branches on which the relative path exists choose the drive
  988. with the least free space.
  989. T}
  990. T{
  991. eplus (existing path, least used space)
  992. T}@T{
  993. Of all the branches on which the relative path exists choose the drive
  994. with the least used space.
  995. T}
  996. T{
  997. epmfs (existing path, most free space)
  998. T}@T{
  999. Of all the branches on which the relative path exists choose the drive
  1000. with the most free space.
  1001. T}
  1002. T{
  1003. eppfrd (existing path, percentage free random distribution)
  1004. T}@T{
  1005. Like \f[B]pfrd\f[R] but limited to existing paths.
  1006. T}
  1007. T{
  1008. eprand (existing path, random)
  1009. T}@T{
  1010. Calls \f[B]epall\f[R] and then randomizes.
  1011. Returns 1.
  1012. T}
  1013. T{
  1014. ff (first found)
  1015. T}@T{
  1016. Given the order of the drives, as defined at mount time or configured at
  1017. runtime, act on the first one found.
  1018. T}
  1019. T{
  1020. lfs (least free space)
  1021. T}@T{
  1022. Pick the drive with the least available free space.
  1023. T}
  1024. T{
  1025. lus (least used space)
  1026. T}@T{
  1027. Pick the drive with the least used space.
  1028. T}
  1029. T{
  1030. mfs (most free space)
  1031. T}@T{
  1032. Pick the drive with the most available free space.
  1033. T}
  1034. T{
  1035. msplfs (most shared path, least free space)
  1036. T}@T{
  1037. Like \f[B]eplfs\f[R] but if it fails to find a branch it will try again
  1038. with the parent directory.
  1039. Continues this pattern till finding one.
  1040. T}
  1041. T{
  1042. msplus (most shared path, least used space)
  1043. T}@T{
  1044. Like \f[B]eplus\f[R] but if it fails to find a branch it will try again
  1045. with the parent directory.
  1046. Continues this pattern till finding one.
  1047. T}
  1048. T{
  1049. mspmfs (most shared path, most free space)
  1050. T}@T{
  1051. Like \f[B]epmfs\f[R] but if it fails to find a branch it will try again
  1052. with the parent directory.
  1053. Continues this pattern till finding one.
  1054. T}
  1055. T{
  1056. msppfrd (most shared path, percentage free random distribution)
  1057. T}@T{
  1058. Like \f[B]eppfrd\f[R] but if it fails to find a branch it will try again
  1059. with the parent directory.
  1060. Continues this pattern till finding one.
  1061. T}
  1062. T{
  1063. newest
  1064. T}@T{
  1065. Pick the file / directory with the largest mtime.
  1066. T}
  1067. T{
  1068. pfrd (percentage free random distribution)
  1069. T}@T{
  1070. Chooses a branch at random with the likelihood of selection based on a
  1071. branch\[cq]s available space relative to the total.
  1072. T}
  1073. T{
  1074. rand (random)
  1075. T}@T{
  1076. Calls \f[B]all\f[R] and then randomizes.
  1077. Returns 1 branch.
  1078. T}
  1079. .TE
  1080. .PP
  1081. \f[B]NOTE:\f[R] If you are using an underlying filesystem that reserves
  1082. blocks such as ext2, ext3, or ext4 be aware that mergerfs respects the
  1083. reservation by using \f[C]f_bavail\f[R] (number of free blocks for
  1084. unprivileged users) rather than \f[C]f_bfree\f[R] (number of free
  1085. blocks) in policy calculations.
  1086. \f[B]df\f[R] does NOT use \f[C]f_bavail\f[R], it uses \f[C]f_bfree\f[R],
  1087. so direct comparisons between \f[B]df\f[R] output and mergerfs\[cq]
  1088. policies is not appropriate.
  1089. .SS Defaults
  1090. .PP
  1091. .TS
  1092. tab(@);
  1093. l l.
  1094. T{
  1095. Category
  1096. T}@T{
  1097. Policy
  1098. T}
  1099. _
  1100. T{
  1101. action
  1102. T}@T{
  1103. epall
  1104. T}
  1105. T{
  1106. create
  1107. T}@T{
  1108. epmfs
  1109. T}
  1110. T{
  1111. search
  1112. T}@T{
  1113. ff
  1114. T}
  1115. .TE
  1116. .SS ioctl
  1117. .PP
  1118. When \f[C]ioctl\f[R] is used with an open file then it will use the file
  1119. handle which was created at the original \f[C]open\f[R] call.
  1120. However, when using \f[C]ioctl\f[R] with a directory mergerfs will use
  1121. the \f[C]open\f[R] policy to find the directory to act on.
  1122. .SS rename & link
  1123. .PP
  1124. \f[B]NOTE:\f[R] If you\[cq]re receiving errors from software when files
  1125. are moved / renamed / linked then you should consider changing the
  1126. create policy to one which is \f[B]not\f[R] path preserving, enabling
  1127. \f[C]ignorepponrename\f[R], or contacting the author of the offending
  1128. software and requesting that \f[C]EXDEV\f[R] (cross device / improper
  1129. link) be properly handled.
  1130. .PP
  1131. \f[C]rename\f[R] and \f[C]link\f[R] are tricky functions in a union
  1132. filesystem.
  1133. \f[C]rename\f[R] only works within a single filesystem or device.
  1134. If a rename can\[cq]t be done atomically due to the source and
  1135. destination paths existing on different mount points it will return
  1136. \f[B]-1\f[R] with \f[B]errno = EXDEV\f[R] (cross device / improper
  1137. link).
  1138. So if a \f[C]rename\f[R]\[cq]s source and target are on different drives
  1139. within the pool it creates an issue.
  1140. .PP
  1141. Originally mergerfs would return EXDEV whenever a rename was requested
  1142. which was cross directory in any way.
  1143. This made the code simple and was technically compliant with POSIX
  1144. requirements.
  1145. However, many applications fail to handle EXDEV at all and treat it as a
  1146. normal error or otherwise handle it poorly.
  1147. Such apps include: gvfsd-fuse v1.20.3 and prior, Finder / CIFS/SMB
  1148. client in Apple OSX 10.9+, NZBGet, Samba\[cq]s recycling bin feature.
  1149. .PP
  1150. As a result a compromise was made in order to get most software to work
  1151. while still obeying mergerfs\[cq] policies.
  1152. Below is the basic logic.
  1153. .IP \[bu] 2
  1154. If using a \f[B]create\f[R] policy which tries to preserve directory
  1155. paths (epff,eplfs,eplus,epmfs)
  1156. .RS 2
  1157. .IP \[bu] 2
  1158. Using the \f[B]rename\f[R] policy get the list of files to rename
  1159. .IP \[bu] 2
  1160. For each file attempt rename:
  1161. .RS 2
  1162. .IP \[bu] 2
  1163. If failure with ENOENT (no such file or directory) run \f[B]create\f[R]
  1164. policy
  1165. .IP \[bu] 2
  1166. If create policy returns the same drive as currently evaluating then
  1167. clone the path
  1168. .IP \[bu] 2
  1169. Re-attempt rename
  1170. .RE
  1171. .IP \[bu] 2
  1172. If \f[B]any\f[R] of the renames succeed the higher level rename is
  1173. considered a success
  1174. .IP \[bu] 2
  1175. If \f[B]no\f[R] renames succeed the first error encountered will be
  1176. returned
  1177. .IP \[bu] 2
  1178. On success:
  1179. .RS 2
  1180. .IP \[bu] 2
  1181. Remove the target from all drives with no source file
  1182. .IP \[bu] 2
  1183. Remove the source from all drives which failed to rename
  1184. .RE
  1185. .RE
  1186. .IP \[bu] 2
  1187. If using a \f[B]create\f[R] policy which does \f[B]not\f[R] try to
  1188. preserve directory paths
  1189. .RS 2
  1190. .IP \[bu] 2
  1191. Using the \f[B]rename\f[R] policy get the list of files to rename
  1192. .IP \[bu] 2
  1193. Using the \f[B]getattr\f[R] policy get the target path
  1194. .IP \[bu] 2
  1195. For each file attempt rename:
  1196. .RS 2
  1197. .IP \[bu] 2
  1198. If the source drive != target drive:
  1199. .RS 2
  1200. .IP \[bu] 2
  1201. Clone target path from target drive to source drive
  1202. .RE
  1203. .IP \[bu] 2
  1204. Rename
  1205. .RE
  1206. .IP \[bu] 2
  1207. If \f[B]any\f[R] of the renames succeed the higher level rename is
  1208. considered a success
  1209. .IP \[bu] 2
  1210. If \f[B]no\f[R] renames succeed the first error encountered will be
  1211. returned
  1212. .IP \[bu] 2
  1213. On success:
  1214. .RS 2
  1215. .IP \[bu] 2
  1216. Remove the target from all drives with no source file
  1217. .IP \[bu] 2
  1218. Remove the source from all drives which failed to rename
  1219. .RE
  1220. .RE
  1221. .PP
  1222. The the removals are subject to normal entitlement checks.
  1223. .PP
  1224. The above behavior will help minimize the likelihood of EXDEV being
  1225. returned but it will still be possible.
  1226. .PP
  1227. \f[B]link\f[R] uses the same strategy but without the removals.
  1228. .SS readdir
  1229. .PP
  1230. readdir (http://linux.die.net/man/3/readdir) is different from all other
  1231. filesystem functions.
  1232. While it could have its own set of policies to tweak its behavior at
  1233. this time it provides a simple union of files and directories found.
  1234. Remember that any action or information queried about these files and
  1235. directories come from the respective function.
  1236. For instance: an \f[B]ls\f[R] is a \f[B]readdir\f[R] and for each
  1237. file/directory returned \f[B]getattr\f[R] is called.
  1238. Meaning the policy of \f[B]getattr\f[R] is responsible for choosing the
  1239. file/directory which is the source of the metadata you see in an
  1240. \f[B]ls\f[R].
  1241. .SS statfs / statvfs
  1242. .PP
  1243. statvfs (http://linux.die.net/man/2/statvfs) normalizes the source
  1244. drives based on the fragment size and sums the number of adjusted blocks
  1245. and inodes.
  1246. This means you will see the combined space of all sources.
  1247. Total, used, and free.
  1248. The sources however are dedupped based on the drive so multiple sources
  1249. on the same drive will not result in double counting its space.
  1250. Filesystems mounted further down the tree of the branch will not be
  1251. included when checking the mount\[cq]s stats.
  1252. .PP
  1253. The options \f[C]statfs\f[R] and \f[C]statfs_ignore\f[R] can be used to
  1254. modify \f[C]statfs\f[R] behavior.
  1255. .SH ERROR HANDLING
  1256. .PP
  1257. POSIX filesystem functions offer a single return code meaning that there
  1258. is some complication regarding the handling of multiple branches as
  1259. mergerfs does.
  1260. It tries to handle errors in a way that would generally return
  1261. meaningful values for that particular function.
  1262. .SS chmod, chown, removexattr, setxattr, truncate, utimens
  1263. .IP "1)" 3
  1264. if no error: return 0 (success)
  1265. .IP "2)" 3
  1266. if no successes: return first error
  1267. .IP "3)" 3
  1268. if one of the files acted on was the same as the related search
  1269. function: return its value
  1270. .IP "4)" 3
  1271. return 0 (success)
  1272. .PP
  1273. While doing this increases the complexity and cost of error handling,
  1274. particularly step 3, this provides probably the most reasonable return
  1275. value.
  1276. .SS unlink, rmdir
  1277. .IP "1)" 3
  1278. if no errors: return 0 (success)
  1279. .IP "2)" 3
  1280. return first error
  1281. .PP
  1282. Older version of mergerfs would return success if any success occurred
  1283. but for unlink and rmdir there are downstream assumptions that, while
  1284. not impossible to occur, can confuse some software.
  1285. .SS others
  1286. .PP
  1287. For search functions there is always a single thing acted on and as such
  1288. whatever return value that comes from the single function call is
  1289. returned.
  1290. .PP
  1291. For create functions \f[C]mkdir\f[R], \f[C]mknod\f[R], and
  1292. \f[C]symlink\f[R] which don\[cq]t return a file descriptor and therefore
  1293. can have \f[C]all\f[R] or \f[C]epall\f[R] policies it will return
  1294. success if any of the calls succeed and an error otherwise.
  1295. .SH INSTALL
  1296. .PP
  1297. https://github.com/trapexit/mergerfs/releases
  1298. .PP
  1299. If your distribution\[cq]s package manager includes mergerfs check if
  1300. the version is up to date.
  1301. If out of date it is recommended to use the latest release found on the
  1302. release page.
  1303. Details for common distros are below.
  1304. .SS Debian
  1305. .PP
  1306. Most Debian installs are of a stable branch and therefore do not have
  1307. the most up to date software.
  1308. While mergerfs is available via \f[C]apt\f[R] it is suggested that uses
  1309. install the most recent version available from the releases
  1310. page (https://github.com/trapexit/mergerfs/releases).
  1311. .SS prebuilt deb
  1312. .IP
  1313. .nf
  1314. \f[C]
  1315. wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs_<ver>.debian-<rel>_<arch>.deb
  1316. dpkg -i mergerfs_<ver>.debian-<rel>_<arch>.deb
  1317. \f[R]
  1318. .fi
  1319. .SS apt
  1320. .IP
  1321. .nf
  1322. \f[C]
  1323. sudo apt install -y mergerfs
  1324. \f[R]
  1325. .fi
  1326. .SS Ubuntu
  1327. .PP
  1328. Most Ubuntu installs are of a stable branch and therefore do not have
  1329. the most up to date software.
  1330. While mergerfs is available via \f[C]apt\f[R] it is suggested that uses
  1331. install the most recent version available from the releases
  1332. page (https://github.com/trapexit/mergerfs/releases).
  1333. .SS prebuilt deb
  1334. .IP
  1335. .nf
  1336. \f[C]
  1337. wget https://github.com/trapexit/mergerfs/releases/download/<version>/mergerfs_<ver>.ubuntu-<rel>_<arch>.deb
  1338. dpkg -i mergerfs_<ver>.ubuntu-<rel>_<arch>.deb
  1339. \f[R]
  1340. .fi
  1341. .SS apt
  1342. .IP
  1343. .nf
  1344. \f[C]
  1345. sudo apt install -y mergerfs
  1346. \f[R]
  1347. .fi
  1348. .SS Raspberry Pi OS
  1349. .PP
  1350. Effectively the same as Debian or Ubuntu.
  1351. .SS Fedora
  1352. .IP
  1353. .nf
  1354. \f[C]
  1355. wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs-<ver>.fc<rel>.<arch>.rpm
  1356. sudo rpm -i mergerfs-<ver>.fc<rel>.<arch>.rpm
  1357. \f[R]
  1358. .fi
  1359. .SS CentOS / Rocky
  1360. .IP
  1361. .nf
  1362. \f[C]
  1363. wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs-<ver>.el<rel>.<arch>.rpm
  1364. sudo rpm -i mergerfs-<ver>.el<rel>.<arch>.rpm
  1365. \f[R]
  1366. .fi
  1367. .SS ArchLinux
  1368. .IP "1." 3
  1369. Setup AUR
  1370. .IP "2." 3
  1371. Install \f[C]mergerfs\f[R]
  1372. .SS Other
  1373. .PP
  1374. Static binaries are provided for situations where native packages are
  1375. unavailable.
  1376. .IP
  1377. .nf
  1378. \f[C]
  1379. wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs-static-linux_<arch>.tar.gz
  1380. sudo tar xvf mergerfs-static-linux_<arch>.tar.gz -C /
  1381. \f[R]
  1382. .fi
  1383. .SH BUILD
  1384. .PP
  1385. \f[B]NOTE:\f[R] Prebuilt packages can be found at and recommended for
  1386. most users: https://github.com/trapexit/mergerfs/releases
  1387. .PP
  1388. \f[B]NOTE:\f[R] Only tagged releases are supported.
  1389. \f[C]master\f[R] and other branches should be considered works in
  1390. progress.
  1391. .PP
  1392. First get the code from github (https://github.com/trapexit/mergerfs).
  1393. .IP
  1394. .nf
  1395. \f[C]
  1396. $ git clone https://github.com/trapexit/mergerfs.git
  1397. $ # or
  1398. $ wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs-<ver>.tar.gz
  1399. \f[R]
  1400. .fi
  1401. .SS Debian / Ubuntu
  1402. .IP
  1403. .nf
  1404. \f[C]
  1405. $ cd mergerfs
  1406. $ sudo tools/install-build-pkgs
  1407. $ make deb
  1408. $ sudo dpkg -i ../mergerfs_<version>_<arch>.deb
  1409. \f[R]
  1410. .fi
  1411. .SS RHEL / CentOS / Rocky / Fedora
  1412. .IP
  1413. .nf
  1414. \f[C]
  1415. $ su -
  1416. # cd mergerfs
  1417. # tools/install-build-pkgs
  1418. # make rpm
  1419. # rpm -i rpmbuild/RPMS/<arch>/mergerfs-<version>.<arch>.rpm
  1420. \f[R]
  1421. .fi
  1422. .SS Generic
  1423. .PP
  1424. Have git, g++, make, python installed.
  1425. .IP
  1426. .nf
  1427. \f[C]
  1428. $ cd mergerfs
  1429. $ make
  1430. $ sudo make install
  1431. \f[R]
  1432. .fi
  1433. .SS Build options
  1434. .IP
  1435. .nf
  1436. \f[C]
  1437. $ make help
  1438. usage: make
  1439. make USE_XATTR=0 - build program without xattrs functionality
  1440. make STATIC=1 - build static binary
  1441. make LTO=1 - build with link time optimization
  1442. \f[R]
  1443. .fi
  1444. .SH UPGRADE
  1445. .PP
  1446. mergerfs can be upgraded live by mounting on top of the previous
  1447. instance.
  1448. Simply install the new version of mergerfs and follow the instructions
  1449. below.
  1450. .PP
  1451. Run mergerfs again or if using \f[C]/etc/fstab\f[R] call for it to mount
  1452. again.
  1453. Existing open files and such will continue to work fine though they
  1454. won\[cq]t see runtime changes since any such change would be the new
  1455. mount.
  1456. If you plan on changing settings with the new mount you should / could
  1457. apply those before mounting the new version.
  1458. .IP
  1459. .nf
  1460. \f[C]
  1461. $ sudo mount /mnt/mergerfs
  1462. $ mount | grep mergerfs
  1463. media on /mnt/mergerfs type fuse.mergerfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other)
  1464. media on /mnt/mergerfs type fuse.mergerfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other)
  1465. \f[R]
  1466. .fi
  1467. .PP
  1468. A problem with this approach is that the underlying instance will
  1469. continue to run even if the software using it stop or are restarted.
  1470. To work around this you can use a \[lq]lazy umount\[rq].
  1471. Before mounting over top the mount point with the new instance of
  1472. mergerfs issue: \f[C]umount -l <mergerfs_mountpoint>\f[R].
  1473. Or you can let mergerfs do it by setting the option
  1474. \f[C]lazy-umount-mountpoint=true\f[R].
  1475. .SH RUNTIME CONFIG
  1476. .SS .mergerfs pseudo file
  1477. .IP
  1478. .nf
  1479. \f[C]
  1480. <mountpoint>/.mergerfs
  1481. \f[R]
  1482. .fi
  1483. .PP
  1484. There is a pseudo file available at the mount point which allows for the
  1485. runtime modification of certain \f[B]mergerfs\f[R] options.
  1486. The file will not show up in \f[B]readdir\f[R] but can be
  1487. \f[B]stat\f[R]\[cq]ed and manipulated via
  1488. {list,get,set}xattrs (http://linux.die.net/man/2/listxattr) calls.
  1489. .PP
  1490. Any changes made at runtime are \f[B]not\f[R] persisted.
  1491. If you wish for values to persist they must be included as options
  1492. wherever you configure the mounting of mergerfs (/etc/fstab).
  1493. .SS Keys
  1494. .PP
  1495. Use \f[C]getfattr -d /mountpoint/.mergerfs\f[R] or
  1496. \f[C]xattr -l /mountpoint/.mergerfs\f[R] to see all supported keys.
  1497. Some are informational and therefore read-only.
  1498. \f[C]setxattr\f[R] will return EINVAL (invalid argument) on read-only
  1499. keys.
  1500. .SS Values
  1501. .PP
  1502. Same as the command line.
  1503. .SS user.mergerfs.branches
  1504. .PP
  1505. Used to query or modify the list of branches.
  1506. When modifying there are several shortcuts to easy manipulation of the
  1507. list.
  1508. .PP
  1509. .TS
  1510. tab(@);
  1511. l l.
  1512. T{
  1513. Value
  1514. T}@T{
  1515. Description
  1516. T}
  1517. _
  1518. T{
  1519. [list]
  1520. T}@T{
  1521. set
  1522. T}
  1523. T{
  1524. +<[list]
  1525. T}@T{
  1526. prepend
  1527. T}
  1528. T{
  1529. +>[list]
  1530. T}@T{
  1531. append
  1532. T}
  1533. T{
  1534. -[list]
  1535. T}@T{
  1536. remove all values provided
  1537. T}
  1538. T{
  1539. -<
  1540. T}@T{
  1541. remove first in list
  1542. T}
  1543. T{
  1544. ->
  1545. T}@T{
  1546. remove last in list
  1547. T}
  1548. .TE
  1549. .PP
  1550. \f[C]xattr -w user.mergerfs.branches +</mnt/drive3 /mnt/pool/.mergerfs\f[R]
  1551. .PP
  1552. The \f[C]=NC\f[R], \f[C]=RO\f[R], \f[C]=RW\f[R] syntax works just as on
  1553. the command line.
  1554. .SS Example
  1555. .IP
  1556. .nf
  1557. \f[C]
  1558. [trapexit:/mnt/mergerfs] $ getfattr -d .mergerfs
  1559. user.mergerfs.branches=\[dq]/mnt/a=RW:/mnt/b=RW\[dq]
  1560. user.mergerfs.minfreespace=\[dq]4294967295\[dq]
  1561. user.mergerfs.moveonenospc=\[dq]false\[dq]
  1562. \&...
  1563. [trapexit:/mnt/mergerfs] $ getfattr -n user.mergerfs.category.search .mergerfs
  1564. user.mergerfs.category.search=\[dq]ff\[dq]
  1565. [trapexit:/mnt/mergerfs] $ setfattr -n user.mergerfs.category.search -v newest .mergerfs
  1566. [trapexit:/mnt/mergerfs] $ getfattr -n user.mergerfs.category.search .mergerfs
  1567. user.mergerfs.category.search=\[dq]newest\[dq]
  1568. \f[R]
  1569. .fi
  1570. .SS file / directory xattrs
  1571. .PP
  1572. While they won\[cq]t show up when using \f[C]getfattr\f[R]
  1573. \f[B]mergerfs\f[R] offers a number of special xattrs to query
  1574. information about the files served.
  1575. To access the values you will need to issue a
  1576. getxattr (http://linux.die.net/man/2/getxattr) for one of the following:
  1577. .IP \[bu] 2
  1578. \f[B]user.mergerfs.basepath\f[R]: the base mount point for the file
  1579. given the current getattr policy
  1580. .IP \[bu] 2
  1581. \f[B]user.mergerfs.relpath\f[R]: the relative path of the file from the
  1582. perspective of the mount point
  1583. .IP \[bu] 2
  1584. \f[B]user.mergerfs.fullpath\f[R]: the full path of the original file
  1585. given the getattr policy
  1586. .IP \[bu] 2
  1587. \f[B]user.mergerfs.allpaths\f[R]: a NUL (`\[rs]0') separated list of
  1588. full paths to all files found
  1589. .SH TOOLING
  1590. .IP \[bu] 2
  1591. https://github.com/trapexit/mergerfs-tools
  1592. .RS 2
  1593. .IP \[bu] 2
  1594. mergerfs.ctl: A tool to make it easier to query and configure mergerfs
  1595. at runtime
  1596. .IP \[bu] 2
  1597. mergerfs.fsck: Provides permissions and ownership auditing and the
  1598. ability to fix them
  1599. .IP \[bu] 2
  1600. mergerfs.dedup: Will help identify and optionally remove duplicate files
  1601. .IP \[bu] 2
  1602. mergerfs.dup: Ensure there are at least N copies of a file across the
  1603. pool
  1604. .IP \[bu] 2
  1605. mergerfs.balance: Rebalance files across drives by moving them from the
  1606. most filled to the least filled
  1607. .IP \[bu] 2
  1608. mergerfs.consolidate: move files within a single mergerfs directory to
  1609. the drive with most free space
  1610. .RE
  1611. .IP \[bu] 2
  1612. https://github.com/trapexit/scorch
  1613. .RS 2
  1614. .IP \[bu] 2
  1615. scorch: A tool to help discover silent corruption of files and keep
  1616. track of files
  1617. .RE
  1618. .IP \[bu] 2
  1619. https://github.com/trapexit/bbf
  1620. .RS 2
  1621. .IP \[bu] 2
  1622. bbf (bad block finder): a tool to scan for and `fix' hard drive bad
  1623. blocks and find the files using those blocks
  1624. .RE
  1625. .SH CACHING
  1626. .SS page caching
  1627. .PP
  1628. https://en.wikipedia.org/wiki/Page_cache
  1629. .IP \[bu] 2
  1630. cache.files=off: Disables page caching.
  1631. Underlying files cached, mergerfs files are not.
  1632. .IP \[bu] 2
  1633. cache.files=partial: Enables page caching.
  1634. Underlying files cached, mergerfs files cached while open.
  1635. .IP \[bu] 2
  1636. cache.files=full: Enables page caching.
  1637. Underlying files cached, mergerfs files cached across opens.
  1638. .IP \[bu] 2
  1639. cache.files=auto-full: Enables page caching.
  1640. Underlying files cached, mergerfs files cached across opens if mtime and
  1641. size are unchanged since previous open.
  1642. .IP \[bu] 2
  1643. cache.files=libfuse: follow traditional libfuse \f[C]direct_io\f[R],
  1644. \f[C]kernel_cache\f[R], and \f[C]auto_cache\f[R] arguments.
  1645. .IP \[bu] 2
  1646. cache.files=per-process: Enable page caching only for processes which
  1647. `comm' name matches one of the values defined in
  1648. \f[C]cache.files.process-names\f[R].
  1649. .PP
  1650. FUSE, which mergerfs uses, offers a number of page caching modes.
  1651. mergerfs tries to simplify their use via the \f[C]cache.files\f[R]
  1652. option.
  1653. It can and should replace usage of \f[C]direct_io\f[R],
  1654. \f[C]kernel_cache\f[R], and \f[C]auto_cache\f[R].
  1655. .PP
  1656. Due to mergerfs using FUSE and therefore being a userland process
  1657. proxying existing filesystems the kernel will double cache the content
  1658. being read and written through mergerfs.
  1659. Once from the underlying filesystem and once from mergerfs (it sees them
  1660. as two separate entities).
  1661. Using \f[C]cache.files=off\f[R] will keep the double caching from
  1662. happening by disabling caching of mergerfs but this has the side effect
  1663. that \f[I]all\f[R] read and write calls will be passed to mergerfs which
  1664. may be slower than enabling caching, you lose shared \f[C]mmap\f[R]
  1665. support which can affect apps such as rtorrent, and no read-ahead will
  1666. take place.
  1667. The kernel will still cache the underlying filesystem data but that only
  1668. helps so much given mergerfs will still process all requests.
  1669. .PP
  1670. If you do enable file page caching,
  1671. \f[C]cache.files=partial|full|auto-full\f[R], you should also enable
  1672. \f[C]dropcacheonclose\f[R] which will cause mergerfs to instruct the
  1673. kernel to flush the underlying file\[cq]s page cache when the file is
  1674. closed.
  1675. This behavior is the same as the rsync fadvise / drop cache patch and
  1676. Feh\[cq]s nocache project.
  1677. .PP
  1678. If most files are read once through and closed (like media) it is best
  1679. to enable \f[C]dropcacheonclose\f[R] regardless of caching mode in order
  1680. to minimize buffer bloat.
  1681. .PP
  1682. It is difficult to balance memory usage, cache bloat & duplication, and
  1683. performance.
  1684. Ideally mergerfs would be able to disable caching for the files it
  1685. reads/writes but allow page caching for itself.
  1686. That would limit the FUSE overhead.
  1687. However, there isn\[cq]t a good way to achieve this.
  1688. It would need to open all files with O_DIRECT which places limitations
  1689. on the what underlying filesystems would be supported and complicates
  1690. the code.
  1691. .PP
  1692. kernel documentation:
  1693. https://www.kernel.org/doc/Documentation/filesystems/fuse-io.txt
  1694. .SS entry & attribute caching
  1695. .PP
  1696. Given the relatively high cost of FUSE due to the kernel <-> userspace
  1697. round trips there are kernel side caches for file entries and
  1698. attributes.
  1699. The entry cache limits the \f[C]lookup\f[R] calls to mergerfs which ask
  1700. if a file exists.
  1701. The attribute cache limits the need to make \f[C]getattr\f[R] calls to
  1702. mergerfs which provide file attributes (mode, size, type, etc.).
  1703. As with the page cache these should not be used if the underlying
  1704. filesystems are being manipulated at the same time as it could lead to
  1705. odd behavior or data corruption.
  1706. The options for setting these are \f[C]cache.entry\f[R] and
  1707. \f[C]cache.negative_entry\f[R] for the entry cache and
  1708. \f[C]cache.attr\f[R] for the attributes cache.
  1709. \f[C]cache.negative_entry\f[R] refers to the timeout for negative
  1710. responses to lookups (non-existent files).
  1711. .SS writeback caching
  1712. .PP
  1713. When \f[C]cache.files\f[R] is enabled the default is for it to perform
  1714. writethrough caching.
  1715. This behavior won\[cq]t help improve performance as each write still
  1716. goes one for one through the filesystem.
  1717. By enabling the FUSE writeback cache small writes may be aggregated by
  1718. the kernel and then sent to mergerfs as one larger request.
  1719. This can greatly improve the throughput for apps which write to files
  1720. inefficiently.
  1721. The amount the kernel can aggregate is limited by the size of a FUSE
  1722. message.
  1723. Read the \f[C]fuse_msg_size\f[R] section for more details.
  1724. .PP
  1725. There is a small side effect as a result of enabling writeback caching.
  1726. Underlying files won\[cq]t ever be opened with O_APPEND or O_WRONLY.
  1727. The former because the kernel then manages append mode and the latter
  1728. because the kernel may request file data from mergerfs to populate the
  1729. write cache.
  1730. The O_APPEND change means that if a file is changed outside of mergerfs
  1731. it could lead to corruption as the kernel won\[cq]t know the end of the
  1732. file has changed.
  1733. That said any time you use caching you should keep from using the same
  1734. file outside of mergerfs at the same time.
  1735. .PP
  1736. Note that if an application is properly sizing writes then writeback
  1737. caching will have little or no effect.
  1738. It will only help with writes of sizes below the FUSE message size (128K
  1739. on older kernels, 1M on newer).
  1740. .SS policy caching
  1741. .PP
  1742. Policies are run every time a function (with a policy as mentioned
  1743. above) is called.
  1744. These policies can be expensive depending on mergerfs\[cq] setup and
  1745. client usage patterns.
  1746. Generally we wouldn\[cq]t want to cache policy results because it may
  1747. result in stale responses if the underlying drives are used directly.
  1748. .PP
  1749. The \f[C]open\f[R] policy cache will cache the result of an
  1750. \f[C]open\f[R] policy for a particular input for \f[C]cache.open\f[R]
  1751. seconds or until the file is unlinked.
  1752. Each file close (release) will randomly chose to clean up the cache of
  1753. expired entries.
  1754. .PP
  1755. This cache is really only useful in cases where you have a large number
  1756. of branches and \f[C]open\f[R] is called on the same files repeatedly
  1757. (like \f[B]Transmission\f[R] which opens and closes a file on every
  1758. read/write presumably to keep file handle usage low).
  1759. .SS statfs caching
  1760. .PP
  1761. Of the syscalls used by mergerfs in policies the \f[C]statfs\f[R] /
  1762. \f[C]statvfs\f[R] call is perhaps the most expensive.
  1763. It\[cq]s used to find out the available space of a drive and whether it
  1764. is mounted read-only.
  1765. Depending on the setup and usage pattern these queries can be relatively
  1766. costly.
  1767. When \f[C]cache.statfs\f[R] is enabled all calls to \f[C]statfs\f[R] by
  1768. a policy will be cached for the number of seconds its set to.
  1769. .PP
  1770. Example: If the create policy is \f[C]mfs\f[R] and the timeout is 60
  1771. then for that 60 seconds the same drive will be returned as the target
  1772. for creates because the available space won\[cq]t be updated for that
  1773. time.
  1774. .SS symlink caching
  1775. .PP
  1776. As of version 4.20 Linux supports symlink caching.
  1777. Significant performance increases can be had in workloads which use a
  1778. lot of symlinks.
  1779. Setting \f[C]cache.symlinks=true\f[R] will result in requesting symlink
  1780. caching from the kernel only if supported.
  1781. As a result its safe to enable it on systems prior to 4.20.
  1782. That said it is disabled by default for now.
  1783. You can see if caching is enabled by querying the xattr
  1784. \f[C]user.mergerfs.cache.symlinks\f[R] but given it must be requested at
  1785. startup you can not change it at runtime.
  1786. .SS readdir caching
  1787. .PP
  1788. As of version 4.20 Linux supports readdir caching.
  1789. This can have a significant impact on directory traversal.
  1790. Especially when combined with entry (\f[C]cache.entry\f[R]) and
  1791. attribute (\f[C]cache.attr\f[R]) caching.
  1792. Setting \f[C]cache.readdir=true\f[R] will result in requesting readdir
  1793. caching from the kernel on each \f[C]opendir\f[R].
  1794. If the kernel doesn\[cq]t support readdir caching setting the option to
  1795. \f[C]true\f[R] has no effect.
  1796. This option is configurable at runtime via xattr
  1797. \f[C]user.mergerfs.cache.readdir\f[R].
  1798. .SS tiered caching
  1799. .PP
  1800. Some storage technologies support what some call \[lq]tiered\[rq]
  1801. caching.
  1802. The placing of usually smaller, faster storage as a transparent cache to
  1803. larger, slower storage.
  1804. NVMe, SSD, Optane in front of traditional HDDs for instance.
  1805. .PP
  1806. MergerFS does not natively support any sort of tiered caching.
  1807. Most users have no use for such a feature and its inclusion would
  1808. complicate the code.
  1809. However, there are a few situations where a cache drive could help with
  1810. a typical mergerfs setup.
  1811. .IP "1." 3
  1812. Fast network, slow drives, many readers: You\[cq]ve a 10+Gbps network
  1813. with many readers and your regular drives can\[cq]t keep up.
  1814. .IP "2." 3
  1815. Fast network, slow drives, small\[cq]ish bursty writes: You have a
  1816. 10+Gbps network and wish to transfer amounts of data less than your
  1817. cache drive but wish to do so quickly.
  1818. .PP
  1819. With #1 it\[cq]s arguable if you should be using mergerfs at all.
  1820. RAID would probably be the better solution.
  1821. If you\[cq]re going to use mergerfs there are other tactics that may
  1822. help: spreading the data across drives (see the mergerfs.dup tool) and
  1823. setting \f[C]func.open=rand\f[R], using \f[C]symlinkify\f[R], or using
  1824. dm-cache or a similar technology to add tiered cache to the underlying
  1825. device.
  1826. .PP
  1827. With #2 one could use dm-cache as well but there is another solution
  1828. which requires only mergerfs and a cronjob.
  1829. .IP "1." 3
  1830. Create 2 mergerfs pools.
  1831. One which includes just the slow drives and one which has both the fast
  1832. drives (SSD,NVME,etc.) and slow drives.
  1833. .IP "2." 3
  1834. The `cache' pool should have the cache drives listed first.
  1835. .IP "3." 3
  1836. The best \f[C]create\f[R] policies to use for the `cache' pool would
  1837. probably be \f[C]ff\f[R], \f[C]epff\f[R], \f[C]lfs\f[R], or
  1838. \f[C]eplfs\f[R].
  1839. The latter two under the assumption that the cache drive(s) are far
  1840. smaller than the backing drives.
  1841. If using path preserving policies remember that you\[cq]ll need to
  1842. manually create the core directories of those paths you wish to be
  1843. cached.
  1844. Be sure the permissions are in sync.
  1845. Use \f[C]mergerfs.fsck\f[R] to check / correct them.
  1846. You could also tag the slow drives as \f[C]=NC\f[R] though that\[cq]d
  1847. mean if the cache drives fill you\[cq]d get \[lq]out of space\[rq]
  1848. errors.
  1849. .IP "4." 3
  1850. Enable \f[C]moveonenospc\f[R] and set \f[C]minfreespace\f[R]
  1851. appropriately.
  1852. To make sure there is enough room on the \[lq]slow\[rq] pool you might
  1853. want to set \f[C]minfreespace\f[R] to at least as large as the size of
  1854. the largest cache drive if not larger.
  1855. This way in the worst case the whole of the cache drive(s) can be moved
  1856. to the other drives.
  1857. .IP "5." 3
  1858. Set your programs to use the cache pool.
  1859. .IP "6." 3
  1860. Save one of the below scripts or create you\[cq]re own.
  1861. .IP "7." 3
  1862. Use \f[C]cron\f[R] (as root) to schedule the command at whatever
  1863. frequency is appropriate for your workflow.
  1864. .SS time based expiring
  1865. .PP
  1866. Move files from cache to backing pool based only on the last time the
  1867. file was accessed.
  1868. Replace \f[C]-atime\f[R] with \f[C]-amin\f[R] if you want minutes rather
  1869. than days.
  1870. May want to use the \f[C]fadvise\f[R] / \f[C]--drop-cache\f[R] version
  1871. of rsync or run rsync with the tool \[lq]nocache\[rq].
  1872. .PP
  1873. \f[I]NOTE:\f[R] The arguments to these scripts include the cache
  1874. \f[B]drive\f[R].
  1875. Not the pool with the cache drive.
  1876. You could have data loss if the source is the cache pool.
  1877. .IP
  1878. .nf
  1879. \f[C]
  1880. #!/bin/bash
  1881. if [ $# != 3 ]; then
  1882. echo \[dq]usage: $0 <cache-drive> <backing-pool> <days-old>\[dq]
  1883. exit 1
  1884. fi
  1885. CACHE=\[dq]${1}\[dq]
  1886. BACKING=\[dq]${2}\[dq]
  1887. N=${3}
  1888. find \[dq]${CACHE}\[dq] -type f -atime +${N} -printf \[aq]%P\[rs]n\[aq] | \[rs]
  1889. rsync --files-from=- -axqHAXWES --preallocate --remove-source-files \[dq]${CACHE}/\[dq] \[dq]${BACKING}/\[dq]
  1890. \f[R]
  1891. .fi
  1892. .SS percentage full expiring
  1893. .PP
  1894. Move the oldest file from the cache to the backing pool.
  1895. Continue till below percentage threshold.
  1896. .PP
  1897. \f[I]NOTE:\f[R] The arguments to these scripts include the cache
  1898. \f[B]drive\f[R].
  1899. Not the pool with the cache drive.
  1900. You could have data loss if the source is the cache pool.
  1901. .IP
  1902. .nf
  1903. \f[C]
  1904. #!/bin/bash
  1905. if [ $# != 3 ]; then
  1906. echo \[dq]usage: $0 <cache-drive> <backing-pool> <percentage>\[dq]
  1907. exit 1
  1908. fi
  1909. CACHE=\[dq]${1}\[dq]
  1910. BACKING=\[dq]${2}\[dq]
  1911. PERCENTAGE=${3}
  1912. set -o errexit
  1913. while [ $(df --output=pcent \[dq]${CACHE}\[dq] | grep -v Use | cut -d\[aq]%\[aq] -f1) -gt ${PERCENTAGE} ]
  1914. do
  1915. FILE=$(find \[dq]${CACHE}\[dq] -type f -printf \[aq]%A\[at] %P\[rs]n\[aq] | \[rs]
  1916. sort | \[rs]
  1917. head -n 1 | \[rs]
  1918. cut -d\[aq] \[aq] -f2-)
  1919. test -n \[dq]${FILE}\[dq]
  1920. rsync -axqHAXWESR --preallocate --remove-source-files \[dq]${CACHE}/./${FILE}\[dq] \[dq]${BACKING}/\[dq]
  1921. done
  1922. \f[R]
  1923. .fi
  1924. .SH PERFORMANCE
  1925. .PP
  1926. mergerfs is at its core just a proxy and therefore its theoretical max
  1927. performance is that of the underlying devices.
  1928. However, given it is a FUSE filesystem working from userspace there is
  1929. an increase in overhead relative to kernel based solutions.
  1930. That said the performance can match the theoretical max but it depends
  1931. greatly on the system\[cq]s configuration.
  1932. Especially when adding network filesystems into the mix there are many
  1933. variables which can impact performance.
  1934. Drive speeds and latency, network speeds and latency, general
  1935. concurrency, read/write sizes, etc.
  1936. Unfortunately, given the number of variables it has been difficult to
  1937. find a single set of settings which provide optimal performance.
  1938. If you\[cq]re having performance issues please look over the suggestions
  1939. below (including the benchmarking section.)
  1940. .PP
  1941. NOTE: be sure to read about these features before changing them to
  1942. understand what behaviors it may impact
  1943. .IP \[bu] 2
  1944. disable \f[C]security_capability\f[R] and/or \f[C]xattr\f[R]
  1945. .IP \[bu] 2
  1946. increase cache timeouts \f[C]cache.attr\f[R], \f[C]cache.entry\f[R],
  1947. \f[C]cache.negative_entry\f[R]
  1948. .IP \[bu] 2
  1949. enable (or disable) page caching (\f[C]cache.files\f[R])
  1950. .IP \[bu] 2
  1951. enable \f[C]cache.writeback\f[R]
  1952. .IP \[bu] 2
  1953. enable \f[C]cache.statfs\f[R]
  1954. .IP \[bu] 2
  1955. enable \f[C]cache.symlinks\f[R]
  1956. .IP \[bu] 2
  1957. enable \f[C]cache.readdir\f[R]
  1958. .IP \[bu] 2
  1959. change the number of worker threads
  1960. .IP \[bu] 2
  1961. disable \f[C]posix_acl\f[R]
  1962. .IP \[bu] 2
  1963. disable \f[C]async_read\f[R]
  1964. .IP \[bu] 2
  1965. test theoretical performance using \f[C]nullrw\f[R] or mounting a ram
  1966. disk
  1967. .IP \[bu] 2
  1968. use \f[C]symlinkify\f[R] if your data is largely static and read-only
  1969. .IP \[bu] 2
  1970. use tiered cache drives
  1971. .IP \[bu] 2
  1972. use LVM and LVM cache to place a SSD in front of your HDDs
  1973. .IP \[bu] 2
  1974. if \f[C]cache.files\f[R] is enabled increase readahead:
  1975. \f[C]echo \[dq]1024\[dq] > /sys/class/bdi/0:$(stat -c%d /MOUNT)/read_ahead_kb\f[R]
  1976. .IP \[bu] 2
  1977. increase readahead on all devices:
  1978. \f[C]ls -1 /sys/class/bdi/*/read_ahead_kb | xargs -n1 -I{} sh -c \[dq]echo 1024 > {}\[dq]\f[R]
  1979. .PP
  1980. If you come across a setting that significantly impacts performance
  1981. please contact trapexit so he may investigate further.
  1982. Please test both against your normal setup, a singular branch, and with
  1983. \f[C]nullrw=true\f[R]
  1984. .SH BENCHMARKING
  1985. .PP
  1986. Filesystems are complicated.
  1987. They do many things and many of those are interconnected.
  1988. Additionally, the OS, drivers, hardware, etc.
  1989. all can impact performance.
  1990. Therefore, when benchmarking, it is \f[B]necessary\f[R] that the test
  1991. focus as narrowly as possible.
  1992. .PP
  1993. For most throughput is the key benchmark.
  1994. To test throughput \f[C]dd\f[R] is useful but \f[B]must\f[R] be used
  1995. with the correct settings in order to ensure the filesystem or device is
  1996. actually being tested.
  1997. The OS can and will cache data.
  1998. Without forcing synchronous reads and writes and/or disabling caching
  1999. the values returned will not be representative of the device\[cq]s true
  2000. performance.
  2001. .PP
  2002. When benchmarking through mergerfs ensure you only use 1 branch to
  2003. remove any possibility of the policies complicating the situation.
  2004. Benchmark the underlying filesystem first and then mount mergerfs over
  2005. it and test again.
  2006. If you\[cq]re experience speeds below your expectation you will need to
  2007. narrow down precisely which component is leading to the slowdown.
  2008. Preferably test the following in the order listed (but not combined).
  2009. .IP "1." 3
  2010. Enable \f[C]nullrw\f[R] mode with \f[C]nullrw=true\f[R].
  2011. This will effectively make reads and writes no-ops.
  2012. Removing the underlying device / filesystem from the equation.
  2013. This will give us the top theoretical speeds.
  2014. .IP "2." 3
  2015. Mount mergerfs over \f[C]tmpfs\f[R].
  2016. \f[C]tmpfs\f[R] is a RAM disk.
  2017. Extremely high speed and very low latency.
  2018. This is a more realistic best case scenario.
  2019. Example: \f[C]mount -t tmpfs -o size=2G tmpfs /tmp/tmpfs\f[R]
  2020. .IP "3." 3
  2021. Mount mergerfs over a local drive.
  2022. NVMe, SSD, HDD, etc.
  2023. If you have more than one I\[cq]d suggest testing each of them as drives
  2024. and/or controllers (their drivers) could impact performance.
  2025. .IP "4." 3
  2026. Finally, if you intend to use mergerfs with a network filesystem, either
  2027. as the source of data or to combine with another through mergerfs, test
  2028. each of those alone as above.
  2029. .PP
  2030. Once you find the component which has the performance issue you can do
  2031. further testing with different options to see if they impact
  2032. performance.
  2033. For reads and writes the most relevant would be: \f[C]cache.files\f[R],
  2034. \f[C]async_read\f[R].
  2035. Less likely but relevant when using NFS or with certain filesystems
  2036. would be \f[C]security_capability\f[R], \f[C]xattr\f[R], and
  2037. \f[C]posix_acl\f[R].
  2038. If you find a specific system, drive, filesystem, controller, etc.
  2039. that performs poorly contact trapexit so he may investigate further.
  2040. .PP
  2041. Sometimes the problem is really the application accessing or writing
  2042. data through mergerfs.
  2043. Some software use small buffer sizes which can lead to more requests and
  2044. therefore greater overhead.
  2045. You can test this out yourself by replace \f[C]bs=1M\f[R] in the
  2046. examples below with \f[C]ibs\f[R] or \f[C]obs\f[R] and using a size of
  2047. \f[C]512\f[R] instead of \f[C]1M\f[R].
  2048. In one example test using \f[C]nullrw\f[R] the write speed dropped from
  2049. 4.9GB/s to 69.7MB/s when moving from \f[C]1M\f[R] to \f[C]512\f[R].
  2050. Similar results were had when testing reads.
  2051. Small writes overhead may be improved by leveraging a write cache but in
  2052. casual tests little gain was found.
  2053. More tests will need to be done before this feature would become
  2054. available.
  2055. If you have an app that appears slow with mergerfs it could be due to
  2056. this.
  2057. Contact trapexit so he may investigate further.
  2058. .SS write benchmark
  2059. .IP
  2060. .nf
  2061. \f[C]
  2062. $ dd if=/dev/zero of=/mnt/mergerfs/1GB.file bs=1M count=1024 oflag=nocache conv=fdatasync status=progress
  2063. \f[R]
  2064. .fi
  2065. .SS read benchmark
  2066. .IP
  2067. .nf
  2068. \f[C]
  2069. $ dd if=/mnt/mergerfs/1GB.file of=/dev/null bs=1M count=1024 iflag=nocache conv=fdatasync status=progress
  2070. \f[R]
  2071. .fi
  2072. .SS other benchmarks
  2073. .PP
  2074. If you are attempting to benchmark other behaviors you must ensure you
  2075. clear kernel caches before runs.
  2076. In fact it would be a good deal to run before the read and write
  2077. benchmarks as well just in case.
  2078. .IP
  2079. .nf
  2080. \f[C]
  2081. sync
  2082. echo 3 | sudo tee /proc/sys/vm/drop_caches
  2083. \f[R]
  2084. .fi
  2085. .SH TIPS / NOTES
  2086. .IP \[bu] 2
  2087. This document is literal and thorough.
  2088. If a suspected feature isn\[cq]t mentioned it doesn\[cq]t exist.
  2089. If certain libfuse arguments aren\[cq]t listed they probably
  2090. shouldn\[cq]t be used.
  2091. .IP \[bu] 2
  2092. Ensure you\[cq]re using the latest version.
  2093. .IP \[bu] 2
  2094. Run mergerfs as \f[C]root\f[R].
  2095. mergerfs is designed and intended to be run as \f[C]root\f[R] and may
  2096. exibit incorrect behavior if run otherwise..
  2097. .IP \[bu] 2
  2098. If you don\[cq]t see some directories and files you expect, policies
  2099. seem to skip branches, you get strange permission errors, etc.
  2100. be sure the underlying filesystems\[cq] permissions are all the same.
  2101. Use \f[C]mergerfs.fsck\f[R] to audit the drive for out of sync
  2102. permissions.
  2103. .IP \[bu] 2
  2104. If you still have permission issues be sure you are using POSIX ACL
  2105. compliant filesystems.
  2106. mergerfs doesn\[cq]t generally make exceptions for FAT, NTFS, or other
  2107. non-POSIX filesystem.
  2108. .IP \[bu] 2
  2109. Do \f[B]not\f[R] use \f[C]cache.files=off\f[R] if you expect
  2110. applications (such as rtorrent) to use
  2111. mmap (http://linux.die.net/man/2/mmap) files.
  2112. Shared mmap is not currently supported in FUSE w/ page caching disabled.
  2113. Enabling \f[C]dropcacheonclose\f[R] is recommended when
  2114. \f[C]cache.files=partial|full|auto-full\f[R].
  2115. .IP \[bu] 2
  2116. Kodi (http://kodi.tv), Plex (http://plex.tv),
  2117. Subsonic (http://subsonic.org), etc.
  2118. can use directory mtime (http://linux.die.net/man/2/stat) to more
  2119. efficiently determine whether to scan for new content rather than simply
  2120. performing a full scan.
  2121. If using the default \f[B]getattr\f[R] policy of \f[B]ff\f[R] it\[cq]s
  2122. possible those programs will miss an update on account of it returning
  2123. the first directory found\[cq]s \f[B]stat\f[R] info and it\[cq]s a later
  2124. directory on another mount which had the \f[B]mtime\f[R] recently
  2125. updated.
  2126. To fix this you will want to set \f[B]func.getattr=newest\f[R].
  2127. Remember though that this is just \f[B]stat\f[R].
  2128. If the file is later \f[B]open\f[R]\[cq]ed or \f[B]unlink\f[R]\[cq]ed
  2129. and the policy is different for those then a completely different file
  2130. or directory could be acted on.
  2131. .IP \[bu] 2
  2132. Some policies mixed with some functions may result in strange behaviors.
  2133. Not that some of these behaviors and race conditions couldn\[cq]t happen
  2134. outside \f[B]mergerfs\f[R] but that they are far more likely to occur on
  2135. account of the attempt to merge together multiple sources of data which
  2136. could be out of sync due to the different policies.
  2137. .IP \[bu] 2
  2138. For consistency its generally best to set \f[B]category\f[R] wide
  2139. policies rather than individual \f[B]func\f[R]\[cq]s.
  2140. This will help limit the confusion of tools such as
  2141. rsync (http://linux.die.net/man/1/rsync).
  2142. However, the flexibility is there if needed.
  2143. .SH KNOWN ISSUES / BUGS
  2144. .SS kernel issues & bugs
  2145. .PP
  2146. <https://github.com/trapexit/mergerfs/wiki/Kernel-Issues-&-Bugs>
  2147. .SS directory mtime is not being updated
  2148. .PP
  2149. Remember that the default policy for \f[C]getattr\f[R] is \f[C]ff\f[R].
  2150. The information for the first directory found will be returned.
  2151. If it wasn\[cq]t the directory which had been updated then it will
  2152. appear outdated.
  2153. .PP
  2154. The reason this is the default is because any other policy would be more
  2155. expensive and for many applications it is unnecessary.
  2156. To always return the directory with the most recent mtime or a faked
  2157. value based on all found would require a scan of all drives.
  2158. .PP
  2159. If you always want the directory information from the one with the most
  2160. recent mtime then use the \f[C]newest\f[R] policy for \f[C]getattr\f[R].
  2161. .SS `mv /mnt/pool/foo /mnt/disk1/foo' removes `foo'
  2162. .PP
  2163. This is not a bug.
  2164. .PP
  2165. Run in verbose mode to better understand what\[cq]s happening:
  2166. .IP
  2167. .nf
  2168. \f[C]
  2169. $ mv -v /mnt/pool/foo /mnt/disk1/foo
  2170. copied \[aq]/mnt/pool/foo\[aq] -> \[aq]/mnt/disk1/foo\[aq]
  2171. removed \[aq]/mnt/pool/foo\[aq]
  2172. $ ls /mnt/pool/foo
  2173. ls: cannot access \[aq]/mnt/pool/foo\[aq]: No such file or directory
  2174. \f[R]
  2175. .fi
  2176. .PP
  2177. \f[C]mv\f[R], when working across devices, is copying the source to
  2178. target and then removing the source.
  2179. Since the source \f[B]is\f[R] the target in this case, depending on the
  2180. unlink policy, it will remove the just copied file and other files
  2181. across the branches.
  2182. .PP
  2183. If you want to move files to one drive just copy them there and use
  2184. mergerfs.dedup to clean up the old paths or manually remove them from
  2185. the branches directly.
  2186. .SS cached memory appears greater than it should be
  2187. .PP
  2188. Use \f[C]cache.files=off\f[R] and/or \f[C]dropcacheonclose=true\f[R].
  2189. See the section on page caching.
  2190. .SS NFS clients returning ESTALE / Stale file handle
  2191. .PP
  2192. NFS does not like out of band changes.
  2193. That is especially true of inode values.
  2194. .PP
  2195. Be sure to use the following options:
  2196. .IP \[bu] 2
  2197. noforget
  2198. .IP \[bu] 2
  2199. inodecalc=path-hash
  2200. .SS rtorrent fails with ENODEV (No such device)
  2201. .PP
  2202. Be sure to set \f[C]cache.files=partial|full|auto-full|per-processe\f[R]
  2203. or turn off \f[C]direct_io\f[R].
  2204. rtorrent and some other applications use
  2205. mmap (http://linux.die.net/man/2/mmap) to read and write to files and
  2206. offer no fallback to traditional methods.
  2207. FUSE does not currently support mmap while using \f[C]direct_io\f[R].
  2208. There may be a performance penalty on writes with \f[C]direct_io\f[R]
  2209. off as well as the problem of double caching but it\[cq]s the only way
  2210. to get such applications to work.
  2211. If the performance loss is too high for other apps you can mount
  2212. mergerfs twice.
  2213. Once with \f[C]direct_io\f[R] enabled and one without it.
  2214. Be sure to set \f[C]dropcacheonclose=true\f[R] if not using
  2215. \f[C]direct_io\f[R].
  2216. .SS Plex doesn\[cq]t work with mergerfs
  2217. .PP
  2218. It does.
  2219. If you\[cq]re trying to put Plex\[cq]s config / metadata / database on
  2220. mergerfs you can\[cq]t set \f[C]cache.files=off\f[R] because Plex is
  2221. using sqlite3 with mmap enabled.
  2222. Shared mmap is not supported by Linux\[cq]s FUSE implementation when
  2223. page caching is disabled.
  2224. To fix this place the data elsewhere (preferable) or enable
  2225. \f[C]cache.files\f[R] (with \f[C]dropcacheonclose=true\f[R]).
  2226. Sqlite3 does not need mmap but the developer needs to fall back to
  2227. standard IO if mmap fails.
  2228. .PP
  2229. This applies to other software: Radarr, Sonarr, Lidarr, Jellyfin, etc.
  2230. .PP
  2231. I would recommend reaching out to the developers of the software
  2232. you\[cq]re having troubles with and asking them to add a fallback to
  2233. regular file IO when mmap is unavailable.
  2234. .PP
  2235. If the issue is that scanning doesn\[cq]t seem to pick up media then be
  2236. sure to set \f[C]func.getattr=newest\f[R] though generally a full scan
  2237. will pick up all media anyway.
  2238. .SS When a program tries to move or rename a file it fails
  2239. .PP
  2240. Please read the section above regarding rename & link.
  2241. .PP
  2242. The problem is that many applications do not properly handle
  2243. \f[C]EXDEV\f[R] errors which \f[C]rename\f[R] and \f[C]link\f[R] may
  2244. return even though they are perfectly valid situations which do not
  2245. indicate actual drive or OS errors.
  2246. The error will only be returned by mergerfs if using a path preserving
  2247. policy as described in the policy section above.
  2248. If you do not care about path preservation simply change the mergerfs
  2249. policy to the non-path preserving version.
  2250. For example: \f[C]-o category.create=mfs\f[R]
  2251. .PP
  2252. Ideally the offending software would be fixed and it is recommended that
  2253. if you run into this problem you contact the software\[cq]s author and
  2254. request proper handling of \f[C]EXDEV\f[R] errors.
  2255. .SS my 32bit software has problems
  2256. .PP
  2257. Some software have problems with 64bit inode values.
  2258. The symptoms can include EOVERFLOW errors when trying to list files.
  2259. You can address this by setting \f[C]inodecalc\f[R] to one of the 32bit
  2260. based algos as described in the relevant section.
  2261. .SS Samba: Moving files / directories fails
  2262. .PP
  2263. Workaround: Copy the file/directory and then remove the original rather
  2264. than move.
  2265. .PP
  2266. This isn\[cq]t an issue with Samba but some SMB clients.
  2267. GVFS-fuse v1.20.3 and prior (found in Ubuntu 14.04 among others) failed
  2268. to handle certain error codes correctly.
  2269. Particularly \f[B]STATUS_NOT_SAME_DEVICE\f[R] which comes from the
  2270. \f[B]EXDEV\f[R] which is returned by \f[B]rename\f[R] when the call is
  2271. crossing mount points.
  2272. When a program gets an \f[B]EXDEV\f[R] it needs to explicitly take an
  2273. alternate action to accomplish its goal.
  2274. In the case of \f[B]mv\f[R] or similar it tries \f[B]rename\f[R] and on
  2275. \f[B]EXDEV\f[R] falls back to a manual copying of data between the two
  2276. locations and unlinking the source.
  2277. In these older versions of GVFS-fuse if it received \f[B]EXDEV\f[R] it
  2278. would translate that into \f[B]EIO\f[R].
  2279. This would cause \f[B]mv\f[R] or most any application attempting to move
  2280. files around on that SMB share to fail with a IO error.
  2281. .PP
  2282. GVFS-fuse v1.22.0 (https://bugzilla.gnome.org/show_bug.cgi?id=734568)
  2283. and above fixed this issue but a large number of systems use the older
  2284. release.
  2285. On Ubuntu the version can be checked by issuing
  2286. \f[C]apt-cache showpkg gvfs-fuse\f[R].
  2287. Most distros released in 2015 seem to have the updated release and will
  2288. work fine but older systems may not.
  2289. Upgrading gvfs-fuse or the distro in general will address the problem.
  2290. .PP
  2291. In Apple\[cq]s MacOSX 10.9 they replaced Samba (client and server) with
  2292. their own product.
  2293. It appears their new client does not handle \f[B]EXDEV\f[R] either and
  2294. responds similar to older release of gvfs on Linux.
  2295. .SS Trashing files occasionally fails
  2296. .PP
  2297. This is the same issue as with Samba.
  2298. \f[C]rename\f[R] returns \f[C]EXDEV\f[R] (in our case that will really
  2299. only happen with path preserving policies like \f[C]epmfs\f[R]) and the
  2300. software doesn\[cq]t handle the situation well.
  2301. This is unfortunately a common failure of software which moves files
  2302. around.
  2303. The standard indicates that an implementation \f[C]MAY\f[R] choose to
  2304. support non-user home directory trashing of files (which is a
  2305. \f[C]MUST\f[R]).
  2306. The implementation \f[C]MAY\f[R] also support \[lq]top directory
  2307. trashes\[rq] which many probably do.
  2308. .PP
  2309. To create a \f[C]$topdir/.Trash\f[R] directory as defined in the
  2310. standard use the
  2311. mergerfs-tools (https://github.com/trapexit/mergerfs-tools) tool
  2312. \f[C]mergerfs.mktrash\f[R].
  2313. .SS Supplemental user groups
  2314. .PP
  2315. Due to the overhead of
  2316. getgroups/setgroups (http://linux.die.net/man/2/setgroups) mergerfs
  2317. utilizes a cache.
  2318. This cache is opportunistic and per thread.
  2319. Each thread will query the supplemental groups for a user when that
  2320. particular thread needs to change credentials and will keep that data
  2321. for the lifetime of the thread.
  2322. This means that if a user is added to a group it may not be picked up
  2323. without the restart of mergerfs.
  2324. However, since the high level FUSE API\[cq]s (at least the standard
  2325. version) thread pool dynamically grows and shrinks it\[cq]s possible
  2326. that over time a thread will be killed and later a new thread with no
  2327. cache will start and query the new data.
  2328. .PP
  2329. The gid cache uses fixed storage to simplify the design and be
  2330. compatible with older systems which may not have C++11 compilers.
  2331. There is enough storage for 256 users\[cq] supplemental groups.
  2332. Each user is allowed up to 32 supplemental groups.
  2333. Linux >= 2.6.3 allows up to 65535 groups per user but most other *nixs
  2334. allow far less.
  2335. NFS allowing only 16.
  2336. The system does handle overflow gracefully.
  2337. If the user has more than 32 supplemental groups only the first 32 will
  2338. be used.
  2339. If more than 256 users are using the system when an uncached user is
  2340. found it will evict an existing user\[cq]s cache at random.
  2341. So long as there aren\[cq]t more than 256 active users this should be
  2342. fine.
  2343. If either value is too low for your needs you will have to modify
  2344. \f[C]gidcache.hpp\f[R] to increase the values.
  2345. Note that doing so will increase the memory needed by each thread.
  2346. .PP
  2347. While not a bug some users have found when using containers that
  2348. supplemental groups defined inside the container don\[cq]t work properly
  2349. with regard to permissions.
  2350. This is expected as mergerfs lives outside the container and therefore
  2351. is querying the host\[cq]s group database.
  2352. There might be a hack to work around this (make mergerfs read the
  2353. /etc/group file in the container) but it is not yet implemented and
  2354. would be limited to Linux and the /etc/group DB.
  2355. Preferably users would mount in the host group file into the containers
  2356. or use a standard shared user & groups technology like NIS or LDAP.
  2357. .SH FAQ
  2358. .SS How well does mergerfs scale? Is it \[lq]production ready?\[rq]
  2359. .PP
  2360. Users have reported running mergerfs on everything from a Raspberry Pi
  2361. to dual socket Xeon systems with >20 cores.
  2362. I\[cq]m aware of at least a few companies which use mergerfs in
  2363. production.
  2364. Open Media Vault (https://www.openmediavault.org) includes mergerfs as
  2365. its sole solution for pooling drives.
  2366. The author of mergerfs had it running for over 300 days managing 16+
  2367. drives with reasonably heavy 24/7 read and write usage.
  2368. Stopping only after the machine\[cq]s power supply died.
  2369. .PP
  2370. Most serious issues (crashes or data corruption) have been due to kernel
  2371. bugs (https://github.com/trapexit/mergerfs/wiki/Kernel-Issues-&-Bugs).
  2372. All of which are fixed in stable releases.
  2373. .SS Can mergerfs be used with drives which already have data / are in use?
  2374. .PP
  2375. Yes.
  2376. MergerFS is a proxy and does \f[B]NOT\f[R] interfere with the normal
  2377. form or function of the drives / mounts / paths it manages.
  2378. .PP
  2379. MergerFS is \f[B]not\f[R] a traditional filesystem.
  2380. MergerFS is \f[B]not\f[R] RAID.
  2381. It does \f[B]not\f[R] manipulate the data that passes through it.
  2382. It does \f[B]not\f[R] shard data across drives.
  2383. It merely shards some \f[B]behavior\f[R] and aggregates others.
  2384. .SS Can mergerfs be removed without affecting the data?
  2385. .PP
  2386. See the previous question\[cq]s answer.
  2387. .SS What policies should I use?
  2388. .PP
  2389. Unless you\[cq]re doing something more niche the average user is
  2390. probably best off using \f[C]mfs\f[R] for \f[C]category.create\f[R].
  2391. It will spread files out across your branches based on available space.
  2392. Use \f[C]mspmfs\f[R] if you want to try to colocate the data a bit more.
  2393. You may want to use \f[C]lus\f[R] if you prefer a slightly different
  2394. distribution of data if you have a mix of smaller and larger drives.
  2395. Generally though \f[C]mfs\f[R], \f[C]lus\f[R], or even \f[C]rand\f[R]
  2396. are good for the general use case.
  2397. If you are starting with an imbalanced pool you can use the tool
  2398. \f[B]mergerfs.balance\f[R] to redistribute files across the pool.
  2399. .PP
  2400. If you really wish to try to colocate files based on directory you can
  2401. set \f[C]func.create\f[R] to \f[C]epmfs\f[R] or similar and
  2402. \f[C]func.mkdir\f[R] to \f[C]rand\f[R] or \f[C]eprand\f[R] depending on
  2403. if you just want to colocate generally or on specific branches.
  2404. Either way the \f[I]need\f[R] to colocate is rare.
  2405. For instance: if you wish to remove the drive regularly and want the
  2406. data to predictably be on that drive or if you don\[cq]t use backup at
  2407. all and don\[cq]t wish to replace that data piecemeal.
  2408. In which case using path preservation can help but will require some
  2409. manual attention.
  2410. Colocating after the fact can be accomplished using the
  2411. \f[B]mergerfs.consolidate\f[R] tool.
  2412. If you don\[cq]t need strict colocation which the \f[C]ep\f[R] policies
  2413. provide then you can use the \f[C]msp\f[R] based policies which will
  2414. walk back the path till finding a branch that works.
  2415. .PP
  2416. Ultimately there is no correct answer.
  2417. It is a preference or based on some particular need.
  2418. mergerfs is very easy to test and experiment with.
  2419. I suggest creating a test setup and experimenting to get a sense of what
  2420. you want.
  2421. .PP
  2422. The reason \f[C]mfs\f[R] is not the default \f[C]category.create\f[R]
  2423. policy is historical.
  2424. When/if a 3.X gets released it will be changed to minimize confusion
  2425. people often have with path preserving policies.
  2426. .SS What settings should I use?
  2427. .PP
  2428. Depends on what features you want.
  2429. Generally speaking there are no \[lq]wrong\[rq] settings.
  2430. All settings are performance or feature related.
  2431. The best bet is to read over the available options and choose what fits
  2432. your situation.
  2433. If something isn\[cq]t clear from the documentation please reach out and
  2434. the documentation will be improved.
  2435. .PP
  2436. That said, for the average person, the following should be fine:
  2437. .PP
  2438. \f[C]cache.files=off,dropcacheonclose=true,category.create=mfs\f[R]
  2439. .SS Why are all my files ending up on 1 drive?!
  2440. .PP
  2441. Did you start with empty drives?
  2442. Did you explicitly configure a \f[C]category.create\f[R] policy?
  2443. Are you using an \f[C]existing path\f[R] / \f[C]path preserving\f[R]
  2444. policy?
  2445. .PP
  2446. The default create policy is \f[C]epmfs\f[R].
  2447. That is a path preserving algorithm.
  2448. With such a policy for \f[C]mkdir\f[R] and \f[C]create\f[R] with a set
  2449. of empty drives it will select only 1 drive when the first directory is
  2450. created.
  2451. Anything, files or directories, created in that first directory will be
  2452. placed on the same branch because it is preserving paths.
  2453. .PP
  2454. This catches a lot of new users off guard but changing the default would
  2455. break the setup for many existing users.
  2456. If you do not care about path preservation and wish your files to be
  2457. spread across all your drives change to \f[C]mfs\f[R] or similar policy
  2458. as described above.
  2459. If you do want path preservation you\[cq]ll need to perform the manual
  2460. act of creating paths on the drives you want the data to land on before
  2461. transferring your data.
  2462. Setting \f[C]func.mkdir=epall\f[R] can simplify managing path
  2463. preservation for \f[C]create\f[R].
  2464. Or use \f[C]func.mkdir=rand\f[R] if you\[cq]re interested in just
  2465. grouping together directory content by drive.
  2466. .SS Do hardlinks work?
  2467. .PP
  2468. Yes.
  2469. See also the option \f[C]inodecalc\f[R] for how inode values are
  2470. calculated.
  2471. .PP
  2472. What mergerfs does not do is fake hard links across branches.
  2473. Read the section \[lq]rename & link\[rq] for how it works.
  2474. .PP
  2475. Remember that hardlinks will NOT work across devices.
  2476. That includes between the original filesystem and a mergerfs pool,
  2477. between two separate pools of the same underlying filesystems, or bind
  2478. mounts of paths within the mergerfs pool.
  2479. The latter is common when using Docker or Podman.
  2480. Multiple volumes (bind mounts) to the same underlying filesystem are
  2481. considered different devices.
  2482. There is no way to link between them.
  2483. You should mount in the highest directory in the mergerfs pool that
  2484. includes all the paths you need if you want links to work.
  2485. .SS Can I use mergerfs without SnapRAID? SnapRAID without mergerfs?
  2486. .PP
  2487. Yes.
  2488. They are completely unrelated pieces of software.
  2489. .SS Can mergerfs run via Docker, Podman, Kubernetes, etc.
  2490. .PP
  2491. Yes.
  2492. With Docker you\[cq]ll need to include
  2493. \f[C]--cap-add=SYS_ADMIN --device=/dev/fuse --security-opt=apparmor:unconfined\f[R]
  2494. or similar with other container runtimes.
  2495. You should also be running it as root or given sufficient caps to change
  2496. user and group identity as well as have root like filesystem
  2497. permissions.
  2498. .PP
  2499. Keep in mind that you \f[B]MUST\f[R] consider identity when using
  2500. containers.
  2501. For example: supplemental groups will be picked up from the container
  2502. unless you properly manage users and groups by sharing relevant /etc
  2503. files or by using some other means to share identity across containers.
  2504. Similarly if you use \[lq]rootless\[rq] containers and user namespaces
  2505. to do uid/gid translations you \f[B]MUST\f[R] consider that while
  2506. managing shared files.
  2507. .PP
  2508. Also, as mentioned by hotio (https://hotio.dev/containers/mergerfs),
  2509. with Docker you should probably be mounting with
  2510. \f[C]bind-propagation\f[R] set to \f[C]slave\f[R].
  2511. .SS Does mergerfs support CoW / copy-on-write / writes to read-only filesystems?
  2512. .PP
  2513. Not in the sense of a filesystem like BTRFS or ZFS nor in the overlayfs
  2514. or aufs sense.
  2515. It does offer a
  2516. cow-shell (http://manpages.ubuntu.com/manpages/bionic/man1/cow-shell.1.html)
  2517. like hard link breaking (copy to temp file then rename over original)
  2518. which can be useful when wanting to save space by hardlinking duplicate
  2519. files but wish to treat each name as if it were a unique and separate
  2520. file.
  2521. .PP
  2522. If you want to write to a read-only filesystem you should look at
  2523. overlayfs.
  2524. You can always include the overlayfs mount into a mergerfs pool.
  2525. .SS Why can\[cq]t I see my files / directories?
  2526. .PP
  2527. It\[cq]s almost always a permissions issue.
  2528. Unlike mhddfs and unionfs-fuse, which runs as root and attempts to
  2529. access content as such, mergerfs always changes its credentials to that
  2530. of the caller.
  2531. This means that if the user does not have access to a file or directory
  2532. than neither will mergerfs.
  2533. However, because mergerfs is creating a union of paths it may be able to
  2534. read some files and directories on one drive but not another resulting
  2535. in an incomplete set.
  2536. .PP
  2537. Whenever you run into a split permission issue (seeing some but not all
  2538. files) try using
  2539. mergerfs.fsck (https://github.com/trapexit/mergerfs-tools) tool to check
  2540. for and fix the mismatch.
  2541. If you aren\[cq]t seeing anything at all be sure that the basic
  2542. permissions are correct.
  2543. The user and group values are correct and that directories have their
  2544. executable bit set.
  2545. A common mistake by users new to Linux is to \f[C]chmod -R 644\f[R] when
  2546. they should have \f[C]chmod -R u=rwX,go=rX\f[R].
  2547. .PP
  2548. If using a network filesystem such as NFS, SMB, CIFS (Samba) be sure to
  2549. pay close attention to anything regarding permissioning and users.
  2550. Root squashing and user translation for instance has bitten a few
  2551. mergerfs users.
  2552. Some of these also affect the use of mergerfs from container platforms
  2553. such as Docker.
  2554. .SS Why use FUSE? Why not a kernel based solution?
  2555. .PP
  2556. As with any solutions to a problem there are advantages and
  2557. disadvantages to each one.
  2558. .PP
  2559. A FUSE based solution has all the downsides of FUSE:
  2560. .IP \[bu] 2
  2561. Higher IO latency due to the trips in and out of kernel space
  2562. .IP \[bu] 2
  2563. Higher general overhead due to trips in and out of kernel space
  2564. .IP \[bu] 2
  2565. Double caching when using page caching
  2566. .IP \[bu] 2
  2567. Misc limitations due to FUSE\[cq]s design
  2568. .PP
  2569. But FUSE also has a lot of upsides:
  2570. .IP \[bu] 2
  2571. Easier to offer a cross platform solution
  2572. .IP \[bu] 2
  2573. Easier forward and backward compatibility
  2574. .IP \[bu] 2
  2575. Easier updates for users
  2576. .IP \[bu] 2
  2577. Easier and faster release cadence
  2578. .IP \[bu] 2
  2579. Allows more flexibility in design and features
  2580. .IP \[bu] 2
  2581. Overall easier to write, secure, and maintain
  2582. .IP \[bu] 2
  2583. Much lower barrier to entry (getting code into the kernel takes a lot of
  2584. time and effort initially)
  2585. .PP
  2586. FUSE was chosen because of all the advantages listed above.
  2587. The negatives of FUSE do not outweigh the positives.
  2588. .SS Is my OS\[cq]s libfuse needed for mergerfs to work?
  2589. .PP
  2590. No.\ Normally \f[C]mount.fuse\f[R] is needed to get mergerfs (or any
  2591. FUSE filesystem to mount using the \f[C]mount\f[R] command but in
  2592. vendoring the libfuse library the \f[C]mount.fuse\f[R] app has been
  2593. renamed to \f[C]mount.mergerfs\f[R] meaning the filesystem type in
  2594. \f[C]fstab\f[R] can simply be \f[C]mergerfs\f[R].
  2595. That said there should be no harm in having it installed and continuing
  2596. to using \f[C]fuse.mergerfs\f[R] as the type in \f[C]/etc/fstab\f[R].
  2597. .PP
  2598. If \f[C]mergerfs\f[R] doesn\[cq]t work as a type it could be due to how
  2599. the \f[C]mount.mergerfs\f[R] tool was installed.
  2600. Must be in \f[C]/sbin/\f[R] with proper permissions.
  2601. .SS Why was splice support removed?
  2602. .PP
  2603. After a lot of testing over the years splicing always appeared to be at
  2604. best provide equivalent performance and in cases worse performance.
  2605. Splice is not supported on other platforms forcing a traditional
  2606. read/write fallback to be provided.
  2607. The splice code was removed to simplify the codebase.
  2608. .SS Why use mergerfs over mhddfs?
  2609. .PP
  2610. mhddfs is no longer maintained and has some known stability and security
  2611. issues (see below).
  2612. MergerFS provides a superset of mhddfs\[cq] features and should offer
  2613. the same or maybe better performance.
  2614. .PP
  2615. Below is an example of mhddfs and mergerfs setup to work similarly.
  2616. .PP
  2617. \f[C]mhddfs -o mlimit=4G,allow_other /mnt/drive1,/mnt/drive2 /mnt/pool\f[R]
  2618. .PP
  2619. \f[C]mergerfs -o minfreespace=4G,category.create=ff /mnt/drive1:/mnt/drive2 /mnt/pool\f[R]
  2620. .SS Why use mergerfs over aufs?
  2621. .PP
  2622. aufs is mostly abandoned and no longer available in many distros.
  2623. .PP
  2624. While aufs can offer better peak performance mergerfs provides more
  2625. configurability and is generally easier to use.
  2626. mergerfs however does not offer the overlay / copy-on-write (CoW)
  2627. features which aufs and overlayfs have.
  2628. .SS Why use mergerfs over unionfs?
  2629. .PP
  2630. UnionFS is more like aufs than mergerfs in that it offers overlay / CoW
  2631. features.
  2632. If you\[cq]re just looking to create a union of drives and want
  2633. flexibility in file/directory placement then mergerfs offers that
  2634. whereas unionfs is more for overlaying RW filesystems over RO ones.
  2635. .SS Why use mergerfs over overlayfs?
  2636. .PP
  2637. Same reasons as with unionfs.
  2638. .SS Why use mergerfs over LVM/ZFS/BTRFS/RAID0 drive concatenation / striping?
  2639. .PP
  2640. With simple JBOD / drive concatenation / stripping / RAID0 a single
  2641. drive failure will result in full pool failure.
  2642. mergerfs performs a similar function without the possibility of
  2643. catastrophic failure and the difficulties in recovery.
  2644. Drives may fail, however, all other data will continue to be accessible.
  2645. .PP
  2646. When combined with something like SnapRaid (http://www.snapraid.it)
  2647. and/or an offsite backup solution you can have the flexibility of JBOD
  2648. without the single point of failure.
  2649. .SS Why use mergerfs over ZFS?
  2650. .PP
  2651. MergerFS is not intended to be a replacement for ZFS.
  2652. MergerFS is intended to provide flexible pooling of arbitrary drives
  2653. (local or remote), of arbitrary sizes, and arbitrary filesystems.
  2654. For \f[C]write once, read many\f[R] usecases such as bulk media storage.
  2655. Where data integrity and backup is managed in other ways.
  2656. In that situation ZFS can introduce a number of costs and limitations as
  2657. described
  2658. here (http://louwrentius.com/the-hidden-cost-of-using-zfs-for-your-home-nas.html),
  2659. here (https://markmcb.com/2020/01/07/five-years-of-btrfs/), and
  2660. here (https://utcc.utoronto.ca/~cks/space/blog/solaris/ZFSWhyNoRealReshaping).
  2661. .SS Why use mergerfs over UnRAID?
  2662. .PP
  2663. UnRAID is a full OS and its storage layer, as I understand, is
  2664. proprietary and closed source.
  2665. Users who have experience with both have said they prefer the
  2666. flexibility offered by mergerfs and for some the fact it is free and
  2667. open source is important.
  2668. .PP
  2669. There are a number of UnRAID users who use mergerfs as well though
  2670. I\[cq]m not entirely familiar with the use case.
  2671. .SS What should mergerfs NOT be used for?
  2672. .IP \[bu] 2
  2673. databases: Even if the database stored data in separate files (mergerfs
  2674. wouldn\[cq]t offer much otherwise) the higher latency of the indirection
  2675. will kill performance.
  2676. If it is a lightly used SQLITE database then it may be fine but
  2677. you\[cq]ll need to test.
  2678. .IP \[bu] 2
  2679. VM images: For the same reasons as databases.
  2680. VM images are accessed very aggressively and mergerfs will introduce too
  2681. much latency (if it works at all).
  2682. .IP \[bu] 2
  2683. As replacement for RAID: mergerfs is just for pooling branches.
  2684. If you need that kind of device performance aggregation or high
  2685. availability you should stick with RAID.
  2686. .SS Can drives be written to directly? Outside of mergerfs while pooled?
  2687. .PP
  2688. Yes, however it\[cq]s not recommended to use the same file from within
  2689. the pool and from without at the same time (particularly writing).
  2690. Especially if using caching of any kind (cache.files, cache.entry,
  2691. cache.attr, cache.negative_entry, cache.symlinks, cache.readdir, etc.)
  2692. as there could be a conflict between cached data and not.
  2693. .SS Why do I get an \[lq]out of space\[rq] / \[lq]no space left on device\[rq] / ENOSPC error even though there appears to be lots of space available?
  2694. .PP
  2695. First make sure you\[cq]ve read the sections above about policies, path
  2696. preservation, branch filtering, and the options \f[B]minfreespace\f[R],
  2697. \f[B]moveonenospc\f[R], \f[B]statfs\f[R], and \f[B]statfs_ignore\f[R].
  2698. .PP
  2699. mergerfs is simply presenting a union of the content within multiple
  2700. branches.
  2701. The reported free space is an aggregate of space available within the
  2702. pool (behavior modified by \f[B]statfs\f[R] and
  2703. \f[B]statfs_ignore\f[R]).
  2704. It does not represent a contiguous space.
  2705. In the same way that read-only filesystems, those with quotas, or
  2706. reserved space report the full theoretical space available.
  2707. .PP
  2708. Due to path preservation, branch tagging, read-only status, and
  2709. \f[B]minfreespace\f[R] settings it is perfectly valid that
  2710. \f[C]ENOSPC\f[R] / \[lq]out of space\[rq] / \[lq]no space left on
  2711. device\[rq] be returned.
  2712. It is doing what was asked of it: filtering possible branches due to
  2713. those settings.
  2714. Only one error can be returned and if one of the reasons for filtering a
  2715. branch was \f[B]minfreespace\f[R] then it will be returned as such.
  2716. \f[B]moveonenospc\f[R] is only relevant to writing a file which is too
  2717. large for the drive its currently on.
  2718. .PP
  2719. It is also possible that the filesystem selected has run out of inodes.
  2720. Use \f[C]df -i\f[R] to list the total and available inodes per
  2721. filesystem.
  2722. .PP
  2723. If you don\[cq]t care about path preservation then simply change the
  2724. \f[C]create\f[R] policy to one which isn\[cq]t.
  2725. \f[C]mfs\f[R] is probably what most are looking for.
  2726. The reason it\[cq]s not default is because it was originally set to
  2727. \f[C]epmfs\f[R] and changing it now would change people\[cq]s setup.
  2728. Such a setting change will likely occur in mergerfs 3.
  2729. .SS Why does the total available space in mergerfs not equal outside?
  2730. .PP
  2731. Are you using ext2/3/4?
  2732. With reserve for root?
  2733. mergerfs uses available space for statfs calculations.
  2734. If you\[cq]ve reserved space for root then it won\[cq]t show up.
  2735. .PP
  2736. You can remove the reserve by running: \f[C]tune2fs -m 0 <device>\f[R]
  2737. .SS Can mergerfs mounts be exported over NFS?
  2738. .PP
  2739. Yes, however if you do anything which may changes files out of band
  2740. (including for example using the \f[C]newest\f[R] policy) it will result
  2741. in \[lq]stale file handle\[rq] errors unless properly setup.
  2742. .PP
  2743. Be sure to use the following options:
  2744. .IP \[bu] 2
  2745. noforget
  2746. .IP \[bu] 2
  2747. inodecalc=path-hash
  2748. .SS Can mergerfs mounts be exported over Samba / SMB?
  2749. .PP
  2750. Yes.
  2751. While some users have reported problems it appears to always be related
  2752. to how Samba is setup in relation to permissions.
  2753. .SS Can mergerfs mounts be used over SSHFS?
  2754. .PP
  2755. Yes.
  2756. .SS I notice massive slowdowns of writes when enabling cache.files.
  2757. .PP
  2758. When file caching is enabled in any form (\f[C]cache.files!=off\f[R] or
  2759. \f[C]direct_io=false\f[R]) it will issue \f[C]getxattr\f[R] requests for
  2760. \f[C]security.capability\f[R] prior to \f[I]every single write\f[R].
  2761. This will usually result in a performance degradation, especially when
  2762. using a network filesystem (such as NFS or CIFS/SMB/Samba.)
  2763. Unfortunately at this moment the kernel is not caching the response.
  2764. .PP
  2765. To work around this situation mergerfs offers a few solutions.
  2766. .IP "1." 3
  2767. Set \f[C]security_capability=false\f[R].
  2768. It will short circuit any call and return \f[C]ENOATTR\f[R].
  2769. This still means though that mergerfs will receive the request before
  2770. every write but at least it doesn\[cq]t get passed through to the
  2771. underlying filesystem.
  2772. .IP "2." 3
  2773. Set \f[C]xattr=noattr\f[R].
  2774. Same as above but applies to \f[I]all\f[R] calls to getxattr.
  2775. Not just \f[C]security.capability\f[R].
  2776. This will not be cached by the kernel either but mergerfs\[cq] runtime
  2777. config system will still function.
  2778. .IP "3." 3
  2779. Set \f[C]xattr=nosys\f[R].
  2780. Results in mergerfs returning \f[C]ENOSYS\f[R] which \f[I]will\f[R] be
  2781. cached by the kernel.
  2782. No future xattr calls will be forwarded to mergerfs.
  2783. The downside is that also means the xattr based config and query
  2784. functionality won\[cq]t work either.
  2785. .IP "4." 3
  2786. Disable file caching.
  2787. If you aren\[cq]t using applications which use \f[C]mmap\f[R] it\[cq]s
  2788. probably simpler to just disable it all together.
  2789. The kernel won\[cq]t send the requests when caching is disabled.
  2790. .SS It\[cq]s mentioned that there are some security issues with mhddfs. What are they? How does mergerfs address them?
  2791. .PP
  2792. mhddfs (https://github.com/trapexit/mhddfs) manages running as
  2793. \f[B]root\f[R] by calling
  2794. getuid() (https://github.com/trapexit/mhddfs/blob/cae96e6251dd91e2bdc24800b4a18a74044f6672/src/main.c#L319)
  2795. and if it returns \f[B]0\f[R] then it will
  2796. chown (http://linux.die.net/man/1/chown) the file.
  2797. Not only is that a race condition but it doesn\[cq]t handle other
  2798. situations.
  2799. Rather than attempting to simulate POSIX ACL behavior the proper way to
  2800. manage this is to use seteuid (http://linux.die.net/man/2/seteuid) and
  2801. setegid (http://linux.die.net/man/2/setegid), in effect becoming the
  2802. user making the original call, and perform the action as them.
  2803. This is what mergerfs does and why mergerfs should always run as root.
  2804. .PP
  2805. In Linux setreuid syscalls apply only to the thread.
  2806. GLIBC hides this away by using realtime signals to inform all threads to
  2807. change credentials.
  2808. Taking after \f[B]Samba\f[R], mergerfs uses
  2809. \f[B]syscall(SYS_setreuid,\&...)\f[R] to set the callers credentials for
  2810. that thread only.
  2811. Jumping back to \f[B]root\f[R] as necessary should escalated privileges
  2812. be needed (for instance: to clone paths between drives).
  2813. .PP
  2814. For non-Linux systems mergerfs uses a read-write lock and changes
  2815. credentials only when necessary.
  2816. If multiple threads are to be user X then only the first one will need
  2817. to change the processes credentials.
  2818. So long as the other threads need to be user X they will take a readlock
  2819. allowing multiple threads to share the credentials.
  2820. Once a request comes in to run as user Y that thread will attempt a
  2821. write lock and change to Y\[cq]s credentials when it can.
  2822. If the ability to give writers priority is supported then that flag will
  2823. be used so threads trying to change credentials don\[cq]t starve.
  2824. This isn\[cq]t the best solution but should work reasonably well
  2825. assuming there are few users.
  2826. .SH SUPPORT
  2827. .PP
  2828. Filesystems are complex and difficult to debug.
  2829. mergerfs, while being just a proxy of sorts, can be difficult to debug
  2830. given the large number of possible settings it can have itself and the
  2831. number of environments it can run in.
  2832. When reporting on a suspected issue \f[B]please\f[R] include as much of
  2833. the below information as possible otherwise it will be difficult or
  2834. impossible to diagnose.
  2835. Also please read the above documentation as it provides details on many
  2836. previously encountered questions/issues.
  2837. .PP
  2838. \f[B]Please make sure you are using the latest
  2839. release (https://github.com/trapexit/mergerfs/releases) or have tried it
  2840. in comparison. Old versions, which are often included in distros like
  2841. Debian and Ubuntu, are not ever going to be updated and the issue you
  2842. are encountering may have been addressed already.\f[R]
  2843. .PP
  2844. \f[B]For commercial support or feature requests please contact me
  2845. directly. (mailto:support@spawn.link)\f[R]
  2846. .SS Information to include in bug reports
  2847. .IP \[bu] 2
  2848. Information about the broader problem along with any attempted
  2849. solutions. (https://xyproblem.info)
  2850. .IP \[bu] 2
  2851. Solution already ruled out and why.
  2852. .IP \[bu] 2
  2853. Version of mergerfs: \f[C]mergerfs --version\f[R]
  2854. .IP \[bu] 2
  2855. mergerfs settings / arguments: from fstab, systemd unit, command line,
  2856. OMV plugin, etc.
  2857. .IP \[bu] 2
  2858. Version of the OS: \f[C]uname -a\f[R] and \f[C]lsb_release -a\f[R]
  2859. .IP \[bu] 2
  2860. List of branches, their filesystem types, sizes (before and after
  2861. issue): \f[C]df -h\f[R]
  2862. .IP \[bu] 2
  2863. \f[B]All\f[R] information about the relevant paths and files:
  2864. permissions, ownership, etc.
  2865. .IP \[bu] 2
  2866. \f[B]All\f[R] information about the client app making the requests:
  2867. version, uid/gid
  2868. .IP \[bu] 2
  2869. Runtime environment:
  2870. .RS 2
  2871. .IP \[bu] 2
  2872. Is mergerfs running within a container?
  2873. .IP \[bu] 2
  2874. Are the client apps using mergerfs running in a container?
  2875. .RE
  2876. .IP \[bu] 2
  2877. A \f[C]strace\f[R] of the app having problems:
  2878. .RS 2
  2879. .IP \[bu] 2
  2880. \f[C]strace -fvTtt -s 256 -o /tmp/app.strace.txt <cmd>\f[R]
  2881. .RE
  2882. .IP \[bu] 2
  2883. A \f[C]strace\f[R] of mergerfs while the program is trying to do
  2884. whatever it is failing to do:
  2885. .RS 2
  2886. .IP \[bu] 2
  2887. \f[C]strace -fvTtt -s 256 -p <mergerfsPID> -o /tmp/mergerfs.strace.txt\f[R]
  2888. .RE
  2889. .IP \[bu] 2
  2890. \f[B]Precise\f[R] directions on replicating the issue.
  2891. Do not leave \f[B]anything\f[R] out.
  2892. .IP \[bu] 2
  2893. Try to recreate the problem in the simplest way using standard programs:
  2894. \f[C]ln\f[R], \f[C]mv\f[R], \f[C]cp\f[R], \f[C]ls\f[R], \f[C]dd\f[R],
  2895. etc.
  2896. .SS Contact / Issue submission
  2897. .IP \[bu] 2
  2898. github.com: https://github.com/trapexit/mergerfs/issues
  2899. .IP \[bu] 2
  2900. discord: https://discord.gg/MpAr69V
  2901. .IP \[bu] 2
  2902. reddit: https://www.reddit.com/r/mergerfs
  2903. .SS Donations
  2904. .PP
  2905. https://github.com/trapexit/support
  2906. .PP
  2907. Development and support of a project like mergerfs requires a
  2908. significant amount of time and effort.
  2909. The software is released under the very liberal ISC license and is
  2910. therefore free to use for personal or commercial uses.
  2911. .PP
  2912. If you are a personal user and find mergerfs and its support valuable
  2913. and would like to support the project financially it would be very much
  2914. appreciated.
  2915. .PP
  2916. If you are using mergerfs commercially please consider sponsoring the
  2917. project to ensure it continues to be maintained and receive updates.
  2918. If custom features are needed feel free to contact me
  2919. directly (mailto:support@spawn.link).
  2920. .SH LINKS
  2921. .IP \[bu] 2
  2922. https://spawn.link
  2923. .IP \[bu] 2
  2924. https://github.com/trapexit/mergerfs
  2925. .IP \[bu] 2
  2926. https://github.com/trapexit/mergerfs/wiki
  2927. .IP \[bu] 2
  2928. https://github.com/trapexit/mergerfs-tools
  2929. .IP \[bu] 2
  2930. https://github.com/trapexit/scorch
  2931. .IP \[bu] 2
  2932. https://github.com/trapexit/bbf