Usage Patterns
tiered cache
Some storage technologies support what is called "tiered" caching. The placing of smaller, faster storage as a transparent cache to larger, slower storage. NVMe, SSD, Optane in front of traditional HDDs for instance.
mergerfs does not natively support any sort of tiered caching. Most users have no use for such a feature and its inclusion would complicate the code as it exists today. However, there are a few situations where a cache filesystem could help with a typical mergerfs setup.
- Fast network, slow filesystems, many readers: You've a 10+Gbps network with many readers and your regular filesystems can't keep up.
- Fast network, slow filesystems, small'ish bursty writes: You have a 10+Gbps network and wish to transfer amounts of data less than your cache filesystem but wish to do so quickly and the time between bursts is long enough to migrate data.
With #1 it's arguable if you should be using mergerfs at all. A RAID
level that can aggregate performance or using higher performance
storage would probably be the better solution. If you're going to use
mergerfs there are other tactics that may help: spreading the data
across filesystems (see the mergerfs.dup tool) and setting
func.open=rand
, using symlinkify
, or using dm-cache or a similar
technology to add tiered cache to the underlying device itself.
With #2 one could use dm-cache as well but there is another solution which requires only mergerfs and a cronjob.
- Create 2 mergerfs pools. One which includes just the slow branches and one which has both the fast branches (SSD,NVME,etc.) and slow branches. The 'base' pool and the 'cache' pool.
- The 'cache' pool should have the cache branches listed first in the branch list.
- The best
create
policies to use for the 'cache' pool would probably beff
,epff
,lfs
,msplfs
, oreplfs
. The latter three under the assumption that the cache filesystem(s) are far smaller than the backing filesystems. If using path preserving policies remember that you'll need to manually create the core directories of those paths you wish to be cached. Be sure the permissions are in sync. Usemergerfs.fsck
to check / correct them. You could also set the slow filesystems mode toNC
though that'd mean if the cache filesystems fill you'd get "out of space" errors. - Enable
moveonenospc
and setminfreespace
appropriately. To make sure there is enough room on the "slow" pool you might want to setminfreespace
to at least as large as the size of the largest cache filesystem if not larger. This way in the worst case the whole of the cache filesystem(s) can be moved to the other drives. - Set your programs to use the 'cache' pool.
- Save one of the below scripts or create you're own. The script's responsibility is to move files from the cache filesystems (not pool) to the 'base' pool.
- Use
cron
(as root) to schedule the command at whatever frequency is appropriate for your workflow.
time based expiring
Move files from cache to base pool based only on the last time the
file was accessed. Replace -atime
with -amin
if you want minutes
rather than days. May want to use the fadvise
/ --drop-cache
version of rsync or run rsync with the tool
nocache.
NOTE: The arguments to these scripts include the cache filesystem itself. Not the pool with the cache filesystem. You could have data loss if the source is the cache pool.
percentage full expiring
Move the oldest file from the cache to the backing pool. Continue till below percentage threshold.
NOTE: The arguments to these scripts include the cache filesystem itself. Not the pool with the cache filesystem. You could have data loss if the source is the cache pool.