My application architecture requires me to mount 2 folders at the same partition and move 2 files between them. I have the following mounts:

/drive2/folder1 on /var/www/myapp/folder1 type none (rw,bind)
/drive2/folder2 on /var/www/myapp/folder2 type none (rw,bind)

The problem is in moving file between 2 folders /var/www/myapp/folder1 and /var/www/myapp/folder2. It takes approximately 10 secs for a 1Gb file:

mv /var/www/myapp/folder1/test /var/www/myapp/folder2/

And also it produces high disk activity. However, when I am moving the same file between /drive2/folder1 and /drive2/folder2, it takes less than a sec to move it.

Anyone can give me heads up on this problem?

2 Answers 2


When moving between filesystems, a file is copied to the destination, and then deleted on the source. When moving on the local filesystem, only the filesystem tables are updated which takes far less time. Apparently with a bind mount, mv sees these two points as separate filesystems.

I setup a similar mounts on a local system and ran strace mv folder1/1gb folder2/.

lstat("folder1/1gb", {st_mode=S_IFREG|0644, st_size=1000000000, ...}) = 0
lstat("folder2/1gb", 0x7fff30fd1e20)    = -1 ENOENT (No such file or directory)
rename("folder1/1gb", "folder2/1gb")    = -1 EXDEV (Invalid cross-device link)
unlink("folder2/1gb")                   = -1 ENOENT (No such file or directory)
open("folder1/1gb", O_RDONLY|O_NOFOLLOW) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=1000000000, ...}) = 0
open("folder2/1gb", O_WRONLY|O_CREAT|O_EXCL, 0600) = 4
fstat(4, {st_mode=S_IFREG|0600, st_size=0, ...}) = 0
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 32768) = 32768
write(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 32768) = 32768

oth folder1 and folder2 were actually on the same filesystem, the rename system call failed, with an error reporting that the destination is on a separate device. Short of modifying the kernel and/or core libraries, I doubt there is much you can do to change this.

  • If you can use symlinks instead of bind mounts, mv should treat them as being on the same filesystem.
    – MikeyB
    Commented Nov 3, 2011 at 17:00
  • Yup, symlinks certainly work, but the rename() call is successful, in my testing setup.
    – Zoredache
    Commented Nov 3, 2011 at 17:05

I'm assuming you need to bind mount those folders separately because there are other folders on /drive2 and your application can't use symlinks due to the use of something like chroot.

You can achieve the same thing without a performance penalty if you can add another directory between /drive2 and folder1 and folder2. Then you only need to bind mount that one folder.

 $ ls /drive2/myapp
 folder1         folder2

Then your bind mount will be

 /drive2/myapp on /var/www/myapp/myapp type none (rw,bind)

Now your moves will be instant again

mv /var/www/myapp/myapp/folder1/test /var/www/myapp/myapp/folder2/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .