Skip to content
Sign in
Prez3.6 rating from 80 members38.1K ptsRate

Flash Memory Fragmentation – Myths and Facts (based on the FAT system)

Flash Memory Fragmentation – Myths and Facts

by Anton Tomov on Jun 02

http://www.wizcode.com/articles/comments/flash_memory_fragmentation_myths_and_facts/

Flash Memory Fragmentation and PerformanceA quick Google search shows many "expert" suggestions that defragmentation of solid state drives should give no difference in performance while increasing the wear of flash cards and even possibly killing them.

Myth: Flash cards unlike hard drives do not have movable parts so defragmentation is useless.

On theory, since a flash drive does not have moving parts, its access time is independent on where the data is stored, which is why supposedly flash drives don't need defragmenting.

The fact is that flash memory is physically organized in blocks (or pages) of data, usually 128K or 256K large. Things get even worse from the fact that in order to change even one single byte, the entire page has to be first erased and then re-written with its contents again. In our example the time needed to change one byte of information is calculated the following way:

T = R + E + W

T is the total time, R is the time needed to read the entire flash page containing the byte we wish to change, E is the time required to erase the page and W is the time it takes for the data to be written back to the empty page. Not only we had to read 128KB in order to change a single byte but we also had to erase the entire block (which is very slow) and then write 128KB over again.

To complicate matters even further, it must be noted that there are additional layers between the flash card controller and the file system that cache pages being read and written to. The cache serves for improving performance. It is a simple trade-off between read/write performance and some RAM being used to cache the pages. It is most effective to read or write entire flash pages performance wise. When the operating system instructs the controller to read a particular sector on the card the cache normally retrieves the entire block and stores it internally. What this means is that information that is stored in a contiguous matter is more likely to be found in the cache than non-contiguous information.

Suppose we have a file that is 263892 bytes large and is fragmented. On a FAT32 file system using 1K cluster the file will occupy 260 clusters. In the worst case scenario the clusters will be dispersed across 260 different flash pages. If the file is contiguous all 260 clusters will fit inside 3 flash pages. Caching of the fragmented file will be impossible as it won't fit in the cache (260 pages will require 33MB of RAM to cache) while the defragmented file will fit in just 384K.

And finally the FAT file system stores folders the same way files are being stored - in cluster chains. A large folder that is fragmented and is not cached represents a huge performance penalty for standard file operations like listing the files in that folder, renaming or even deleting a file.

Conclusion: Fragmentation has a serious impact on flash card performance especially during write operations and when the file system is heavily fragmented across many different flash pages.

Myth: Defragmentation shortens flash memory life span.

The truth is that flash memory has a limited number of write cycles. There are two types of flash chips used - NOR and NAND. Flash cards using NOR chips have a life span of approximately 300,000 write cycles while the ones utilizing NAND chips can stand up about 1,000,000 write cycles. NAND had historically less possible write cycles, but is catching up lately as the technology is improving. All fast CF cards are based on NAND flash (NOR flash is slower but has other advantages as processors can boot from it directly).

Just because a flash chip has a given write cycle rating, it doesn't mean that the chip will self-destruct as soon as that threshold is reached. It means that a flash chip with 1 million erase/write endurance threshold limit will have only 0.02 percent of the sample population turn into a bad block when the write threshold is reached for that block.

The flash card controller is tracking how often it wrote to a flash sector and is trying to level the wear of the sectors. This is called wear leveling. The storage card controller monitors how many times each disk block has been written. When a given block has been written above a certain percentage threshold, the solid state flash drive will (in the background, avoiding performance decreases) swap the data in that block with the data in a block that has exhibited a "read-only-like" characteristic.

Simple math shows that even if you write to ALL sectors of a flash card about 10 times a day (that is 20 GB of written data for an average 2GB flash card daily!) it will take about 82 years before 0.02% of the card blocks will turn into bad blocks.

Since defragmentation involves moving non-contiguous clusters belonging to a file chain to a contiguous cluster space the process indeed does wear the storage card. However modern flash cards have a great tolerance and will last for many years of heavy writing before sectors start becoming “bad”. Built-in wear leveling will further minimize card wear. Also once a file chain becomes contiguous (defragmented) it won’t be moved again during the next defragmentation.

Conclusion: Defragmentation indeed increases the number of flash media write-cycles. With modern flash cards life cycle and wear leveling this does not represent a potential problem as it takes decades for the sectors to start becoming bad.

