This can be solved by backporting ea0eba69a2a8 ("btrfs: don't hold CPU for too long when defragging a file"). There are some conflicts but not that hard to resolve.