btrfsmaintenance detect_mixed_bg -- What is a mixed block group?

# function: detect_mixed_bg
# parameter: path to a mounted filesystem
#
# check if the filesystem contains mixed block groups,
detect_mixed_bg() {
    # simple test is to read 'btrfs fi df',
    # (we could look for /sys/sfs/btrfs/UUID/allocation/mixed if we know
    # the UUID)

    btrfs filesystem df "$1" | grep -q "Data+Metadata"
}

https://github.com/kdave/btrfsmaintenance/blob/master/btrfsmaintenance-functions

This is called in https://github.com/kdave/btrfsmaintenance/blob/master/btrfs-balance.sh
but I’m not understanding what a “mixed block group” is;
although, I’m guessing it has to do with data and metadata being in the same block.

The following returns nothing on my system, which I guess means no “mixed block groups” were detected.

btrfs filesystem df / | grep -q "Data+Metadata"

What is a mixed block group?
In what situation is one created?
What would the output of this command look like if one was detected?

-M|–mixed

Normally the data and metadata block groups are isolated. The mixed mode will remove the isolation and store both types in the same block group type. This helps to utilize the free space regardless of the purpose and is suitable for small devices. The separate allocation of block groups leads to a situation where the space is reserved for the other block group type, is not available for allocation and can lead to ENOSPC state.

The recommended size for the mixed mode is for filesystems less than 1GiB. The soft recommendation is to use it for filesystems smaller than 5GiB. The mixed mode may lead to degraded performance on larger filesystems, but is otherwise usable, even on multiple devices.

The nodesize and sectorsize must be equal, and the block group types must match.

    Note: versions up to 4.2.x forced the mixed mode for devices smaller than 1GiB. This has been removed in 4.3+ as it caused some usability issues.

https://btrfs.wiki.kernel.org/index.php/Manpage/mkfs.btrfs#OPTIONS

So I guess if this wasn’t used when the filesystem was created, you will never have mixed block groups.

I’d agree,
I’d assume that once the partition has been formatted with BTRFS (not the volumes), you can’t modify how the metadata is stored.

TSU