Like smartd, Debian installs btrfsmaintenance in a disabled state.

One day, when consensus on the most useful and safe default
configuration has been reached, maintenance operations will be
automatically enabled.  It also seems wise to wait until
btrfsmaintenance supports something like upower, so that these IO and
CPU intensive jobs can be paused if a system switches to battery, or
deferred until AC power is available.  At present btrfsmaintenance is
not power-state aware on either laptops or servers with
uninterruptible power supplies.

Configuration is found at /etc/default/btrfsmaintenance

This configuration can be reloaded and its maintenance operations
rescheduled by running btrfsmaintenance-refresh.service every time a
systemd-enabled system is booted in multi-user mode.  To manually
reload configuration after editing it run:

  systemctl restart btrfsmaintenance-refresh.service

To refresh maintenance schedule automatically whenever the system is
booted (see below for one caveat) run:

  systemctl enable btrfsmaintenance-refresh.service

Enabling that service may also enable btrfsmaintenance-refresh.watch,
particularly when enabled by a normal user who then authenticates for
org.freedesktop.systemd1.manage-unit-files (root).  Refresh.path
watches /etc/default/btrfsmaintenance and applies scheduling changes
whenever this file is modified.  To disable this automatic behaviour
run:

  systemctl disable btrfsmaintenance-refresh.watch

Finally, enable systemd timers:

  systemctl enable btrfs-balance.timer  # [1]
  systemctl enable btrfs-defrag.timer   # [2]
  systemctl enable btrfs-scrub.timer    # [3]
  systemctl enable btrfs-trim.timer     # [4]

[1] This rewrites all data that is not excluded by a filter.  Consensus has
    not yet been reached on how much nor how often to run balance, and the
    ideal policy is workload-dependent.  Some advocate not running it at all.
    Eg: Qu Wenruo, writes:
        Full balance makes no sense.

        For older kernel we used to recommend balance based on usage
        filter to free empty block groups, but now empty block groups
        are automatically freed thus should cause no problem.

        Balance should be triggered when:

          - There is very unbalanced data/metadata block groups usage.
            E.g. a lot of data block groups are almost empty while
            metadata block groups are almost full.  However this
            should be really rare.

          - You want to convert profile
        (https://lore.kernel.org/linux-btrfs/fddf59e6-b4c5-307b-2cb4-fbb8e120ac61@gmx.com/)
[2] See wiki.debian.org/Btrfs for issues with defrag eg: out of space errors,
    complications when using snapshots, fewer more fine-grained paths are
    better, etc.  This is also workload-dependent.  Directories with logs,
    databases, and VM images benefit the most.
[3] Recommended; however, battery life will be reduced during a scrub.
[4] Prefer fstrim.timer to this option and leave btrfs-trim.timer disabled,
    in case fstrim.timer is someday enabled by default for non-rotational
    disks.

For the time being, users who forgo systemd can enable roughly
equivalent behaviour by running the following script directly:

  /usr/share/btrfsmaintenance/btrfsmaintenance-refresh-cron.sh

To enable this on every boot, add it to /etc/rc.local.  To refresh
configuration every hour, run:

  cd /etc/cron.hourly
  ln -s ../../usr/share/btrfsmaintenance/btrfsmaintenance-refresh-cron.sh ./

Btrfsmaintenance must not be configured to use both the systemd and
cron methods (see upstream README).  One day, when systemd units for
btrfsmaintenance are automatically activated, those who choose not to
use systemd will still need to manually activate the refresh-cron
script, because upstream maintains that providing automatic scheduling
with cron conflicts with automatically enabled scheduling with
systemd.

 -- Nicholas D Steeves <nsteeves@gmail.com>, Tue,  4 Aug 2020 10:43:20 -0400
