Subject: optimize mv for multiple bind mounts

From: Ruediger Meier <[email-masked]>
Date: Thu, 2 Mar 2017 10:51:40 +0100

Hi,

I have two bind mounts of the same filesystem

$ grep "/tmp"  /etc/fstab
/dev/vg0/tmpdirs     /mnt/tmpdirs         ext4       acl,user_xattr,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0  1 2
/mnt/tmpdirs/tmp     /tmp                 none       bind                  0 0
/mnt/tmpdirs/var/tmp /var/tmp             none       bind                  0 0

Using mv to move files between the bind mounts makes a slow copy:

$ time mv /var/tmp/BIGFILE  /tmp/

real    0m0.622s
user    0m0.001s
sys     0m0.621s

In theory mv could know somehow that's the same filesystem
and do it like this:

$ time mv /mnt/tmpdirs/tmp/BIGFILE /mnt/tmpdirs/var/tmp/

real    0m0.004s
user    0m0.001s
sys     0m0.003s

Would it be possible to optimize mv regarding bind mounts? Or perhaps
are there other filesystems which do this better than ext4? Specially
the case that the original whole filesystem (/mnt/tmpdirs) is umounted
should work too somewhow.

cu,
Rudi