Myth: Backing up the data of a flash card, formatting and then restoring it again will produce a file system free of fragmentation.

There are many opinions that instead of using defragmentation software one can defragment a storage card by performing a full backup of its contents, performing a fresh format and then restoring the files from the backup on the card again. The idea is that the operating system will lay the files in a contiguous way across the card and will therefore produce a free of fragmentation file system.

  • Folders will become heavily fragmented. While the files are likely to be contiguous the same does not apply for folders. The reason is that folders are initially created small (usually one cluster only) and later on as new files are being added the OS extends the folders by adding new clusters to their chains. During the restore process folders will be initially created small and then as the files from the backup are restored inside the folders they will become fragmented as they grow. A folder that is one cluster long on a FAT32 file system using 1K cluster will be able to store about 5 to 6 files before it runs out of free directory entry space (one directory entry is 32 bytes and a long file name occupies usually more than 5 directory entries so one cluster can hold about 5-6 long file names).
  • The entire process is very slow. It will take hours to copy back and forth a large flash card filled with multimedia.
  • There are some specific optimizations carried out by defragmentation software that the backup/restore solution will not solve like flash block alignment or sorting of directory entries.
  • All chances of data recovery are lost. If there were any deleted files that could be restored or file system errors that could be fixed they won't be recoverable at all after the backup/restore solution.
Conclusion: Using the backup/restore approach will not achieve the same results as using a well designed file system defragmenter.

Data reliability on fragmented vs. non-fragmented file systems

Should you ever need to recover lost data or deleted files from a storage card you should be aware that the more contiguous data on the card was the higher the chances of recovering that data is.

Data recovery software works by analyzing the existing data on storage devices and tries to reconstruct deleted or otherwise damaged files. When a file is deleted all information about the clusters it contained is lost. Undelete software will probably be able to locate the beginning of the file but without knowing the exact clusters it won't succeed in recovering the data if the clusters were not contiguous. Same goes for unformat/zero-assumption recovery software that attempts to rescue data from storage media with a damaged file system. Disk checking software like ScanDisk will also perform better and more reliably if the file system is not fragmented. That is the reason all FAT data recovery applications heavily rely on the file system being contiguous.

Conclusion: Keeping a file system free of fragmentation significantly increases the chances of data recovery.

Join the conversation about e.Digital.

Reply

