View Full Version : Defragmenting the SD card
Adam Helberg
08-20-2007, 12:30 PM
Every once in a while I've been defragmenting the card on my PC using a card reader. I've never seen this discussed anywhere. Anyone else do this? Does it speed access to files on the card?
Adam
BrentDC
08-20-2007, 03:17 PM
From what I've read, people are pretty split on wether it needs to be done or not. Just look at this http://www.mtekk.com.au/Forums/tabid/56/forumid/2/postid/42099/view/topic/Default.aspx
pruss
08-20-2007, 04:47 PM
It decreases the lifetime of the card. Depending on caching is implemented, I could imagine it speeding up access slightly, but it's not worth it given the damage it does to the card.
One thing to note is that there are two kinds of fragmentation - file fragmentation and structure fragmentation. SD cards have their own internal memory management structure, so software-based defragmentation probably isn't even doing what you think it is -- the cards are designed to balance data writes out across the entire memory area to minimize media deterioration.
Thus, when you defragment, all it will do is cluster all the file position references in the FAT table; the actual data on the card will still be fragmented.
I'm of the opinion that an optimized FAT table is not worth the degradation to the physical medium.
Adam Helberg
08-20-2007, 05:22 PM
What happens as the card approaches close to its lifetime? How do I know the card is worn?
dmccunney
08-20-2007, 05:26 PM
It decreases the lifetime of the card. Depending on caching is implemented, I could imagine it speeding up access slightly, but it's not worth it given the damage it does to the card.The fundamental problem you run into is that flash memory used in cards has a finite number of writes possible (something like 100,000, if I recall correctly.) Cells on the card "wear out". Circuitry on the card transparently maps things so dead spots aren't used, but there are limits. We get away with that on expansion cards in PDAs because they are written to far less than they are read, and we are likely to replace cards with higher capacity models long before wear becomes noticeable.
I've defragmented cards and seen no speedup. That makes sense: on an actual disk, fragmentation can cause files to be scattered in multiple pieces all over the disk, and the drive takes longer to seek and read all of the parts of the file.
On a memory card, you may see file fragmentation, but it's flash memory. Seek times to any specific location on the card should be the same, and you don't have variables like "rotational latency" (the time spent for the disk to spin until the desired sector comes under the read/write heads) or the track to track seek time as the heads are moved inward or outward on the drive to be positioned over the correct track.
I have had occasion put a card into a USB reader and use CHKDSK to repair cards with damaged file systems. Expansion cards are formatted with the FAT16 (for cards up to 2GB) or FAT32 file systems (for newer 4GB cards), and can develop "lost clusters" just as real drives can. These will mightily confuse PalmOS and your applications.
(The smallest unit of space on a disk readable/writeable in open operation is the cluster. It's possible on FAT drives for clusters to be marked as allocated, but not actually owned by any file. These are "lost clusters", and confuse the OS. Running CHKDSK allocates lost clusters to dummy file names like FILE0000.CHK, which can then be examined and delted if they don't contain valuable data.)
A USB card reader is an essential accessory if you deal with expansion cards.
______
Dennis
dmccunney
08-20-2007, 05:33 PM
What happens as the card approaches close to its lifetime? How do I know the card is worn?It's not that simple. As mentioned elsewhere, flash media has a finite number of write operations before it can't be written to. But it doesn't wear out all at once. Individual cells will go bad, and the circuitry on the card will map things so they don't get used. What you'll get is a gradual degradation, not a sudden failure.
But when you think about it, expansion cards for PDAs primarily store data that is read, not written. You are likely to replace the card with a higher capacity model long before you will notice virtual "wear".
______
Dennis
scottl
08-20-2007, 09:02 PM
SD cards occassionally just act screwed up. Whether backups fail or an app doesn't work as it should, you know something's not right. At that time I copy the files off to another drive (hopefully still all accessible), then reformat the card and copy the files back. I suppose this should at least create a less fragmented file system on the card. I would think this couldn't hurt to set an alarm to run this procedure every 6 months or so. Thoughts anyone?
dmccunney
08-21-2007, 12:54 AM
SD cards occassionally just act screwed up. Whether backups fail or an app doesn't work as it should, you know something's not right. At that time I copy the files off to another drive (hopefully still all accessible), then reformat the card and copy the files back. I suppose this should at least create a less fragmented file system on the card. I would think this couldn't hurt to set an alarm to run this procedure every 6 months or so. Thoughts anyone?Reformatting and copying files files back will certainly create a less fragmented file system. The question is how fragmented it actually was, and whether fragmentation was the problem.
Remember, these are FAT formatted drives, with the same potential problems real disks can have like lost clusters. I'd try sticking the card in a USB reader and running CHKDSK /F before I went to the extreme of reformatting.
Since you read an SD card in a PDA a lot more than you write to it, I wouldn't expect a great deal of fragmentation.
______
Dennis
juggernaut#2
08-21-2007, 04:18 AM
The main reason fragmentation is a speed problem on hard disks is the way they work: the write/read head is fixed and the storage media is spinning underneath it. That way the write/read head has to wait until the part containing the wanted media is coming itīs way. Therefore you can achieve a reasonable speed gain by giving the data a physical order on the disk that makes for continous reading without having to move the write/read head - at itīs best to arrange the data (= i.e. the file) in a physical "circle" so that the read/write head is able to read the whole thing within just one turn of the spinning disk (instead of waiting like 10 turns).
SD cards on the other hand arenīt spinning. Data is adressed in physical blocks, like chunks. If a file uses say 10 blocks of data, 10 read operations have to be performed, it (almost) doesnīt matter if these 10 read operations are adressing continous blocks or fragmented blocks. Therefore fragmentation on cards is not an issue.
Windows offers you to defragment them anyway. Try it, you will not have a noticable speed gain.
vBulletin v3.0.3, Copyright ©2000-2012, Jelsoft Enterprises Ltd.