Btrfs: Remove a large file takes long

btrfssynology

I'm running a synology nas DS1817+ with DSM 6.2.2-24922 with a RAID5 volume formatted with BTRFS.

Deleting a large file either with DSM FileStation or directly in an ssh session with "rm filename" takes a long time.

bash-4.3# ls -al
total 31362720
drwxr-xr-x 1 root root         154 Apr 13 05:09 .
drwxr-xr-x 1 root root          86 Apr 13 05:09 ..
-rw------- 1 root root 42949672960 Apr 13 05:09 Zoll-VM-flat.vmdk

bash-4.3# time rm Zoll-VM-flat.vmdk 

real    7m24.817s
user    0m0.000s
sys     0m6.435s

Why? Looking at iotop it seems to be, that it reads and writes the whole file?!?

Best Answer

btrfs is a CoW filesystem which uses 4K blocks as the base "record" size. This, for large files with intense rewrite workload (as your vm disk file) will cause immense data and metadata fragmentation. You can check data fragmentation by running filefrag -v <diskfile> and counting the number or fragments; when altering each fragment, a metadata record should be create/modified.

With volumes on classical mechanical disks, deleting such files will require a fair amount of time, especially when running on raid5/6.

So I don't think you can avoid that long delete time. Give a look here for a similar case.

Related Topic