The algorithm for creating a new file, preallocating and comparing
extents before doing any data movement is pretty much the same as what
xfs_fsr does. however, they differ in teh method of data exchange
xfs_fsr does all the data movement via direct IO in userspace
(i.e. scales extremely well). It swaps the extents atomically
if the inode has not changed between the start of the data copy
and the completion of it. Hence you can't defragment active files.
This was considered a fundamental blocker for ext4 even though
most active files never need defragmentation (think shared
libraries). Hence the ext4 patchset implements data movement inside
ext4 itself and so the kernel defrag code is much, much more complex
than the XFS swap extents ioctl. Userspace complexity is about the
same, but different APIs were required for ext4 to do it's "a bit at
a time" algorithm....