Skip to contentSkip to conversation

btrfs metadata has reserved 1T of extra space and balances don't reclaim it

DISCUSSION Brandon Heisner 5 participants 11 messages Sep 29, 2021 – Oct 3, 2021 Btrfs file system

lore
Share & tools
lore
#0 lore raw

I have a server running CentOS 7 on 4.9.5-1.el7.elrepo.x86_64 #1 SMP Fri Jan 20 11:34:13 EST 2017 x86_64 x86_64 x86_64 GNU/Linux. It is version locked to that kernel. The metadata has reserved a full 1T of disk space, while only using ~38G. I've tried to balance the metadata to reclaim that so it can be used for data, but it doesn't work and gives no errors. It just says it balanced the chunks but the size doesn't change. The metadata total is still growing as well, as it used to be 1.04 and now it is 1.08 with only about 10G more of metadata used. I've tried doing balances up to 70 or 80 musage I think, and the total metadata does not decrease. I've done so many attempts at balancing, I've probably tried to move 300 chunks or more. None have resulted in any change to the metadata total like they do on other servers running btrfs. I first started with very low musage, like 10 and then increased it by 10 to try to see if that would balance any chunks out, but with no success.

# /sbin/btrfs balance start -musage=60 -mlimit=30 /opt/zimbra
Done, had to relocate 30 out of 2127 chunks

I can do that command over and over again, or increase the mlimit, and it doesn't change the metadata total ever.

# btrfs fi show /opt/zimbra/
Label: 'Data'  uuid: ece150db-5817-4704-9e84-80f7d8a3b1da
        Total devices 4 FS bytes used 1.48TiB
        devid    1 size 1.46TiB used 1.38TiB path /dev/sde
        devid    2 size 1.46TiB used 1.38TiB path /dev/sdf
        devid    3 size 1.46TiB used 1.38TiB path /dev/sdg
        devid    4 size 1.46TiB used 1.38TiB path /dev/sdh
# btrfs fi df /opt/zimbra/
Data, RAID10: total=1.69TiB, used=1.45TiB
System, RAID10: total=64.00MiB, used=640.00KiB
Metadata, RAID10: total=1.08TiB, used=37.69GiB
GlobalReserve, single: total=512.00MiB, used=0.00B
# btrfs fi us /opt/zimbra/ -T
Overall:
    Device size:                   5.82TiB
    Device allocated:              5.54TiB
    Device unallocated:          291.54GiB
    Device missing:                  0.00B
    Used:                          2.96TiB
    Free (estimated):            396.36GiB      (min: 396.36GiB)
    Data ratio:                       2.00
    Metadata ratio:                   2.00
    Global reserve:              512.00MiB      (used: 0.00B)
            Data      Metadata  System
Id Path     RAID10    RAID10    RAID10    Unallocated
-- -------- --------- --------- --------- -----------
 1 /dev/sde 432.75GiB 276.00GiB  16.00MiB   781.65GiB
 2 /dev/sdf 432.75GiB 276.00GiB  16.00MiB   781.65GiB
 3 /dev/sdg 432.75GiB 276.00GiB  16.00MiB   781.65GiB
 4 /dev/sdh 432.75GiB 276.00GiB  16.00MiB   781.65GiB

-- -------- --------- --------- --------- -----------
Total 1.69TiB 1.08TiB 64.00MiB 3.05TiB
Used 1.45TiB 37.69GiB 640.00KiB

Signature · 3 lines
Brandon Heisner
System Administrator
Wolfram Research
#1 lore raw

---- From: Brandon Heisner <[email protected]> -- Sent: 2021-09-29 - 04:23 ----

Quoted 1 line

I have a server running CentOS 7 on 4.9.5-1.el7.elrepo.x86_64 #1 SMP Fri Jan 20 11:34:13 EST 2017 x86_64 x86_64 x86_64 GNU/Linux. It is version locked to that kernel. The metadata has reserved a full 1T of disk space, while only using ~38G. I've tried to balance the metadata to reclaim that so it can be used for data, but it doesn't work and gives no errors. It just says it balanced the chunks but the size doesn't change. The metadata total is still growing as well, as it used to be 1.04 and now it is 1.08 with only about 10G more of metadata used. I've tried doing balances up to 70 or 80 musage I think, and the total metadata does not decrease. I've done so many attempts at balancing, I've probably tried to move 300 chunks or more. None have resulted in any change to the metadata total like they do on other servers running btrfs. I first started with very low musage, like 10 and then increased it by 10 to try to see if that would balance any chunks out, but with no succes

