6

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

3
  • 6
    Copying or moving? When moving within a partition, only the file system metadata that describes where the file is needs to be changed. Copying is often faster between separate physical hard drives.
    – Bob
    May 15, 2012 at 6:41
  • @Bob so why cutting from a partition and pasting it to the same one is faster than pasting it to another one? so what happen in cutting process? Jun 18, 2014 at 12:24
  • @AmirrezaNasiri ? "Cutting and pasting" in most file managers is an abstraction for moving. In other words, it is moving.
    – Bob
    Jun 18, 2014 at 12:37

3 Answers 3

3

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.

1

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.

2
  • So why cutting from a partition and pasting it to the same one is faster than pasting it to another one? so what happen in cutting process? Jun 18, 2014 at 12:25
  • @AmirrezaNasiri: If the destination is on the same partition, no files are physically moved. The file system maintains a table which is updated to reflect the fact that a certain range of bytes on the hard drive now makes up a file in a different directory. Updating this table requires very little data to be written. Moving files to a different partition involves the data itself being written to another part of the hard drive. Jun 18, 2014 at 13:28
0

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.

3
  • I think what you're describing is commonly called moving files, not copying. Copying is when a copy of a file is created, i.e. a second file with identical contents. After a copy operation you have 2 identical files, while after a move operation you still have 1 file, only in another location. Moving files is faster within the same partition; copying is often faster between different physical drives.
    – Sergey
    May 15, 2012 at 8:16
  • Windows users commonly use the term "move" to refer to dragging and dropping a file from one Window to another. This question was tagged Windows. May 15, 2012 at 8:43
  • 1
    @DavidSchwartz I would say the correct definition of moving is where the source file is, well, moved, "cut and pasted", to the destination. And copying would be creating a copy, leaving the source file as-is: as you describe in your first operation. I've never actually heard anyone refer to dragging and dropping as moving except when the file is actually being moved. So I'd say your second operation, with the hard link manipulation, is moving. Unless you're referring to copy-on-write, in which case... well, the source file would not be unlinked if that were the case.
    – Bob
    May 15, 2012 at 10:14

You must log in to answer this question.

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