0
$\begingroup$

Because SD cards use flash memory, they should requires wear leveling to avoid significantly shortening the life of the card. At the same time, my understanding is that they usually use a FAT32 file system.

My understanding of FAT32 is that there is a small "file system description" block at the beginning of the device, which is followed by the file allocation table (FAT) describing which files are stored where. However, because the FAT needs to be updated every time a file is moved/copied/appended/etc, then doesn't that mean the FAT gets written to many times more often than the rest of the card?

For example, if each erasable block of an SD card is 4 KB, and it uses a 32-bit address space, they each erasable block of the FAT contains 128 addresses, so the FAT should get erased and written ~128 times as often as the rest of the device. If this hypothetical device has an expected life span of >100k cycles, then should it not wear out around 1k cycles if it spends the entire time formatted with a FAT32 file system?

And, if my current understanding is true, then wouldn't FAT32 be basically the worst possible way to format a flash memory device? Or is this a problem that all file systems have, so FAT32 isn't apreciably worse than anything else?

$\endgroup$
1
  • $\begingroup$ "FAT32 be basically the worst possible way to format a flash memory device" It's also old, based on FAT16 which is even older. So it may have a few drawbacks newer filesystems don't have, which is to be expected. $\endgroup$ – Mast Mar 6 at 13:47
6
$\begingroup$

The OS references blocks using a "logical block address". The SD card then maps this to a physical page of flash memory. With wear leveling, each time data in that block is changed, it will get mapped to a new physical page of flash memory. So, even though the OS is changing the same "logical block address" every time, this is causing different physical pages in flash to be erased and rewritten. This spreads out the "wear" across the entire flash device, lengthening its lifetime and avoiding the problem you mentioned. In other words, although the FAT32 is stored at the same "logical block address", it isn't stored on the same physical page of flash memory every time it is modified.

I'd expect that any commercial flash storage device you buy today will be using wear leveling, because of exactly the problem you mention if wear leveling isn't used. This problem is not specific to FAT32; it occurs with essentially all conventional filesystems.

$\endgroup$
1
  • 1
    $\begingroup$ So it is basically only a problem if you are working directly with a flash memory integrated circuit then? Since anything higher level has to add that interface layer or else burn out way ahead of schedule? $\endgroup$ – Richard Dromey Mar 6 at 2:03
3
$\begingroup$

When flash storage is exposed directly to the operating system, it's used with a file system specifically designed for flash, like JFFS2.

USB and SATA flash drives emulate Winchester hard drives, and do wear leveling in the firmware. The details are proprietary and specific to each drive, but it's probably broadly similar to the way JFFS2 works. A file system like FAT32 is layered on top of this. The FAT32 driver thinks it's writing the same sector over and over, but the firmware maps each write to a different block of flash memory.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.