# (re)formatting (block-erasing) flash?

## Progman3K

Hi,

I am trying to optimise the time it takes to write files to a flash drive.

For example,

When you purchase a USB key, the very first use of it is very fast: as you write data to the card, very little block-erasing goes on and the data ends up written quite quickly.

Once you have written to every (good) block on the device ONCE, things get substantially slower because the block must always be reset (to either all one-bits or all zero bits, depending on the implementation) BEFORE it wan be written to.

My question, oh great Gentoo-Devs is -

Is there a tool I could run to selectively block-erase the free space on such hardware?

Thanks

----------

## eccerr0r

Of course the trick is in the details. Other than TRIM support, there's not really an easy way to know whether the underlying block device wants all 1's or all 0's for erase.  You could try and create a file with all 1's and then all 0's filling the remainder of the empty space, deleting it, and then do test writes to see which is faster...  Make sure you "defragment" first -- there actually is advantage to defragmenting SSDs.

I've always wondered about free space handling.  Disks really don't know if a particular 'block' is garbage data or not - only the file system knows.  Only way for a non-TRIM disk to know is to assume all of it is real data and overwrite only what the OS wanted to overwrite...

----------