s.

Quoted 41 lines
# /sbin/btrfs balance start -musage=60 -mlimit=30 /opt/zimbra
Done, had to relocate 30 out of 2127 chunks

I can do that command over and over again, or increase the mlimit, and it doesn't change the metadata total ever.

# btrfs fi show /opt/zimbra/
Label: 'Data'  uuid: ece150db-5817-4704-9e84-80f7d8a3b1da
        Total devices 4 FS bytes used 1.48TiB
        devid    1 size 1.46TiB used 1.38TiB path /dev/sde
        devid    2 size 1.46TiB used 1.38TiB path /dev/sdf
        devid    3 size 1.46TiB used 1.38TiB path /dev/sdg
        devid    4 size 1.46TiB used 1.38TiB path /dev/sdh
# btrfs fi df /opt/zimbra/
Data, RAID10: total=1.69TiB, used=1.45TiB
System, RAID10: total=64.00MiB, used=640.00KiB
Metadata, RAID10: total=1.08TiB, used=37.69GiB
GlobalReserve, single: total=512.00MiB, used=0.00B
# btrfs fi us /opt/zimbra/ -T
Overall:
    Device size:                   5.82TiB
    Device allocated:              5.54TiB
    Device unallocated:          291.54GiB
    Device missing:                  0.00B
    Used:                          2.96TiB
    Free (estimated):            396.36GiB      (min: 396.36GiB)
    Data ratio:                       2.00
    Metadata ratio:                   2.00
    Global reserve:              512.00MiB      (used: 0.00B)
            Data      Metadata  System
Id Path     RAID10    RAID10    RAID10    Unallocated
-- -------- --------- --------- --------- -----------
 1 /dev/sde 432.75GiB 276.00GiB  16.00MiB   781.65GiB
 2 /dev/sdf 432.75GiB 276.00GiB  16.00MiB   781.65GiB
 3 /dev/sdg 432.75GiB 276.00GiB  16.00MiB   781.65GiB
 4 /dev/sdh 432.75GiB 276.00GiB  16.00MiB   781.65GiB
Quoted 13 lines

-- -------- --------- --------- --------- -----------
Total 1.69TiB 1.08TiB 64.00MiB 3.05TiB
Used 1.45TiB 37.69GiB 640.00KiB

Signature · 3 lines
Brandon Heisner
System Administrator
Wolfram Research

What are you mount options? Do you by any chance use metadata_ratio mount option?

https://btrfs.wiki.kernel.org/index.php/Manpage/btrfs(5)#MOUNT_OPTIONS

#5 lore raw
In reply to Brandon Heisner
Quoted 4 lines · Brandon Heisner

I have a server running CentOS 7 on 4.9.5-1.el7.elrepo.x86_64 #1 SMP Fri Jan 20 11:34:13 EST 2017 x86_64 x86_64 x86_64 GNU/Linux. It is version locked to that kernel. The metadata has reserved a full 1T of disk space, while only using ~38G. I've tried to balance the metadata to reclaim that so it can be used for data, but it doesn't work and gives no errors. It just says it balanced the chunks but the size doesn't change. The metadata total is still growing as well, as it used to be 1.04 and now it is 1.08 with only about 10G more of metadata used. I've tried doing balances up to 70 or 80 musage I think, and the total metadata does not decrease. I've done so many attempts at balancing, I've probably tried to move 300 chunks or more. None have resulted in any change to the metadata total like they do on other servers running btrfs. I first started with very low musage, like 10 and then increased it by 10 to try to see if that would balance any chunks out, but with no success.

# /sbin/btrfs balance start -musage=60 -mlimit=30 /opt/zimbra
Done, had to relocate 30 out of 2127 chunks

One question is, did -musage=0 resulted any change?

If there are empty metadata block groups, btrfs should be able to reclaim without any extra commands.

