btrfs - data usage in <ERROR> with inappropriate ioctl for device

I'm attempting to trace down what's using some of the space on my btrfs filesystem. There is a large difference between btrfs fi du -s / and btrfs fi usage / and the difference seems to be in the <ERROR> section when running btdu.

How can I trace down what's contributing to this <ERROR> usage?

# btrfs fi du -s /
     Total   Exclusive  Set shared  Filename
     5.50GiB     5.50GiB       0.00B  /
# btrfs fi usage /
Overall:
    Device size:                  20.00GiB
    Device allocated:             12.28GiB
    Device unallocated:            7.72GiB
    Device missing:                  0.00B
    Used:                         11.59GiB
    Free (estimated):              8.22GiB      (min: 8.22GiB)
    Data ratio:                       1.00
    Metadata ratio:                   1.00
    Global reserve:               16.00MiB      (used: 0.00B)

Data,single: Size:12.00GiB, Used:11.50GiB
   /dev/sda2      12.00GiB

Metadata,single: Size:256.00MiB, Used:89.03MiB
   /dev/sda2     256.00MiB

System,single: Size:32.00MiB, Used:16.00KiB
   /dev/sda2      32.00MiB

Unallocated:
   /dev/sda2       7.72GiB

Relevant btdu output:

--- / --------------------------------------------------------------------------------
   ~12.0 GiB  [##########] /<DATA>  
   ~253.1 MiB [          ]  <METADATA>
   ~32.0 MiB  [          ]  <SYSTEM>
   
   
--- /DATA ----------------------------------------------------------------------------
    ~6.5 GiB [##########] /<ERROR>
    ~2.1 MiB [          ] /<ROOT_TREE>
    ~5.5 GiB [########  ] /@ 
    
    
--- /DATA/ERROR ----------------------------------------------------------------------
    ~6.0 GiB [##########]  logical ino (Inappropriate ioctl for device)
  ~509.9 MiB [          ]  logical ino (No such file or directory)

So my conclusions here is that the actual files on my system are taking up around 5.5GB, and the rest of the usage is from something that btdu reports as Error.

Notes / Things I've tried:

  • I have run every flavour of balance, rescue, check --repair, scrub that I could find on any site. No luck.
  • I have unmounted all other disks / nfs drives / etc. (No hidden files under mounts.)

Solution 1:

OK, looking at the kernel code and at btdu again, I think I got it.

Your kernel is too old (4.14 or older) and does not support BTRFS_IOC_LOGICAL_INO_V2.

The reason why 1) btdu mostly works and 2) these errors are mapped to 6 GB of space is that btdu only uses BTRFS_IOC_LOGICAL_INO_V2 to perform queries if the first query (which is done with BTRFS_IOC_LOGICAL_INO - no _V2) produces no results.

I will update btdu to show an appropriate hint for this case.

As for what is consuming these 6 GB of space: most likely they are unreachable parts of partially-used extents. A defragmentation will get rid of them. If you update your kernel, btdu will be able to tell you which files are pinning these extents.