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.

3079 lines
113 KiB

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