And is there any dmesg during above -musage=0 output?

Thanks,
Qu

Quoted 47 lines

I can do that command over and over again, or increase the mlimit, and it doesn't change the metadata total ever.

# btrfs fi show /opt/zimbra/
Label: 'Data'  uuid: ece150db-5817-4704-9e84-80f7d8a3b1da
         Total devices 4 FS bytes used 1.48TiB
         devid    1 size 1.46TiB used 1.38TiB path /dev/sde
         devid    2 size 1.46TiB used 1.38TiB path /dev/sdf
         devid    3 size 1.46TiB used 1.38TiB path /dev/sdg
         devid    4 size 1.46TiB used 1.38TiB path /dev/sdh
# btrfs fi df /opt/zimbra/
Data, RAID10: total=1.69TiB, used=1.45TiB
System, RAID10: total=64.00MiB, used=640.00KiB
Metadata, RAID10: total=1.08TiB, used=37.69GiB
GlobalReserve, single: total=512.00MiB, used=0.00B
# btrfs fi us /opt/zimbra/ -T
Overall:
     Device size:                   5.82TiB
     Device allocated:              5.54TiB
     Device unallocated:          291.54GiB
     Device missing:                  0.00B
     Used:                          2.96TiB
     Free (estimated):            396.36GiB      (min: 396.36GiB)
     Data ratio:                       2.00
     Metadata ratio:                   2.00
     Global reserve:              512.00MiB      (used: 0.00B)

Data Metadata System
Id Path RAID10 RAID10 RAID10 Unallocated
-- -------- --------- --------- --------- -----------

  1 /dev/sde 432.75GiB 276.00GiB  16.00MiB   781.65GiB
  2 /dev/sdf 432.75GiB 276.00GiB  16.00MiB   781.65GiB
  3 /dev/sdg 432.75GiB 276.00GiB  16.00MiB   781.65GiB
  4 /dev/sdh 432.75GiB 276.00GiB  16.00MiB   781.65GiB
-- -------- --------- --------- --------- -----------
    Total      1.69TiB   1.08TiB  64.00MiB     3.05TiB
    Used       1.45TiB  37.69GiB 640.00KiB
#2 lore raw
In reply to Forza

No I do not use that option. Also, because of btrfs not mounting individual subvolume options, I have the compression and nodatacow set with filesystem attributes on the directories that are btrfs subvolumes.

UUID=ece150db-5817-4704-9e84-80f7d8a3b1da /opt/zimbra           btrfs   subvol=zimbra,defaults,discard,compress=lzo 0 0
UUID=ece150db-5817-4704-9e84-80f7d8a3b1da /var/log              btrfs   subvol=root-var-log,defaults,discard,compress=lzo 0 0
UUID=ece150db-5817-4704-9e84-80f7d8a3b1da /opt/zimbra/db        btrfs   subvol=db,defaults,discard,nodatacow 0 0
UUID=ece150db-5817-4704-9e84-80f7d8a3b1da /opt/zimbra/index     btrfs   subvol=index,defaults,discard,compress=lzo 0 0
UUID=ece150db-5817-4704-9e84-80f7d8a3b1da /opt/zimbra/store     btrfs   subvol=store,defaults,discard,compress=lzo 0 0
UUID=ece150db-5817-4704-9e84-80f7d8a3b1da /opt/zimbra/log       btrfs   subvol=log,defaults,discard,compress=lzo 0 0
UUID=ece150db-5817-4704-9e84-80f7d8a3b1da /opt/zimbra/snapshots btrfs   subvol=snapshots,defaults,discard,compress=lzo 0 0
Quoted 77 lines · ----- On Sep 29, 2021, at 2:23 AM, Forza [email protected] wrote:

---- From: Brandon Heisner <[email protected]> -- Sent: 2021-09-29 - 04:23
----

Quoted 64 lines