Replies


  1. Kinda an oximoron sayig, no moving parts' then saying it changes, or can be changed,,, lol

    ''The fact is that flash memory is physically organized in blocks (or pages) of data, usually 128K or 256K large. Things get even worse from the fact that in order to change even one single byte, the entire page has to be first erased and then re-written with its contents again. In our example the time needed to change one byte of information is calculated the following way:''

    Dear Robert -

    Please allow me to restructure this question... Trying to understand how we may differ and have

    advantages from other processes.

    *Specifically, can claim 6 line (b) of patent 737 when marking bad segments under a read/write

    block logical format size....salvage the balance of the erase block(array) , or would the whole

    array be marked dead?

    Respectfully,

    Tim


    Hi, Tim,

    It's my understanding that the marking of defective memory segments is not
    limited to the whole array.

    Best regards,

    Robert Putnam,
    Sr. Vice President

    ````
    Here-in-lies the discrepancy imvho.

    ''It is a simple trade-off between read/write performance and some RAM being used to cache the pages''

    Amen in highlighting this -
    ''What this means is that information that is stored in a contiguous matter is more likely to be found in the cache than non-contiguous information.''

    As for Sammies oneNAND - Remember we did Handheld Nor FIRST.

    AIMHO

    e

    1. Rather -

      Here-in-lies the conundrum imvho.

      ''It is a simple trade-off between read/write performance and some RAM being used to cache the pages''

      e

      1. every one knew that...LOL....

        thank you for all your information....I am unable to understand most of it, but I plow ahead in hopes of the rainbow....

        1. Datalight XCFiles File System for SDXC Removable Storage Helps OEMs Get Consumer Devices to Market Quickly

          Bothell, WA, – June 22, 2010 – Datalight announced today XCFiles, a design-ready exFAT-compatible file system for next-generation extended capacity SD (SDXC) cards. The SD Card Association will require use of Microsoft’s exFAT format on all SDXC cards, which are available in 32GB-2TB densities. Given the predominance of SD card use in consumer devices, analysts expect broad industry adoption of exFAT within the next few years.

          “HD Video and other high-demand applications will create a compelling need for high-density storage capacities in most consumer electronic and computer devices,” said Tom Coughlin, Founder and Chairman of the Storage Visions Conferences and President of Coughlin Associates, “The SDXC format is coming at the perfect time to meet this demand by bringing large storage capacities into a very small footprint.”

          XCFiles will be of strong interest to OEMs whose products need to support SDXC cards but who are using operating systems that do have native support for exFAT. Using Datalight XCFiles will enable those manufacturers to get to market more quickly than writing their own exFAT-compatible file system.

          “We are pleased to offer OEMs a commercial-grade, ready-made file system that supports the exFAT format,” said Roy Sherrill, Datalight CEO, “In addition to preserving time-to-market advantage, our customers will also benefit from Datalight’s years of expertise in file system development, testing and support across a wide range of operating systems.”

          XCFiles ships in source code and supports standard POSIX APIs, making it portable to virtually any RTOS or it can be used in designs that do not use an operating system. With support for file sizes greater that 4GB, large numbers of directory entries, XCFiles is a good match for consumer devices with a high data storage demand.

          New Version of FlashFX Pro Offers Performance, Security and Power Efficiency Improvements

          Bothell, WA, – August 2, 2010 – Today Datalight announced FlashFX Pro 4.1, the latest version of its well-known flash memory management software. The new version extends the significant performance and design-flexibility benefits formerly available only for Microsoft Windows CE and Windows Mobile to users of Wind River VxWorks and other RTOS environments.

          Enhanced performance comes courtesy of a “deferred discard” feature which speeds NAND write operations, optimization of the Marvell PXA320 and Texas Instruments OMAP3 platforms, specific optimizations for Samsung OneNAND and Micron SLC NAND, and major improvements in background compaction performance and memory efficiency. The product also extends battery life for mobile devices by enabling suspend/resume operations at the flash level.

          Improved design flexibility is the result of an enhanced OEM-level API allowing a virtual disk to span multiple flash devices and dynamic creation/destruction of block device instances. Generalized support for one-time programming (OTP) and an EA streaming API for use in bootloader environments also enhance ease-of-use. Better security is provided via generalized support for block locking/unlocking and generalized support for flash serial numbers.

          “FlashFX 4.1 represents a major leap forward in performance-optimized flash storage and multi-platform support,” said Ken Whitaker, Datalight Director of Engineering. “Device manufacturers and their customers will benefit from noticeably faster performance and improved design flexibility.”

          The Reliance family of >flash media managers comprise the Datalight >high reliability applications. Dynamic Transaction Point™ technology gives developers full control over performance and data protection characteristics, protecting users from file system corruption, even after unexpected system interruption. Embedded applications can benefit from faster boot times that remain consistent for the life of the product, regardless of disk size. FlashFX™ features pre-written support for over 300 flash parts, works with virtually any NAND controller, and features >bad block management, and background compaction for unrivaled performance.

          About Datalight

          Datalight, Inc. headquartered just north of Seattle, Wash., develops technologies to enable risk-free mobile data. Datalight file system and device driver software ensures reliability, performance and flexibility, and is used worldwide on many of today’s most well-known devices. For more information, visit >http://blog.datalight.com

          For information, contact:
          Kerri McConnell, Director of Marketing
          425.686.1069

  2. letgo....

    If you have an understanding of the of this key point, which I assume you highlighted ....

    "What this means is that information that is stored in a contiguous matter is more likely to be found in the cache than non-contiguous information."

    keep this in mind....e.Digital can do what this writer feels is unlikely.

    With that,

    "Since defragmentation involves moving non-contiguous clusters belonging to a file chain to a contiguous cluster space the process indeed does wear the storage card. However modern flash cards have a great tolerance and will last for many years of heavy writing before sectors start becoming “bad”..."

    e.Digital does not have to worry about shuffling the deck to get data to a more manageable contiguous arrangement....in order to meet this condition..."information that is stored in a contiguous matter is more likely to be found in the cache"

    ===========

    "Things get even worse from the fact that in order to change even one single byte, the entire page has to be first erased and then re-written with its contents again."

    e.Digital does not worry about this issue at all. They do not have to erase (or flash) a block in order to update data.....their logical format allows them to overcome that problem.....managing virtual systems like FAT are the problem.

    emit your points are on taret as well...

    doni