Thursday, May 2, 2019

windows 7 - The speed of copying a file from a PC to a USB Flash drive started at 30MB/s and decreased to 5.8 MB/s, why?


If I copy a 8GB file from the PC to a USB Flash Drive, the speed will start at around 30 MB/s... maybe 28 MB/s, and then gradually, after a minute, it will go down to 15 MB/s and finally settle down at 5.8 MB/s.


But I thought if it is a hard drive, then probably there is the RAM cache and also the internal hard drive cache, and will make the copying of file from PC to hard drive appear fast at first.


But for a USB Flash drive, there should be no internal cache for the USB Flash drive itself. Is there a RAM cache for it, so that's why the initial copying seems so fast?


Answer



Windows will buffer the writing for as long as it can, so the first chunk will write faster than the rest. The display is showing the over-all average so it is initially high and slowly drops down towards the actual write speed of the flash drive which is presumably a little under 5.8MB/s.


Even though Windows default to not holding writes for USB drives like this in cache for long (written data is flushed to disk a small amount of time or immediately when the file is closed), it will still buffer writing a little while there is active writing still going on and also the copy operation may have its own buffer so it will keep reading as fast as it can until this is full, so the initial speed will look faster then the over-all speed. This is also why the copy progress display will sometimes sit at 100% for a second or two after a long write operation - as the copy operation closes the file the call to the "close" function blocks until the final few blocks of data have been written.


It is possible to tell the OS to perform completely unbuffered write operations, but very little code does this (Windows Explorer doesn't) as it stands in the way of a number of potential small optimisations (in the OS and the drive's controller) that can speed up write operations.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...