I have a server running CentOS 7 on 4.9.5-1.el7.elrepo.x86_64 #1 SMP Fri Jan 20 11:34:13 EST 2017 x86_64 x86_64 x86_64 GNU/Linux. It is version locked to that kernel. The metadata has reserved a full 1T of disk space, while only using ~38G. I've tried to balance the metadata to reclaim that so it can be used for data, but it doesn't work and gives no errors. It just says it balanced the chunks but the size doesn't change. The metadata total is still growing as well, as it used to be 1.04 and now it is 1.08 with only about 10G more of metadata used. I've tried doing balances up to 70 or 80 musage I think, and the total metadata does not decrease. I've done so many attempts at balancing, I've probably tried to move 300 chunks or more. None have resulted in any change to the metadata total like they do on other servers running btrfs. I first started with very low musage, like 10 and then increased it by 10 to try to see if that would balance any chunks out, but with no success.

# /sbin/btrfs balance start -musage=60 -mlimit=30 /opt/zimbra
Done, had to relocate 30 out of 2127 chunks

I can do that command over and over again, or increase the mlimit, and it doesn't change the metadata total ever.

# btrfs fi show /opt/zimbra/
Label: 'Data'  uuid: ece150db-5817-4704-9e84-80f7d8a3b1da
        Total devices 4 FS bytes used 1.48TiB
        devid    1 size 1.46TiB used 1.38TiB path /dev/sde
        devid    2 size 1.46TiB used 1.38TiB path /dev/sdf
        devid    3 size 1.46TiB used 1.38TiB path /dev/sdg
        devid    4 size 1.46TiB used 1.38TiB path /dev/sdh
# btrfs fi df /opt/zimbra/
Data, RAID10: total=1.69TiB, used=1.45TiB
System, RAID10: total=64.00MiB, used=640.00KiB
Metadata, RAID10: total=1.08TiB, used=37.69GiB
GlobalReserve, single: total=512.00MiB, used=0.00B
# btrfs fi us /opt/zimbra/ -T
Overall:
    Device size:                   5.82TiB
    Device allocated:              5.54TiB
    Device unallocated:          291.54GiB
    Device missing:                  0.00B
    Used:                          2.96TiB
    Free (estimated):            396.36GiB      (min: 396.36GiB)
    Data ratio:                       2.00
    Metadata ratio:                   2.00
    Global reserve:              512.00MiB      (used: 0.00B)
            Data      Metadata  System
Id Path     RAID10    RAID10    RAID10    Unallocated
-- -------- --------- --------- --------- -----------
 1 /dev/sde 432.75GiB 276.00GiB  16.00MiB   781.65GiB
 2 /dev/sdf 432.75GiB 276.00GiB  16.00MiB   781.65GiB
 3 /dev/sdg 432.75GiB 276.00GiB  16.00MiB   781.65GiB
 4 /dev/sdh 432.75GiB 276.00GiB  16.00MiB   781.65GiB

-- -------- --------- --------- --------- -----------
Total 1.69TiB 1.08TiB 64.00MiB 3.05TiB
Used 1.45TiB 37.69GiB 640.00KiB

Quoted 4 lines

--
Brandon Heisner
System Administrator
Wolfram Research

What are you mount options? Do you by any chance use metadata_ratio mount option?

https://btrfs.wiki.kernel.org/index.php/Manpage/btrfs(5)#MOUNT_OPTIONS

#6 lore raw
In reply to Brandon Heisner

Il giorno mer 29 set 2021 alle ore 04:41 Brandon Heisner <[email protected]> ha scritto:

Quoted 2 lines

I have a server running CentOS 7 on 4.9.5-1.el7.elrepo.x86_64 #1 SMP Fri Jan 20 11:34:13 EST 2017 x86_64 x86_64 x86_64 GNU/Linux. It is version locked to that kernel. The metadata has reserved a full 1T of disk space, while only using ~38G. I've tried to balance the metadata to reclaim that so it can be used for data, but it doesn't work and gives no errors. It just says it balanced the chunks but the size doesn't change. The metadata total is still growing as well, as it used to be 1.04 and now it is 1.08 with only about 10G more of metadata used. I've tried doing balances up to 70 or 80 musage I think, and

Similar situation here.
A 18TB single disk with one big snapraid parity file, and a lot of metadata allocated.
I solved with:
btrfs filesystem defrag -v -r -clzo . (useless the compression, in my case)

So, just after a little bit from start I saw already space reclaming.

In the end I fallback to exfat to avoid to keep re-reading/re-writing all data just to avoid "metadata waste".

