15

SSD flash hard drives have started to support TRIM in order to avoid the slowdown that occurs after a while.

How do I do something similar on a SD card ?

Like reformating the SD card, but at a lower-level to avoid the automatic wear-leveling.

7

My understanding is that the current SDCARD spec does not include a TRIM command. Although I am not on the committee, Windows 7's support for TRIM will bring it to the attention of many engineers, and it's reasonable to expect that the command will show up in the SD spec within the next few years.

The OS uses the TRIM command to tell the flash device that a sector will not be read again until it is written. This tells the flash device that the sectors do not need to be copied from one page to another before the first page is erased. This can result in significantly improved performance and improved data privacy.

It would be nice if SD cards could give performance similar to SSDs. I don't see any fundamental reason why the small form factor could not support high-speed access. At the moment, though, if you want high-speed performance, you should use an SSD, not a SD card.

4

I don't know if this is a bogus, but it seems that in Linux fstrim works. I am bit surprised.

fstrim -v /media/32G_SD/
/media/32G_SD/: 7,2 GiB (7705051136 bytes) trimmed

It's 32GiB card formatted with btrfs and I indeed removed around 8GiB. The label is Kingston model: sd10vg2 (grey SD card)

I have to add that you should be careful with fstrim in SSD. And more careful on sdcards. Too much bugs on firmwares. I trust only Intel enterprise series. I had one meltdown with fstrim and SD-card (inaccessible data). I will not fstrim too often on this sdcard and general on sd's.

  • 3
    This is most probably doing MMC_CAP_ERASE for unused dirty blocks. Works slower than TRIM (which lets the controller schedule the actual erase), but the end result should be the same. – Dmitry Grigoryev Sep 11 '17 at 14:36
  • Does it need to be unmounted or something? I only got an error: fstrim: <my_mountpoint> : the discard operation is not supported. I've got an SDxC by Kingston. – Tomasz Gandor Apr 19 '18 at 21:48
  • Mounted. The filesystem has to inform the fstrim command about the available free space. In your case, I suppose your SD card does not support TRIM. – krg May 28 '18 at 8:12
  • 3
    @DmitryGrigoryev right, fstrim sent to SD Cards may not always be "trim" it's essentially ERASE (CMD38) – Irfan Latif Jul 2 at 10:56
3

On Linux:

  • blkdiscard on the unmounted block device (e.g. /dev/mmcblk0) to discard all blocks (renders data inaccessible through normal means, but does not promise to securely erase them).
  • fstrim (on the mounted file system) if you want to keep the data but discard the blocks that are unused.
2

Storage tools claims defragging you SD card increases performance, however they sell the product so they can claim whatever suits them.

Though there are other programs that claim it helps:

Fragmentation refers to the tendency of files, stored in the FAT file system, to become broken into pieces that can end up in very different places within a storage card volume. Fragmentation occurs naturally with time when a storage card is used frequently - creating, deleting, and modifying files. This process is entirely invisible to users.

But PPC Magazine thinks it's a good idea as well. Though not with software:

Werner Ruotsalainen at the PPC Magazine blog shares some good information on whether or not Pocket PC memory cards need to be defragmented, and how to do it.

Some tips:

  • Yes, it's worth defragmenting them every 2-3 months, if there are frequent writes to the card.
  • Never use a Pocket PC utility to do the defragmenting
  • Do consider getting a card reader

If you have a card reader, the process is simple: Copy the files to your hard drive, reformat the card (E.g. "format i: /q /u" but make sure you use the correct drive letter!), and then copy your files back to the card.

But here's some Storage Tools info anyway ;-)

alt text alt text

Storage Tools Description

The most comprehensive storage card management solution, StorageTools is the first product to offer defragmentation functionality for Pocket PC devices, providing dramatic speed improvements by resolving file fragmentations.

With StorageTools you can get detailed device and file system information about your storage cards, analysis of file allocations (slack space) and fragmentation level.

StorageTools works with all media types available on PocketPC/Windows CE devices, including industry standards: ATA compliant memory cards, Compact Flash cards, MicroDrives, Secure Digital (SD) cards, MultiMedia Cards (MMC) and PCMCIA memory cards. You can format storage media with different file system and cluster size.

Scan tool diagnoses and repairs a variety of media problems. It performs several tests, checking everything from the boot sector to its physical surface. If StorageTools finds a problem, it notifies you before making repairs. Optionally allows making all necessary repairs automatically.

With StorageTools defragmenter you achieve maximum performance under Pocket PC/Windows CE with minimum effort! It includes the most professional and user-friendly features ever found in defragmentation software. You must eliminate fragmentation to eliminate the most basic performance bottleneck on your PocketPC device as you can on your powerful desktop computer.

The StorageTools includes full support for all storage/media cards even transparently encrypted volumes by Sentry 2020 for PocketPC, and includes options to choose FAT type and cluster size when formatting, plus the ability to create a backup FAT to improve storage reliability.

Features

  • Display detailed file system statistics
  • Format storage cards with any file system type and any cluster size
  • Verify file system integrity
  • Repair file system errors
  • Supports all Windows CE storage media: MMC/SD, compact flash, etc.
  • Concurrently works with multiple storage cards
  • Automatic card insertion and removal detection
  • Install and Uninstall options
  • Supports FAT and FAT32 file systems
  • Analyze file system fragmentation level
  • Defragment files and free space

Benefits

  • Format recovers storage card space by using smaller cluster size
  • Defragment dramatically improves storage card performance
  • 8
    What does this have to do with TRIM? Defragging doesn't do anything on an SD card. Even if it did, the OS has no control over where the data on an SD card physically resides, so it wouldn't really be possible. I suppose garbage collection is similar to defragging in some ways, but it's purely up to the SD card's controller. You can't control it. TRIM is a command that notifies the controller when data has been erased. Its purpose is to help garbage collection happen more efficiently. The only say an OS has into what an SD card physically does with data is the TRIM command. – William T Froggard Oct 10 '15 at 22:47
  • It's true that some SD cards contain such a poor controller that defragmenting the SD card really improves future reading performance. This is caused by cheap controllers that cannot queue any commands and after OS as emitted one read command the OS must wait for the full read to complete before another can be send. Whitness the difference for stream reading and random 4K read performance for bad SD cards (there can be easily 100x performance difference). – Mikko Rantalainen Nov 10 '16 at 16:43
1

First backup all your data on the SD card. Then you can use the SD Formatter tool and in options select FULL (Erase): https://www.sdcard.org/downloads/formatter_4/

  • SDCard Formatter: Quick format deletes all the file/directory entries by initializing file system parameters of the card, but it does not delete the data written in files. Overwrite format deletes file/directory entries by initializing file system parameters of the card (same as with Quick format), and erases all data by overwriting the user data area completely. So what it does at maximum is to overwrite the data, no TRIM/discard/ERASE (CMD38) happens. – Irfan Latif Jul 2 at 11:02

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.