Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Trillium

macrumors newbie
Original poster
May 24, 2007
22
0
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.
 

aphexii

macrumors 6502
Feb 22, 2006
349
0
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.
 

ThunderBull4

macrumors 6502
Jul 28, 2008
272
0
^ 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?
 

Jeremy W

macrumors regular
Aug 3, 2008
141
5

aphexii

macrumors 6502
Feb 22, 2006
349
0
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?"

The relevant text for those scared of PDF's :)

Will my Corsair USB Flash drive last
more than 10 years?

Yes. All Corsair flash drives are built with memory
components that can handle AT LEAST 10,000 write
cycles; typically they will handle an order of
magnitude more than this. So, this means that in
order to exhaust the drive in ten years, one would
have to write to EVERY BLOCK in the device about
2.7 times per day, every single day. We simply can’t
conceive of such a usage scenario; this would mean
that on a fairly typical 8 GByte drive, one would need
to write over 21 GBytes of data to it every day for ten
years! USB flash drives simply are not used in this
way.

If one thinks he or she might actually try this, we
suggest buying a Corsair Flash Voyager GT or a
Corsair Flash Survivor GT USB drive. They are built
with components guaranteed for 100,000 write
cycles. With these, one can write over 210 GBytes of
data to the drive each day, for ten years!
 

ThunderBull4

macrumors 6502
Jul 28, 2008
272
0
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?
 

aphexii

macrumors 6502
Feb 22, 2006
349
0
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?

Apple provides a good support article about it, http://support.apple.com/kb/HT1375

Specifically;

Do I need to optimize?

You probably won't need to optimize at all if you use Mac OS X. Here's why:

Hard disk capacity is generally much greater now than a few years ago. With more free space available, the file system doesn't need to fill up every "nook and cranny." Mac OS Extended formatting (HFS Plus) avoids reusing space from deleted files as much as possible, to avoid prematurely filling small areas of recently-freed space.
Mac OS X 10.2 and later includes delayed allocation for Mac OS X Extended-formatted volumes. This allows a number of small allocations to be combined into a single large allocation in one area of the disk.
Fragmentation was often caused by continually appending data to existing files, especially with resource forks. With faster hard drives and better caching, as well as the new application packaging format, many applications simply rewrite the entire file each time. Mac OS X 10.3 Panther can also automatically defragment such slow-growing files. This process is sometimes known as "Hot-File-Adaptive-Clustering."
Aggressive read-ahead and write-behind caching means that minor fragmentation has less effect on perceived system performance.

For these reasons, there is little benefit to defragmenting.

Note:Mac OS X systems use hundreds of thousands of small files, many of which are rarely accessed. Optimizing them can be a major effort for very little practical gain. There is also a chance that one of the files placed in the "hot band" for rapid reads during system startup might be moved during defragmentation, which would decrease performance.
 

kdarling

macrumors P6
The relevant text for those scared of PDF's :)

... memory components that can handle AT LEAST 10,000 write cycles; typically they will handle an order of magnitude more than this. So, this means that in order to exhaust the drive in ten years, one would have to write to EVERY BLOCK in the device about 2.7 times per day, every single day...

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.
 

Trillium

macrumors newbie
Original poster
May 24, 2007
22
0
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?
 

Interstella5555

macrumors 603
Jun 30, 2008
5,219
13
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.

(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 :)
 

kdarling

macrumors P6
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?

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.