Ciao,
Gelma

#7 lore raw

---- From: Andrea Gelmini <[email protected]> -- Sent: 2021-09-29 - 17:18 ----

Quoted 11 lines

Il giorno mer 29 set 2021 alle ore 04:41 Brandon Heisner <[email protected]> ha scritto:

Quoted 2 lines

I have a server running CentOS 7 on 4.9.5-1.el7.elrepo.x86_64 #1 SMP Fri Jan 20 11:34:13 EST 2017 x86_64 x86_64 x86_64 GNU/Linux. It is version locked to that kernel. The metadata has reserved a full 1T of disk space, while only using ~38G. I've tried to balance the metadata to reclaim that so it can be used for data, but it doesn't work and gives no errors. It just says it balanced the chunks but the size doesn't change. The metadata total is still growing as well, as it used to be 1.04 and now it is 1.08 with only about 10G more of metadata used. I've tried doing balances up to 70 or 80 musage I think, and

Similar situation here.
A 18TB single disk with one big snapraid parity file, and a lot of metadata allocated.
I solved with:
btrfs filesystem defrag -v -r -clzo . (useless the compression, in my case)

Quoted 7 lines

So, just after a little bit from start I saw already space reclaming.

In the end I fallback to exfat to avoid to keep re-reading/re-writing all data just to avoid "metadata waste".

Ciao,
Gelma

Maybe autodefrag mount option might be helpful?

Your problem sounds like partially filled extents and not metadata related. Typical scenarios where that happens is with some databases and vm images. A file could allocate much more space than actuall data due to this. Use 'compsize' to determine this.

#9 lore raw
In reply to Brandon Heisner
Quoted 2 lines · Brandon Heisner

I have a server running CentOS 7 on 4.9.5-1.el7.elrepo.x86_64 #1 SMP Fri Jan 20 11:34:13 EST 2017 x86_64 x86_64 x86_64 GNU/Linux. It is

That is a really old kernel. I recall there were some anomalous metadata allocation behaviors with kernels of that age, e.g. running scrub and balance at the same time would allocate a lot of metadata because scrub would lock a metadata block group immediately after it had been allocated, forcing another metadata block group to be allocated immediately. The symptom of that bug is very similar to yours--without warning, hundreds of GB of metadata block groups are allocated, all empty, during a scrub or balance operation.

Unfortunately I don't have a better solution than "upgrade to a newer kernel", as that particular bug was solved years ago (along with hundreds of others).

Quoted 5 lines

version locked to that kernel. The metadata has reserved a full 1T of disk space, while only using ~38G. I've tried to balance the metadata to reclaim that so it can be used for data, but it doesn't work and gives no errors. It just says it balanced the chunks but the size doesn't change. The metadata total is still growing as well,

Quoted 8 lines

as it used to be 1.04 and now it is 1.08 with only about 10G more of metadata used. I've tried doing balances up to 70 or 80 musage I think, and the total metadata does not decrease. I've done so many attempts at balancing, I've probably tried to move 300 chunks or more. None have resulted in any change to the metadata total like they do on other servers running btrfs. I first started with very low musage, like 10 and then increased it by 10 to try to see if that would balance any chunks out, but with no success.

Have you tried rebooting? The block groups may be stuck in a locked state in memory or pinned by pending discard requests, in which case balance won't touch them. For that matter, try turning off discard (it's usually better to run fstrim once a day anyway, and not use the discard mount option).

Quoted 5 lines
# /sbin/btrfs balance start -musage=60 -mlimit=30 /opt/zimbra
Done, had to relocate 30 out of 2127 chunks

I can do that command over and over again, or increase the mlimit, and it doesn't change the metadata total ever.

I would use just -m here (no filters, only metadata). If it gets the allocation under control, run 'btrfs balance cancel'; if it doesn't, let it run all the way to the end. Each balance starts from the last block group, so you are effectively restarting balance to process the same 30 block groups over and over here.

