Archive for February, 2011

Flash Storage Devices (and how slow they are)

Monday, February 21st, 2011

There’s been a lot of press in the past year or two about SSDs, and how they are revolutionising hard disk performance for servers, laptops and desktops (at a price).  In the embedded world, however, we’re pretty much stuck with SDHC cards and USB thumb drives, which are both built down to a price rather than up to a benchmark.  After being bitten by ludicrously long write-a-rootfs times once too often, I thought I’d investigate the problem in detail.

The source of the problem is that SDHC cards and USB thumb drives are both designed to be as cheap as possible, while still offering good performance for typical FAT16 or FAT32 implementations when writing “large” files – ie. photos at 1MB each or videos at somewhere above that.  But when developing for Linux, we don’t use FAT, we use ext2 or ext3 (or, when we can get it, ext4).  These have very different layout and access patterns than FAT.  FAT puts all it’s metadata together at the start of the disk, and then writes files in (usually) 32KB aligned clusters, and in a typical camera implementation these are expected to be contiguous.  Ext2 (from which ext3 and ext4 are very closely derived) puts metadata in groups spread across the disk, close to the data – which means that a large file will be broken up periodically by the gaps for the metadata, and then the metadata itself is broken up into small pieces.  Furthermore, it turns out that the default allocation algoritm for ext2 leaves small gaps between files – ext4 improves this greatly.

SSDs can cope with ext2’s idiosyncracies, because they are also designed to cope with NTFS and Windows’ foibles, and manufacturers have the budget to do so.  (Windows, or at least XP, is extremely bad at keeping files contiguous under normal desktop use.)  Basic SDHC and thunb drives, though, do not.  Ext2’s access pattern heavily exercises mechanisms which, in these cheaper devices, are designed to cope with corner cases rather than daily use. (more…)