Quote:
Originally Posted by jocampo
There is a min amount of fragmentation after a lot of writes but because there are no physical heads like regular hard drives, it is not as bad or noticeable as regular disks. The problem is that defragmenting itself affects flash memory lifespan
Now, that's my understanding, ... it would be nice if you have any article or link about it to take a further look ...
|
I do not recall where I have seen the futility of attempting to defragment flash memory discussed in detail, but it is easy enough to figure out from the basics. I glanced through the following links before my original post, but the former does not explicitly mention fragmentation and I was afraid the latter might seem to imply that any information in it is specific to USB.
http://en.wikipedia.org/wiki/Flash_memory
and
http://en.wikipedia.org/wiki/USB_flash_drive
Flash drives present an interface that appears to be a sequential mapping of storage locations, but not only are they not sequential, the the device frequently changes the physical block that a particular address points to. In addition, a flash memory block is much larger than a disk sector and probably much lager than a file system cluster. The remapping is used to implement wear leveling and the block size is inherent to the physical construction of the flash memory.
Wear leveling is needed because flash memory cells wear out after a number of writes, a smaller number than they would like you to believe. Whenever a file on flash is changed, the flash device copies the entire block containing the change to a never written block and remaps the address to point to that new block. When the device runs out of never written blocks, it has to erase an entire previously written but no longer used block, then write to that. To change even a single bit in a file, the flash needs to read the entire block that has that bit, change that bit, erase an unused block, write the entire changed block and remap it address. Now think what happens when a software application tries to defragment at the file system cluster level.
Fragmentation has no meaning for a flash drive, the block addressing is completely arbitrary. Trying to defragment a flash drive could easily cause every block to be erased and rewritten several times. That is just for the blocks storing the file contents. Just think about the blocks containing the FAT. Those get moved many times in a defragment attempt on a flash drive.
Trying to defragment flash not only does not make data access any faster, it also causes the drive to wear out much sooner.
Something to think about. Let's say you put 100 books on a new reader, a few at a time, then do not delete or add any books for months as you read the books that are there. Every time you switch to reading a different book or stop reading for a while or make a bookmark or highlight, your reader keeps track of your last page read, marks and notes. Those changes may not change the size of the files, so the file system thinks nothing has moved, yet the flash device has already moved blocks around every time the reader has changed your book state. Presumably, the programmers try to minimize the number of writes to flash, but they have to save your last page read sometime, probably when you or the device exits the book (to open another, or go to the bookshelf, or whatever. So your flash is getting "fragmented" even when the file system thinks it is not. And even when the file system thinks there is lots of fragmentation, there really is no difference in access time. But trying to defragment will increase wear and take a long time.