Quoted 47 lines
# btrfs fi show /opt/zimbra/
Label: 'Data'  uuid: ece150db-5817-4704-9e84-80f7d8a3b1da
        Total devices 4 FS bytes used 1.48TiB
        devid    1 size 1.46TiB used 1.38TiB path /dev/sde
        devid    2 size 1.46TiB used 1.38TiB path /dev/sdf
        devid    3 size 1.46TiB used 1.38TiB path /dev/sdg
        devid    4 size 1.46TiB used 1.38TiB path /dev/sdh
# btrfs fi df /opt/zimbra/
Data, RAID10: total=1.69TiB, used=1.45TiB
System, RAID10: total=64.00MiB, used=640.00KiB
Metadata, RAID10: total=1.08TiB, used=37.69GiB
GlobalReserve, single: total=512.00MiB, used=0.00B
# btrfs fi us /opt/zimbra/ -T
Overall:
    Device size:                   5.82TiB
    Device allocated:              5.54TiB
    Device unallocated:          291.54GiB
    Device missing:                  0.00B
    Used:                          2.96TiB
    Free (estimated):            396.36GiB      (min: 396.36GiB)
    Data ratio:                       2.00
    Metadata ratio:                   2.00
    Global reserve:              512.00MiB      (used: 0.00B)
            Data      Metadata  System
Id Path     RAID10    RAID10    RAID10    Unallocated
-- -------- --------- --------- --------- -----------
 1 /dev/sde 432.75GiB 276.00GiB  16.00MiB   781.65GiB
 2 /dev/sdf 432.75GiB 276.00GiB  16.00MiB   781.65GiB
 3 /dev/sdg 432.75GiB 276.00GiB  16.00MiB   781.65GiB
 4 /dev/sdh 432.75GiB 276.00GiB  16.00MiB   781.65GiB

-- -------- --------- --------- --------- -----------
Total 1.69TiB 1.08TiB 64.00MiB 3.05TiB
Used 1.45TiB 37.69GiB 640.00KiB

Signature · 3 lines
Brandon Heisner
System Administrator
Wolfram Research
#8 lore raw
In reply to Forza

Il giorno mer 29 set 2021 alle ore 18:39 Forza <[email protected]> ha scritto:

Quoted 1 line

Maybe autodefrag mount option might be helpful?

It was enabled since beginning.

Quoted 1 line

Your problem sounds like partially filled extents and not metadata related. Typical scenarios where that happens is with some databases and vm images. A file could allocate much more space than actuall data due to this. Use 'compsize' to determine this.

I confirm is one big file with random writes. I agree about extents. But I'm quite confident the same approach can fix the original question.

Ciao,
Gelma

#10 lore raw
In reply to Zygo Blaxell

A reboot of the server did help quite a bit with the problem, but still not fixed completely. I went from having 1.08T reserved for metadata to "only" having 446G reserved. My free space went from 346G to 1010G. So at least I have some breathing room again. I prefer not to do a defrag, as that breaks all the COW links and the disk usage would go up then. I haven't tried the balance of all the metadata, which might be resource intensive.

# btrfs fi us /opt/zimbra/ -T
Overall:
    Device size:                   5.82TiB
    Device allocated:              4.36TiB
    Device unallocated:            1.46TiB
    Device missing:                  0.00B
    Used:                          3.05TiB
    Free (estimated):           1010.62GiB      (min: 1010.62GiB)
    Data ratio:                       2.00
    Metadata ratio:                   2.00
    Global reserve:              512.00MiB      (used: 0.00B)
            Data      Metadata  System
Id Path     RAID10    RAID10    RAID10    Unallocated
-- -------- --------- --------- --------- -----------
 1 /dev/sdc 446.25GiB 111.50GiB  32.00MiB   932.63GiB
 2 /dev/sdd 446.25GiB 111.50GiB  32.00MiB   932.63GiB
 3 /dev/sde 446.25GiB 111.50GiB  32.00MiB   932.63GiB
 4 /dev/sdf 446.25GiB 111.50GiB  32.00MiB   932.63GiB
-- -------- --------- --------- --------- -----------
   Total      1.74TiB 446.00GiB 128.00MiB     3.64TiB
   Used       1.49TiB  38.16GiB 464.00KiB
