CARDSPEED - Card Readers and Memory Cards

Cluster Alignment and Card Performance

In my  article about formatting  I already mentioned the  cluster alignment . In most cases, you don't have to worry about that: Some card standards - especially SD and SDHC - already have strict rules how to format a card to get the clusters aligned. Many cards won't suffer from misaligned clusters, but there seem to be a few exceptions.

To answer the obvious question: I don't have any special tools for formatting, I edit the partition table and filesystem sectors using a hex editor.

Why Is Cluster Alignment Important?

Flash memory cards are random access media with a sector size of 512 bytes. But this is only a logical representation. Flash memory can be read out byte-by-byte, but it has to be erased before writing. The erase procedure acts on a whole memory page that is erased within a "flash", hence the name flash memory. Even if you only want to change a single bit, one page has to be read out, flashed, and written back with the modified data. The page size is a power of two equal to or larger than the sector size of 512 bytes, in most cases a value from 4kB to 32kB based on my observations.

If the write size is smaller than the page size, the whole page has to be flashed and written back. If a write operation crosses a page boundary, then two pages have to be read, flashed and written back. The flash card controller could combine consecutive unaligned writes to a series of aligned writes, but there seem to be controllers in use where the write performance suffers from such unaligned writes.

Memory Card Filesystem Setup

For cards other than CompactFlash, there seem to be certain rules how the card should be formatted. The following list is based on detailed analysis of the filesystems of about one hundred memory cards. I don't have access to the documents, these seem to be only available for members of the respective card association.

The basis is of course the FAT Specification from Microsoft (fatgen103.doc). But that document only describes the standard configurations, and points out the risks when changing the configuration within the allowed range.

This means that you get the best performance, if Cluster 2 (the first cluster in the filesystem) is aligned to a page boundary, and the cluster size is equal to or an integer multiple of the page size.

CompactFlash Cards
This is the only card format without any odd rules. Most CF cards have an "old school" partition start at CHS 0/1/1, and cards of more than 256MB use a mapping of C/16/63. In many cases, there is a small unused area at the end due to extended translation and/or the old (and odd) "last cylinder" rule. In general, all filesystem parameters are set to the default values, and Cluster 2 becomes more or less unaligned. With a partition start of LBA 63, and a FAT16 filesystem with default values, Cluster 2 starts at a 1kB boundary.
SD Cards
Due to the card size register layout, most SD cards could be mapped to C/16/32, but the partitions are usually mapped to LBA with C/255/63 and in most cases with an odd partition end (i.e. no cylinder boundary). The partition start is set to a certain value so that the Cluster 2 starts at address 0x40000, 0x50000 or 0x60000 in most cases, i.e. at a 64kB boundary.
SDHC Cards
SDHC cards seem to have the partition start at LBA 8192 (0x400000). By increasing BPB_RsvdSecCnt from 32 (the default value for FAT32) to a much higher value, the address of Cluster 2 is shifted to address 0x800000, an offset of 8MB. The cluster size used is 32kB.
MMC use a mapping of C/16/32 or extended translation with the partition start at CHS 0/1/1 (LBA 32). For MMC of 512MB or less, BPB_RsvdSecCnt is set to a slightly higher value to move Cluster 2 to address 0x48000. I have no data for MMC of 1GB or 2GB, but by increasing the cluster size, this layout could be kept the same for these card sizes. The only 4GB MMCplus I saw so far was partitioned in "SDHC Style" and formatted to FAT32 with 32kB cluster size.
Memory Sticks
Most Memory Sticks have a small unused area at the end, due to extended translation and/or the "last cylinder" rule. The size can be mapped to C/16/32, but the partition start is moved to a higher LBA value to get Cluster 2 aligned to a multiple of 64kB for larger cards, or a multiple of 16kB for smaller cards. The cluster size seems to be 16kB for Memory Sticks up to 64MB, and 32kB for Memory Sticks of 256MB or more. The value for 128MB Memory Sticks is unknown, due to the lack of sample data.
SmartMedia and xD-Picture Cards
While other cards of the same "label capacity" come in slightly different sizes, the size of SmartMedia and xD is 1000 sectors multipled by powers of two, i.e. 16,000 sectors for 8MB cards, up to 4,096,000 sectors for 2GB cards. SmartMedia and xD can be mapped to C/16/32, but the cards use an appropriate partition start to move Cluster 2 to a multiple of 16kB. SmartMedia and xD from 32MB to 1GB also use cluster size of 16kB. Unlike other cards, these cards set the number of FAT 16 root directory entries to 256 instead of the default value 512, saving 8kB of space.

After reading and understanding the above observations, it should be obvious why memory cards should never be formatted outside a device that is specifically built to handle a certain memory card standard.

Odd Card Configurations

As shown above, CompactFlash Cards are the only card family without specific rules regarding formatting and cluster alignment. Most CF cards are not affected by unaligned clusters, but espacially SanDisk CF Cards seem to have controllers where unaligned clusters can cause a significant drop in write speed. But to make things even worse, there are cards that have standard formatting with unaligned clusters, and the controller is patched for best performance at the address of Cluster 2 for the factory formatting. Setting up a filesystem with clusters aligned to "regular" addresses will cause a drop of speed instead of an increase!

The following list is just a quick summary, more information on the actual speed will be added later...

SanDisk Extreme IV CF 4GB
My SanDisk Extreme IV CF 4GB shows best write performance with an offset of 1536 bytes at multiples of 2kB, i.e. addresses ending with 0x600 or 0xE00. With factory formatting, Cluster 2 is located at address 0xFFE00, which means that the controller was configured for this address.
SanDisk Extreme III CF 16GB
My SanDisk Extreme III CF 16GB shows best write performance with an offset of 0 at multiples of 32kB, i.e. addresses ending with 0x0000 or 0x8000. With factory formatting, Cluster 2 is located at address 0x3DCE00, which means that the card is slowed down.
SanDisk Extreme III CF 1GB
My SanDisk Extreme III CF 1GB shows best write performance with an offset of 1kB at multiples of 2kB, i.e. addresses ending with 0x400 or 0xC00. With factory formatting, Cluster 2 is located at address 0x49400, which means that the controller was configured for this address.

Hans-Jürgen Reggel   ·   ·   2007-05-31 ~ 2007-07-12