Skip to content

Automatic balance after btrfs-cleaner #63

@Atemu

Description

@Atemu

Basic idea

  • When the cleaner finishes and made usage% go below a certain threshold within a block group, an automatic filtered balance is queued to get back above the threshold
  • This is on by default (important)
  • Can be turned off via mount option
  • Target % can be tuned via mount option

Intended effect

  • This should mitigate many cases of ENOSPC
    • I've seen countless records of users running into ENOSPC out of nowhere because they thought they had free space when in actuality it was all allocated but unused
  • It should also mitigate free space fragmentation to a degree
  • It would provide this baseline without requiring any userspace setup
  • It shouldn't cost very much to do in most cases
    • IME most chunks will be quite empty after the cleaner cleans a significant amount of data; allowing for quick compaction
    • If you free a whole bunch of data, you will suffer some amount of IOPS degradation for a longer period due to the cleaner anyways

What about btrfs-maintenance?

  • Yes, you can already use e.g. btrfs-maintenance to get most of the benefit
  • That runs on a schedule rather than whenever space is actually freed however
  • It requires userspace setup for each mounted btrfs
  • Users who like to run btrfs-maintenance could still do so; either as a replacement for auto balances or in addition
    • It requires setup for each mount point anyways, so it's not unreasonable to require setting a mount option
    • It doesn't really hurt to have both

Further refinements

  • Perhaps there should be some sort hysteresis as to not constantly queue balances; being slightly above or below the target is fine
  • ENOSPC could trigger an automatic balance to try and get the fs back into a usable state
  • Perhaps there could also be an absolute threshold for free chunks; to always try to keep some amounts of chunks free, even if you'd need more usage% than the threshold to achieve that
    • It's better to have IOPS fall off a cliff due to automatic balances when the disk is close to full than to ENOSPC
  • The automatic balances could be ran at a very low priority as to not impact workloads as much

Alternatives

  • The automatic balance target could be per-chunk usage%
    • This would put better constraints on how much IO would be done, just like with manual balances
    • Easier to run into ENOSPC but that should only happen with very pathological usage patterns
    • Potentially more free space fragmentation?
  • Some way to nofity a userspace process when the cleaner has finished
    • Would allow implementing all of this in userspace
    • Would lose the benefit of this being present OOTB for any btrfs without setup

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions