BTRFS referencer count mismatch

I have a file in my Trash which can’t be deleted. When attempting to empty Trash, the filesystem locks to read-only.

btrfs check output is below.

How to solve this problem and delete the file?

Checking filesystem on /dev/nvme0n1p2
UUID: fe593742-3a21-4778-aada-d1c91df51758
[1/7] checking root items
[2/7] checking extents
data extent[705963376640, 16384] referencer count mismatch (root 262 owner 3137425 offset 0) wanted 0 have 1
data extent[705963376640, 16384] bytenr mimsmatch, extent item bytenr 705963376640 file item bytenr 0
data extent[705963376640, 16384] referencer count mismatch (root 536871174 owner 3137425 offset 0) wanted 1 have 0
backpointer mismatch on [705963376640 16384]
ERROR: errors found in extent allocation tree or chunk allocation
[3/7] checking free space tree
[4/7] checking fs roots
[5/7] checking only csums items (without verifying data)
[6/7] checking root refs
[7/7] checking quota groups
Counts for qgroup id: 0/262 are different
our:            referenced 425673457664 referenced compressed 425673457664
disk:           referenced 425673441280 referenced compressed 425673441280
diff:           referenced 16384 referenced compressed 16384
our:            exclusive 425619918848 exclusive compressed 425619918848
disk:           exclusive 425619918848 exclusive compressed 425619918848
found 592292077568 bytes used, error(s) found
total csum bytes: 538949976
total tree bytes: 2536194048
total fs tree bytes: 1811038208
total extent tree bytes: 131547136
btree space waste bytes: 434305947
file data blocks allocated: 777581977600
 referenced 638596444160

First make a backup from the data on the disk that is important to you.

If you hit the error during the backup (I assume you do not backup Trash, so another problem on the disk) try remounting the drive with some recovery options, and finish the backup.

Next try btrfs check --repair.

I’ve read that command btrfs check --repair is possibly to be used as a last resort.

Should I try any btrfs-rescue command options first?

This is bitflip which is most commonly associated with bad memory.

262       = 0x00000106
536871174 = 0x20000106

If bad memory remains in your system, you are bound to have such problem again.

btrfs rescue is aimed at specific problems and you do not have any of them.

If you are courageous, you may try the way of real men:

btrfs-bitflip.md · GitHub

Otherwise I would suggest contacting btrfs mailing list and asking for guidance there. This may not be the only problem (even if it is not detected by btrfs check).

Btrfs mailing list - btrfs Wiki (kernel.org)

Yea, the “btrfs check --repair” is a last resort. I’ve been thru a major btrfs issue in the past.

I suggest you run the steps, one by one, found in this link:
https://en.opensuse.org/SDB:BTRFS#How_to_repair_a_broken/unmountable_btrfs_filesystem

You might want to toggle to this webpage to compare the steps (SLES documentation):

I followed the steps, one by one, and was able to recover. (using the FIRST link I show above)

I dealt with the btrfs issue over a year ago … this is the post where I got the above links from (it’s just one post in the thread I created):

I believe it was caused when my PC froze while playing a game and required a power-button hard shutdown.