Slashdot Mirror


Mac OS X 10.3 Defrags Automatically

EverLurking writes "There is a very interesting discussion over at Ars' Mac Forum about how Mac OS X 10.3 has implemented an on-the-fly defragmentation scheme for files on the hard drive. Apparently it uses a method known as 'Hot-File-Adaptive-Clustering' to consolidate fragmented files that are under 20 MB in size as they are accessed. Source code from the Davwin 7.0 Kernel is cited as proof that this is happening."

18 of 181 comments (clear)

  1. Amortized cost... by Ianoo · · Score: 3, Interesting

    Obviously doing this process slows down file access a little. I wonder whether any safeguards are in place, such as turning the system off after a certain I/O load is reached? If not, this may not be such a good idea.

    Also, I wonder whether if you were to calculate the extra time (perhaps 500ms) to defragment each fragmented 20MB file against doing a manual defrag every month, and whether it's actually worth it...

    Don't some Linux filesystems already do this to some extent? I could be hallucinating again, but I'm sure I read this somewhere.

    1. Re:Amortized cost... by jrstewart · · Score: 4, Informative

      I can only speak for ext2/ext3. Linux tries to preallocate large blocks when writing files to prevent fragmentation. If you disk is mostly full (or even was once mostly full) or you have heavy concurrent disk activity going on you can still get fragmentation.

      The end goal of the disk subsystem is to get your data to you as soon as you need it. In general that goal would be achieved if the data you want to read next happened to be under the read head. If you're reading sequentially through a single file then this will happen when the file is in a single contiguous region (i.e. unfragmented). For any other access pattern fragmentation doesn't matter as much, since you'll be skipping around the disk regardless of how the files are arranged.

      Prefetching heuristics and caching can hide a lot of these problems from the user as well.

    2. Re:Amortized cost... by clifyt · · Score: 5, Interesting

      "Drives are defragged to allow the OS to access the files faster."

      Are you so sure?

      I have talked with a senior OS designer (one of the non-free ones) and his view is that these days, defragging does more damage than it saves.

      Why? Drives generally have large caches on them and multiple platters / read heads.

      Noting this, the fastest way to get data off a drive might not be a straight line. Its looks pretty when you run the different utilities and makes the home makers of whom believe everything should be put away neat and tidy, but the engineer had mentioned that being defragged means you loose a lot of advantages of those multiple readheads and cache. He claimed that it was actually better to leave your drive to its own devices, allowing for about 30% free space at all times, and you will see a speedup over a defragged drive.

      I didn't believe it at first, but his arguments did make a lot of sense even though it went against everything I had learned before. He actually mentioned if he had his choice, he'd make certain defraggers would NEVER work, but the market believes that these are necessary so its easier to have these things included as well as supporting third parties, so its there.

    3. Re:Amortized cost... by bdsesq · · Score: 5, Insightful

      Noting this, the fastest way to get data off a drive might not be a straight line.

      This is true. However it is also true that a defrag does not have to put the data in physically contigious blocks. It can just as easily put the data in whatever configuration makes retrevial work fastest on that particular drive geometry.

      This means that an intelligent defrag can improve performance.

  2. but but by falcon5768 · · Score: 3, Funny
    I want to see all the pretty colors of blocks moving themselves!!!!!!

    ahh shucks.

    --

    "Slashdot, where telling the truth is overrated but lying is insightful."

  3. Re:In other news.... by squiggleslash · · Score: 3, Interesting
    Er, when you install OS X, you can choose UFS instead of HFS/HFS+. Then you get an old fashioned Unix-style file system. Unfortunately, doing so means that you lose metadata, forks, etc (though the Finder does a sort-of half-arsed job and creates little dot files all over the place to try to at least cover some of the metadata.)

    Me, I'd take the comparatively modern HFS+. I'm still confused as to why metadata isn't being taken seriously by the rest of the computing world.

    --
    You are not alone. This is not normal. None of this is normal.
  4. Autodefrag. (snort) by speechpoet · · Score: 5, Funny

    In my day, we'd crack open the drive on our Mac SE30s, sharpen a magnet on a whetstone, and defrag that sucker by hand.

    Kids these days. It's the MTV, ya know - makes 'em lazy.

    1. Re:Autodefrag. (snort) by jolshefsky · · Score: 4, Funny
      To defrag? Boy were you lucky--my SE hard drive had a crank to start it in the morning.

      Oh wait: that would have been actually useful. (What, nobody else remembers stiction?)

      --
      --- Jason Olshefsky

      Karma: Poser (mostly affected by adding this line long after everyone else did)

  5. Re:In other news.... by bill_mcgonigle · · Score: 4, Informative

    But instead of defraging FFS just makes better decisions as to where to put files....Seriously, if Apple got rid of HFS, none of this technology would be necessary.

    You speak as though HFS+ has trouble with file fragmention. It's easily already one of the best filesystems for avoiding fragmentation - I've worked on Macs that have been run for years without attention and were better than 90% unfragmented. This is considerably better than any of the Microsoft filesystems, for instance. This tweak is an improvement, to get from 90% to 99%.

    HFS+ doesn't just put the files down randomly, either, it has some smarts.

    This also explains why the hard drive on my iBook seems alot hotter since upgrading.

    The only way this feature can do that is if you're writing small files continuously. That's very strange software behavior, and perhaps a worst case for this optimizer. Why would you be doing that?

    Don't get me wrong, HFS+ isn't the best filesystem ever created, but it's very featureful (multiple forks, file ID's, case-preserving, case-insensitive-possible, UNICODE, attributes, 64-bit file sizes, POSIX compliance, etc.) and the MacOS relies on it heavily. Anything to replace it would be a superset of HFS+. Fortunately, Apple hired the guy behind the Be Filesystem a few years back. I doubt he's working on iMovie 3.1.

    --
    My God, it's Full of Source!
    OUTSIDE_IP=$(dig +short my.ip @outsideip.net)
  6. JOUNRALLING my boy JOURNALING by goombah99 · · Score: 3, Informative

    According to the ARS writeup, this feature is on only when journalling is on. This makes total sense, since journalling prevents an incomplete or unverified write from being used.

    --
    Some drink at the fountain of knowledge. Others just gargle.
  7. Re:In other news.... by anarkhos · · Score: 4, Informative

    If you refer to a file by an inode you are basically creating a hard link so if the file is deleted the file still 'exists'.

    Also you cannot get a file path from an inode thus if the file path is changed (moving a file for example) the application cannot know what the new path is.

    A FileID is really more equivalent to a path, or rather used in place of a path with the advantage that the path can change and the fileID remains the same. Thus referring to a FileID is less fragile.

    Also FileIDs are smaller so searching for files using a FolderID or FileID is faster and uses less memory.

    They're not equivalent.

    --
    >80 column hard wrapped e-mail is not a sign of intelligent
    >life
  8. think outside the /. by BortQ · · Score: 4, Insightful
    It seems as if the /. crowd isn't all that impressed by this advance by apple.

    Well that's fine. The real upside of this is for people that have never heard of /. and don't really know what a hard drive is, let alone know how to defrag one.

    Previously these people would just go forever without defragging. Now they can still do that, because Apple is doing it for them behind the scenes.

    This is yet one more example of Apple's winning philosophy: Keep it simple, make it better.

    --

    A Multiplayer Strategy Game for Mac OS X, Windows, and Linux
  9. Re:In other news.... by Teese · · Score: 5, Informative

    Its a just recently added feature!

    See the -s option for newfs_hfs:

    (from man newfs_hfs)

    -s

    Creates a case-sensitive HFS Plus filesystem. By default a case-insensitive filesystem is created. Case-sensitive HFS Plus file systems require a Mac OS X version of 10.3 (Darwin 7.0) or later

    --
    "I'm a Genius!"*


    *Not an actual Genius
  10. Damn! by csoto · · Score: 4, Funny

    That's gonna mess up my UT 2003 ranking! I work hard for those frags! Every one of them!

    --
    There exists no way of exchanging information without making judgments. --Bene Gesserit Axiom
  11. information by djupedal · · Score: 3, Insightful
  12. No such limits. by Trillan · · Score: 3, Informative

    The source code is posted to that thread; the only conditions are (1) 3 minutes after the system time starts (i.e. avoid doing so when booting up), (2) less than 20 MB of size, (3) file isn't already opened.

    The only negative consequence is a possible speed hit, though. There's no danger.

    I'm pretty impressed by this. Sure, it's been done before. Sure, there are more elaborate methods. But this is just a simple little lump of code that'll defragment the worst files most of the time.

  13. Re:Necessarily Useless by berniecase · · Score: 3, Interesting

    Fragmentation is a very real problem for people who need lots of contiguous free space, especially those working with multitrack audio and video files. They can't have drive heads searching around a drive for free blocks of space when they could be writing linearly.

    Even with this file defragmenter built-in, a drive defragmenter is still needed for certain types of users.

  14. Not quite right (clarification) by ploiku · · Score: 5, Informative

    The summary appears to not be quite right.

    To clarify, there are 2 separate file optimizations going on here.

    The first is automatic file defragmentation. When a file is opened, if it is highly fragmented (8+ fragments) and under 20MB in size, it is defragmented. This works by just moving the file to a new, arbitrary, location. This only happens on Journaled HFS+ volumes.

    The second is the "Adaptive Hot File Clustering". Over a period of days, the OS keeps track of files that are read frequently - these are files under 10MB, and which are never written to. At the end of each tracking cycle, the "hottest" files (the files that have been read the most times) are moved to a "hotband" on the disk - this is a part of the disk which is particularly fast given the physical disk characteristics (currently sized at 5MB per GB). "Cold" files are evicted to make room. As a side effect of being moved into the hotband, files are defragmented. Currently, AHFC only works on the boot volume, and only for Journaled HFS+ volumes over 10GB.