Does the iPhone have to defrag itself with each syncing?

Discussion in 'iPhone' started by Trillium, Aug 11, 2008.

  1. Trillium macrumors newbie

    Joined:
    May 24, 2007
    #1
    Does the iPhone have some sort of auto defragmenting feature since it's memory is pretty small and it is constantly having music, video, podcasts, etc.. recycle through it? Just wondering how it keeps its memory organized.
     
  2. Kyeris macrumors 6502

    Joined:
    Jul 19, 2008
    Location:
    Somewhere in Texas
    #2
    I can see why it would defrag, but I don't think it does during a backup...
     
  3. aphexii macrumors 6502

    Joined:
    Feb 22, 2006
    #3
    Since the iPhone does not use a hard drive and uses flash memory, defragging isn't really needed.

    With a physical hard drive, defragging helps line up large blocks of contiguous information together to keep the disk heads from having to jump around too much. When a drive is fragmented, constantly hunting for data can slow the overall speed of the system down as it physically moves to find each piece of data. Defragging puts the data together, making the movement of the disk heads decrease, thereby speeding up the drive.

    On the iphone, which uses flash memory, there is no physical disk head that needs to move around to find the data. The data is accessible just as quick anywhere it resides.

    Also, if I'm not mistaken, flash memory intentionally fragments data, spreading it in various places around the cell. The reason being that flash memory has a limited number of erase-write cycles. By not reusing the same portion over and over, it extends the usable life of the flash memory.
     
  4. Jeremy W macrumors regular

    Joined:
    Aug 3, 2008
    #4
    Yep, it's called wear leveling.
     
  5. ThunderBull4 macrumors 6502

    Joined:
    Jul 28, 2008
    #5
    ^ Thats quite interesting, thanks mate. So if there is a limited time, when would the memory be non-usable? Approx how many years would it take for all the memory to be worn out? What then?
     
  6. Jeremy W macrumors regular

    Joined:
    Aug 3, 2008
    #6
    It would take a very long time. This PDF from Corsair explains everything very well: http://www.corsairmemory.com/_faq/FAQ_flash_drive_wear_leveling.pdf

    Note the section "Will my Corsair USB Flash drive last more than 10 years?"
     
  7. aphexii macrumors 6502

    Joined:
    Feb 22, 2006
    #7
    The relevant text for those scared of PDF's :)

     
  8. Interstella5555 macrumors 603

    Interstella5555

    Joined:
    Jun 30, 2008
    #8
    Since OS X itself doesn't require defrags, and iPhone OS is built off it, I would really doubt it.
     
  9. aphexii macrumors 6502

    Joined:
    Feb 22, 2006
    #9
    While I agree that OSX does a great job without needing a defrag, thats not the reason the iPhone doesn't need it. See my post above.
     
  10. ThunderBull4 macrumors 6502

    Joined:
    Jul 28, 2008
    #10
    That's a good question... (although slowly going off-topic) Why doesn't OSX require defrag? That's a hard drive and not flash drive correct?
     
  11. aphexii macrumors 6502

    Joined:
    Feb 22, 2006
    #11
    Apple provides a good support article about it, http://support.apple.com/kb/HT1375

    Specifically;

     
  12. Trillium thread starter macrumors newbie

    Joined:
    May 24, 2007
  13. kdarling macrumors demi-god

    kdarling

    Joined:
    Jun 9, 2007
    Location:
    First university coding class = 46 years ago
    #13
    Flash is fun. Especially when it's a raw chip, as in the iPhone, which doesn't have even a flash drive. (Flash sticks and drives are very different from the raw chip... they include wear leveling, bad block management and other logic inside... whereas a memory chip has none of that and the OS itself must spend time handling these things.)

    Memory blocks are 256KB each and must be erased and rewritten as a whole, even if you change just one byte.

    Consider what happens if you have a 4GB device with movies and OS using up 3.8GB worth. Now there's only 200MB free and it could get used a lot.

    So what flash file systems sometimes must do, is move files around for wear leveling. In other words, if the 200MB got used a lot, then it would be logically moved to a different physical location, and a less-often-changed file (such as a movie data section) would be swapped with it, so no single memory block wouldn't be written to as much.
     
  14. Trillium thread starter macrumors newbie

    Joined:
    May 24, 2007
    #14
    So over time, blocks of the phones memory will go bad or at least become high risk for going bad? Does that mean after 3 or 4 years the phone's OS might start avoiding 10-20% of the hottest memory sectors? Will it gradually lose available memory?
     
  15. Interstella5555 macrumors 603

    Interstella5555

    Joined:
    Jun 30, 2008
    #15
    (nods) I just don't have the technical knowledge to explain why the iPhone, iPod, and flash drives wouldn't need to be defraged. Thanks :)
     
  16. kdarling macrumors demi-god

    kdarling

    Joined:
    Jun 9, 2007
    Location:
    First university coding class = 46 years ago
    #16
    Yes, over time blocks can go bad, similar to hard drive sectors going bad. So the file system keeps an on-chip erase-write counter for each block, to avoid reusing the same block too much. If it has to, it should move files around to even things out.

    (For that matter, up to 100MB per 4GB stated capacity, can be bad from the factory and still be considered a good chip. E.g. a 16GB chip can have 400MB bad from the start. This type of Flash has high capacity, but is relatively inexpensive because it doesn't have to be perfect even right away.)

    The original Samsung flash chips used in the first iPhone, have a 5,000 write cycle lifetime. For iPods and other mostly playback devices, this is perfectly fine. You'd have rewrite the entire memory with new movies or songs or applications every single day for 13+ years to use up the cycles.

    The larger the chip, of course, the less likely you'd own the device long enough to ever notice any loss, because there's more blocks that can be swapped and reused. A 1MB flash could be killed quickly if it were constantly used for web cache or app log files. Perhaps even within weeks. But 8GB is 8,000 times as large, and would take 8,000 times as many weeks. That's a pretty long time.
     

Share This Page