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.

79 lines
3.8 KiB

  1. # Limiting drive spinup
  2. ## How can I setup my system to limit drive spinup?
  3. TL;DR: You really can't. Not through mergerfs alone. In fact mergerfs
  4. makes an attempt to do so more complicated.
  5. mergerfs is a proxy. Despite having some caching behaviors it is not
  6. designed to cache much more than metadata. It proxies calls between
  7. client software and underlying filesystems. If a client makes a
  8. request such as `open`, `readdir`, `stat`, etc. it must translate that
  9. into something that makes sense across multiple filesystems. For
  10. `readdir` that means running the call against all branches and
  11. aggregating the output. For `open` that means finding the file to open
  12. and doing so. The only way to find the file to open is to scan across
  13. all branches and sort the results and pick one. There is no practical
  14. way to do otherwise. Especially given so many mergerfs users expect
  15. out-of-band changes to "just work."
  16. The best way to limit spinup of drives is to limit their usage at the
  17. client level. Meaning keeping software from interacting with the
  18. filesystem (and therefore the drive) all together.
  19. ### What if you assume no out-of-band changes and cache everything?
  20. This would require a significant rewrite of mergerfs. Everything is
  21. done on the fly right now and all those calls to underlying
  22. filesystems can cause a spinup. To work around that a database of some
  23. sort would have to be used to store ALL metadata about the underlying
  24. filesystems and on startup everything scanned and stored. From then on
  25. it would have to carefully update all the same data the filesystems
  26. do. It couldn't be kept in RAM because it would take up too much space
  27. so it'd have to be on a SSD or other storage device. If anything
  28. changed out of band it would break things in weird ways. It could
  29. rescan on occasion but that would require spinning up
  30. everything. Filesystem watches could be used to get updates when the
  31. filesystem changes but that would allow for race conditions and
  32. might keep the drives from spinning down. Something as "simple" as
  33. keeping the current available free space on each filesystem isn't as
  34. easy as one might think given reflinks, snapshots, and other block
  35. level dedup technologies as well as the space used includes not just
  36. raw file usage.
  37. Even if all metadata (including xattrs) is cached some software will
  38. open files (media like videos and audio) to check their
  39. metadata. Granted a Plex or Jellyfin scan which may do that is
  40. different from a random directory listing but is still something to
  41. consider. Those "deep" scans can't be kept from waking drives.
  42. ### What if you only query already active drives?
  43. Let's assume that is plausible (it isn't because some drives actually
  44. will spin up if you ask if they are spun down... yes... really) you
  45. would have to either cache all the metadata on the filesystem or treat
  46. it like the filesystem doesn't exist. The former has all the problems
  47. mentioned prior and the latter would break a lot of things.
  48. ### Is there anything that can be done where mergerfs is involved?
  49. Yes, but whether it works for you depends on your tolerance for the
  50. complexity.
  51. 1. Cleanly separate writing, storing, and consuming the data.
  52. 1. Use a SSD or dedicated and limited pool of drives for downloads / torrents.
  53. 2. When downloaded move the files to the primary storage pool.
  54. 3. When setting up software like Plex, Jellyfin, etc. point to the
  55. underlying filesystems. Not mergerfs.
  56. 2. Add a bunch of bcache, lvmcache, dm-cache, or similar block level
  57. cache to your setup. After a bit of use, assuming sufficient
  58. storage space, you can limit the likelihood of the underlying
  59. spinning disks from needing to be hit.
  60. Remember too that while it may be a tradeoff you are willing to live
  61. with there is decent evidence that spinning down drives puts increased
  62. wear on them and can lead to their death earlier than otherwise.