# btrfs fi df /opt/zimbra/
Data, RAID10: total=1.74TiB, used=1.49TiB
System, RAID10: total=128.00MiB, used=464.00KiB
Metadata, RAID10: total=446.00GiB, used=38.19GiB
GlobalReserve, single: total=512.00MiB, used=0.00B
Quoted 96 lines · ----- On Sep 29, 2021, at 12:31 PM, Zygo Blaxell…
Quoted 2 lines · Brandon Heisner

I have a server running CentOS 7 on 4.9.5-1.el7.elrepo.x86_64 #1 SMP Fri Jan 20 11:34:13 EST 2017 x86_64 x86_64 x86_64 GNU/Linux. It is

That is a really old kernel. I recall there were some anomalous metadata allocation behaviors with kernels of that age, e.g. running scrub and balance at the same time would allocate a lot of metadata because scrub would lock a metadata block group immediately after it had been allocated, forcing another metadata block group to be allocated immediately. The symptom of that bug is very similar to yours--without warning, hundreds of GB of metadata block groups are allocated, all empty, during a scrub or balance operation.

Unfortunately I don't have a better solution than "upgrade to a newer kernel", as that particular bug was solved years ago (along with hundreds of others).

Quoted 5 lines

version locked to that kernel. The metadata has reserved a full 1T of disk space, while only using ~38G. I've tried to balance the metadata to reclaim that so it can be used for data, but it doesn't work and gives no errors. It just says it balanced the chunks but the size doesn't change. The metadata total is still growing as well,

Quoted 8 lines

as it used to be 1.04 and now it is 1.08 with only about 10G more of metadata used. I've tried doing balances up to 70 or 80 musage I think, and the total metadata does not decrease. I've done so many attempts at balancing, I've probably tried to move 300 chunks or more. None have resulted in any change to the metadata total like they do on other servers running btrfs. I first started with very low musage, like 10 and then increased it by 10 to try to see if that would balance any chunks out, but with no success.

Have you tried rebooting? The block groups may be stuck in a locked state in memory or pinned by pending discard requests, in which case balance won't touch them. For that matter, try turning off discard (it's usually better to run fstrim once a day anyway, and not use the discard mount option).

Quoted 5 lines
# /sbin/btrfs balance start -musage=60 -mlimit=30 /opt/zimbra
Done, had to relocate 30 out of 2127 chunks

I can do that command over and over again, or increase the mlimit, and it doesn't change the metadata total ever.

I would use just -m here (no filters, only metadata). If it gets the allocation under control, run 'btrfs balance cancel'; if it doesn't, let it run all the way to the end. Each balance starts from the last block group, so you are effectively restarting balance to process the same 30 block groups over and over here.

Quoted 47 lines
# btrfs fi show /opt/zimbra/
Label: 'Data'  uuid: ece150db-5817-4704-9e84-80f7d8a3b1da
        Total devices 4 FS bytes used 1.48TiB
        devid    1 size 1.46TiB used 1.38TiB path /dev/sde
        devid    2 size 1.46TiB used 1.38TiB path /dev/sdf
        devid    3 size 1.46TiB used 1.38TiB path /dev/sdg
        devid    4 size 1.46TiB used 1.38TiB path /dev/sdh
# btrfs fi df /opt/zimbra/
Data, RAID10: total=1.69TiB, used=1.45TiB
System, RAID10: total=64.00MiB, used=640.00KiB
Metadata, RAID10: total=1.08TiB, used=37.69GiB
GlobalReserve, single: total=512.00MiB, used=0.00B
# btrfs fi us /opt/zimbra/ -T
Overall:
    Device size:                   5.82TiB
    Device allocated:              5.54TiB
    Device unallocated:          291.54GiB
    Device missing:                  0.00B
    Used:                          2.96TiB
    Free (estimated):            396.36GiB      (min: 396.36GiB)
    Data ratio:                       2.00
    Metadata ratio:                   2.00
    Global reserve:              512.00MiB      (used: 0.00B)
            Data      Metadata  System
Id Path     RAID10    RAID10    RAID10    Unallocated
-- -------- --------- --------- --------- -----------
 1 /dev/sde 432.75GiB 276.00GiB  16.00MiB   781.65GiB
 2 /dev/sdf 432.75GiB 276.00GiB  16.00MiB   781.65GiB
 3 /dev/sdg 432.75GiB 276.00GiB  16.00MiB   781.65GiB
 4 /dev/sdh 432.75GiB 276.00GiB  16.00MiB   781.65GiB

