Why copying files in one partition is much faster than copying files to another partition?

Posted on


Why is it significantly faster to copy files in one partition, than copying them into another?


I don’t think, copying on the same partition is faster. If you mean “moving”, then look at the answer of Daniel Schwartz, he explains perfectly what’s going on.

However if you mean a real copy-operation, I would not expect big performance differences as long as the operation takes place on the same disk. There may be some differences because of the time, the head-placement-operation will consume for harddrives (obviously not for SSDs), but I dont expect the impact of this to be very big.
Maybe there are also some differences because of different caching strategies of the OS, but also this effect, I dont expect to be very big.

What makes a great difference is copying from one to another disc. If the controler is fast, this is much faster than copying on the same disk, because either drive only has to read or to write, not to do both of the operations together (An exception of this rule may be small data, because of the hdd- and controller cache).

Please note that the OS can make links to files. In this case, the data will not be copied, but only a new reference to the data will be created (The file will also not consume double its space). This is very fast. But if you copy your files with explorer or standard shell commands, the files will be copied and not linked.

This is only an issue when copying data to and from the same hard disk drive. Data is read, cached and written back, but before it can start writing, the read/write head must be moved to empty space. Having the source and destination on seperate partions will ensure the corresponding disk sectors are physically far apart. The read/write head will constantly be moving back and forth. Often you can actually hear this.

While the head is moving, data cannot be transfered. Having source and destination on the same partition usually means less time spent moving the head around and therefore more efficient file transfers.

Let’s compare to the two operations. First, copying a file from one partition to another:

  1. The source is opened.

  2. The destination is opened/created.

  3. Space is allocated for the destination.

  4. Every byte of file data is read from the source and written to the destination.

  5. The destination file is closed.

  6. The source file handle is set to unlink on close.

  7. The source file handle is closed, unlinking the file.

  8. Since that is (typically) the last reference to the source file data, the source file data has to be made free.

Now, copying a file from one folder to another on the same partition.

  1. The source is opened.

  2. A new hard link is created to the source file in the destination directory.

  3. The handle to the source file is set to unlink on close.

  4. The source handle is closed, unlinking it. The source file is still linked to the destination directory, so no free space needs to be changed.

Notice that there are fewer steps and also none of them require touching any of the file data or even the free space mapping.

Leave a Reply

Your email address will not be published.