a featureful union filesystem https://trapexit.github.io/mergerfs/
Find a file
Antonio S. Musumeci 8f41b40692 Replace thread-removal lambda+promise with atomic counter
_remove_thread_scaling_locked previously enqueued a heap-allocated
lambda (capturing a shared_ptr<promise>) to signal a specific worker
to exit.  This had two problems:

1. Bug: if the 5-second future::wait_for timed out, the function
   returned -EBUSY but the lambda remained in the queue.  When a
   worker eventually executed it, it would unconditionally set
   _tl_should_exit and call _remove_self, silently killing an
   arbitrary thread with no compensating add.

2. Held _scaling_mutex for up to 5 seconds while blocking on the
   future, serializing all concurrent scaling operations (add_thread,
   remove_thread, _maybe_grow_on_pressure, monitor hill-climb).

Replace the entire mechanism with an atomic _remove_count counter.
_remove_thread_scaling_locked simply increments the counter and
returns immediately.  After each task, _process_func does a
CAS-decrement; the winning worker detaches itself via _remove_self
and exits.

This eliminates:
- All heap allocations (shared_ptr, promise, lambda captures)
- The thread-local _tl_should_exit flag
- The 5-second blocking window under _scaling_mutex
- The stale-lambda bug entirely (no lambda to go stale)
- The <memory> include (no longer needed)

During shutdown, _remove_self is a no-op (_stop is set), so a worker
that wins the CAS stays in _threads and is joined normally by the
destructor.  Any outstanding _remove_count credits are harmlessly
abandoned.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 00:50:25 -04:00
.github Update submitting bug reports, improve collect-info (#1598) 2025-12-06 13:55:14 -06:00
buildtools Detect OS for release-sample make target 2026-04-08 20:48:02 -05:00
debian Build improvements (#1501) 2025-08-04 23:39:52 -05:00
man Fix manpage links for 2.41.0-rc3 (#1555) 2025-10-29 12:07:49 -05:00
mkdocs Update docs on limiting drive spinup 2026-04-06 14:01:20 -05:00
src Misc updates and fixes 2026-04-04 02:46:24 -05:00
tests Add support for FUSE_COPY_FILE_RANGE_64 2026-04-01 23:20:05 -05:00
tools tools/preload: include correct extended attribute headers on FreeBSD (#1590) 2025-11-25 12:09:41 -06:00
vendored Replace thread-removal lambda+promise with atomic counter 2026-04-10 00:50:25 -04:00
.gitignore Build improvements (#1501) 2025-08-04 23:39:52 -05:00
DEPENDENCIES Update vendored/nonstd to latest and fix API usage 2026-03-02 01:09:16 -05:00
LICENSE Update copyright headers 2026-03-02 01:09:16 -05:00
Makefile Detect OS for release-sample make target 2026-04-08 20:48:02 -05:00
mergerfs.spec Build improvements (#1501) 2025-08-04 23:39:52 -05:00
README.md Fix some links in docs (#1582) 2025-11-18 08:35:27 -06:00

mergerfs - a featureful union filesystem

mergerfs is a FUSE based union filesystem geared towards simplifying storage and management of files across numerous commodity storage devices. It is similar to mhddfs, unionfs, aufs, DrivePool, etc.

Features

  • Logically combine numerous filesystems/paths into a single mount point (JBOFS: Just a Bunch of FileSystems)
  • Combine paths of the same or different filesystems
  • Ability to add or remove filesystems/paths without impacting the rest of the data
  • Unaffected by individual filesystem failure
  • Configurable file selection and creation placement
  • File IO passthrough for near native IO performance (where supported)
  • Works with filesystems of any size
  • Works with filesystems of almost any type
  • Ignore read-only filesystems when creating files
  • Hard links
  • Hard link copy-on-write / CoW
  • Runtime configurable
  • Support for extended attributes (xattrs)
  • Support for file attributes (chattr)
  • Support for POSIX ACLs

Non-features

  • Read/write overlay on top of read-only filesystem like OverlayFS
  • File whiteout
  • RAID like parity calculation (see SnapRAID)
  • Redundancy
  • Splitting of files across branches

How it works

mergerfs logically merges multiple filesystem paths together. Not block devices, not filesystem mounts, just paths. It acts as a proxy to the underlying filesystem paths. Combining the behaviors of some functions and being a selector for others.

When the contents of a directory are requested mergerfs combines the list of files from each directory, deduplicating entries, and returns that list.

When a file or directory is created a policy is first run to determine which branch will be selected for the creation.

For functions which change attributes or remove the file the behavior may be applied to all instances found.

The way in which mergerfs behaves is controlled by the config/options/settings. More specifically by policies.

Visualization

A         +      B        =       C
/disk1           /disk2           /merged
|                |                |
+-- /dir1        +-- /dir1        +-- /dir1
|   |            |   |            |   |
|   +-- file1    |   |            |   +-- file1
|                |   +-- file2    |   +-- file2
|                |   +-- file3    |   +-- file3
|                |                |
+-- /dir2        |                +-- /dir2
|   |            |                |   |
|   +-- file4    |                |   +-- file4
|                |                |
|                +-- /dir3        +-- /dir3
|                |   |            |   |
|                |   +-- file5    |   +-- file5
|                |                |
+-- file6        |                +-- file6
+-- file7        +-- file7        +-- file7

QuickStart

https://trapexit.github.io/mergerfs/latest/quickstart/

Documentation

https://trapexit.github.io/mergerfs

Support

https://trapexit.github.io/mergerfs/latest/support/

Sponsorship and Donations

https://github.com/trapexit/support

Development and support of a project like mergerfs requires a significant amount of time and effort. The software is released under the very liberal ISC license and is therefore free to use for personal or commercial uses.

If you are a non-commercial user and find mergerfs and its support valuable and would like to support the project financially it would be very much appreciated.

If you are using mergerfs commercially please consider sponsoring the project to ensure it continues to be maintained and receive updates. If custom features are needed feel free to contact me directly.