-- -------- --------- --------- --------- -----------
Total 1.69TiB 1.08TiB 64.00MiB 3.05TiB
Used 1.45TiB 37.69GiB 640.00KiB

--
Brandon Heisner
System Administrator
Wolfram Research

#3 lore raw
In reply to Brandon Heisner
Quoted 11 lines · Brandon Heisner

No I do not use that option. Also, because of btrfs not mounting individual subvolume options, I have the compression and nodatacow set with filesystem attributes on the directories that are btrfs subvolumes.

UUID=ece150db-5817-4704-9e84-80f7d8a3b1da /opt/zimbra           btrfs   subvol=zimbra,defaults,discard,compress=lzo 0 0
UUID=ece150db-5817-4704-9e84-80f7d8a3b1da /var/log              btrfs   subvol=root-var-log,defaults,discard,compress=lzo 0 0
UUID=ece150db-5817-4704-9e84-80f7d8a3b1da /opt/zimbra/db        btrfs   subvol=db,defaults,discard,nodatacow 0 0
UUID=ece150db-5817-4704-9e84-80f7d8a3b1da /opt/zimbra/index     btrfs   subvol=index,defaults,discard,compress=lzo 0 0
UUID=ece150db-5817-4704-9e84-80f7d8a3b1da /opt/zimbra/store     btrfs   subvol=store,defaults,discard,compress=lzo 0 0
UUID=ece150db-5817-4704-9e84-80f7d8a3b1da /opt/zimbra/log       btrfs   subvol=log,defaults,discard,compress=lzo 0 0
UUID=ece150db-5817-4704-9e84-80f7d8a3b1da /opt/zimbra/snapshots btrfs   subvol=snapshots,defaults,discard,compress=lzo 0 0

It might be worth looking into discard=async (*) or setting up regular fstrim instead of doing the discard mount option.

* async discard:
"mount -o discard=async" to enable it freed extents are not discarded immediatelly, but grouped together and trimmed later, with IO rate limiting
* https://lore.kernel.org/lkml/[email protected]/

#4 lore raw
Quoted 15 lines · Forza
Quoted 11 lines · Brandon Heisner

No I do not use that option. Also, because of btrfs not mounting individual subvolume options, I have the compression and nodatacow set with filesystem attributes on the directories that are btrfs subvolumes.

UUID=ece150db-5817-4704-9e84-80f7d8a3b1da /opt/zimbra           btrfs   subvol=zimbra,defaults,discard,compress=lzo 0 0
UUID=ece150db-5817-4704-9e84-80f7d8a3b1da /var/log              btrfs   subvol=root-var-log,defaults,discard,compress=lzo 0 0
UUID=ece150db-5817-4704-9e84-80f7d8a3b1da /opt/zimbra/db        btrfs   subvol=db,defaults,discard,nodatacow 0 0
UUID=ece150db-5817-4704-9e84-80f7d8a3b1da /opt/zimbra/index     btrfs   subvol=index,defaults,discard,compress=lzo 0 0
UUID=ece150db-5817-4704-9e84-80f7d8a3b1da /opt/zimbra/store     btrfs   subvol=store,defaults,discard,compress=lzo 0 0
UUID=ece150db-5817-4704-9e84-80f7d8a3b1da /opt/zimbra/log       btrfs   subvol=log,defaults,discard,compress=lzo 0 0
UUID=ece150db-5817-4704-9e84-80f7d8a3b1da /opt/zimbra/snapshots btrfs   subvol=snapshots,defaults,discard,compress=lzo 0 0
Quoted 2 lines

It might be worth looking into discard=async (*) or setting up regular fstrim instead of doing the discard mount option.

Brandon's kernel (4.9.5 from 2017) is three years too old to have working discard=async.

Upgrading the kernel would most likely fix the problems even without changing mount options.

Quoted 4 lines

* async discard:
"mount -o discard=async" to enable it freed extents are not discarded immediatelly, but grouped together and trimmed later, with IO rate limiting
* https://lore.kernel.org/lkml/[email protected]/