Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
OS X Businesses Operating Systems Software Utilities (Apple) Apple

Measuring Fragmentation in HFS+ 417

keyblob8K writes "Amit Singh takes a look at fragmentation in HFS+. The author provides numbers from his experiments on several HFS+ disks, and more interestingly he also provides the program he developed for this purpose. From his own limited testing, Apple's filesystem seems pretty solid in the fragmentation avoidance department. I gave hfsdebug a whirl on my 8-month-old iMac and the disk seems to be in good shape. I don't have much idea about ext2/3 or reiser, but I know that my NTFS disks are way more fragmented than this after similar amount of use."
This discussion has been archived. No new comments can be posted.

Measuring Fragmentation in HFS+

Comments Filter:
  • by SirChris ( 676927 ) on Wednesday May 19, 2004 @01:06PM (#9196463) Journal
    what type of file system is there where there is no main allocation table just a header then the file then a header then the file so you could theoretically break a disk and still read the half that was good because all pertinent information relating to a file was in one place?
  • NTFS is not so bad (Score:5, Interesting)

    by W2k ( 540424 ) on Wednesday May 19, 2004 @01:11PM (#9196498) Journal
    It must be pretty damn good if it can outdo NTFS. I have three computers with WinXP (NTFS 5.1) that I run quite a bit of data through on a daily basis, and neither needs to be defragmented very often at all (two of them have never needed defragmentation in more than a year of use). Mind you, I might fall into some special category of people who don't fall victim to fragmentation for some reason. Anyway, my point is, before you make remarks regarding how well this compares to NTFS, and/or how much "Microsoft sucks", consider how well NTFS still holds up considering its age. Another bonus is, I don't risk losing file system integrity if there's a power failure. ;)
  • by dTaylorSingletary ( 448723 ) on Wednesday May 19, 2004 @01:11PM (#9196499) Homepage
    I've had a continued problem on my iBook for the past year or so.

    Under HFS+ in Mac OS X Jaguar or Panther, after about a day of having a clean install, fresh partition and format my hard drive starts making clunking noises and the system locks up (without actually freezing) -- then when reboot attempts are made they take aeons.

    Under ReiserFS in Gentoo Linux for PPC: never have the problem. Same hard drive. Months of use, never once hear the hard drive being funky. No lockups.

    Do I put the blame on HFS? OS X? I just can't figure out this strange problem.
  • by rharder ( 218037 ) on Wednesday May 19, 2004 @01:12PM (#9196502) Homepage
    I still wish there was a reliable, preferrably included, defrag program. I do a lot of video work, and I not only want defragmented files, I want large contiguous sections of free space on my hard drive. I've not had much luck with 3rd party degrag programs (though I've yet to try SpeedDisk).
  • Re:Anonymous (Score:5, Interesting)

    by Malc ( 1751 ) on Wednesday May 19, 2004 @01:15PM (#9196528)
    To be honest, I don't worry too much about NTFS. It seems reliable and for my needs performs satisfactorily. I wonder if fragmentation was an issue overly-promoted by companies like Symantec. What does it mean to have a fragmented disk at logical level when the physical layout is hidden by the drive electronics, which could in fact be translating sectors? Do these defragmentation tools take things like the number of platters in to consideration, and can neighbouring sectors be assumed to be in the same cylinder across platters?
  • by sith ( 15384 ) on Wednesday May 19, 2004 @01:17PM (#9196544)
    Clunk clunk from a drive is the drive saying "I cry out in pain! Replace me!"

    Seriously - it's likely that gentoo just isn't using the particular sector on the drive that OSX is - perhaps there is a file there that doesn't get accessed regularly or something. In any case, Clunk-Clunk is never ok.
  • by shotfeel ( 235240 ) on Wednesday May 19, 2004 @01:17PM (#9196545)
    I thought this was a feature of Panther, not HFS+.

    HFS+ has been around since OS 8.5 (?? somewhere in OS 8). So either this is a feature of HFS+ that hasn't been implemented until now, or its a bit of code added to Panther. Or has HFS+ been updated?
  • by NMerriam ( 15122 ) <NMerriam@artboy.org> on Wednesday May 19, 2004 @01:19PM (#9196562) Homepage
    He didn't mention, however, that when system updates are installed, the final stage of setup is to defragment. Apple is very proactive about avoiding fragmentation, and OSX really does a great job of making sure things run smoothly without requiring the user to know anything about it.
  • by Exitthree ( 646294 ) on Wednesday May 19, 2004 @01:20PM (#9196572) Homepage

    You've only defeated the purpose if you re-fragment the file again after opening it. If this isn't the case, the amortized cost (the initial cost of de-fragmentation when opening the first time minus the speed benefits from a file in a single chunk) over the many times the file is read yields a speed bonus, not a speed loss.

    A good example is me, installing a program from disk onto my computer. I run the program and it accesses a group of files that have been fragmented when copied to my hard drive. The first time it opens the files it spends a little extra time de-fragmenting them. However, subsequent times that I open the program, these files will load faster.

  • Re:Anonymous (Score:2, Interesting)

    by operagost ( 62405 ) on Wednesday May 19, 2004 @01:20PM (#9196578) Homepage Journal
    NTFS is a modern journaling filesystem. There is no reason for concern while using it over other journaling file systems.
  • Panther Defrag (Score:5, Interesting)

    by stang7423 ( 601640 ) on Wednesday May 19, 2004 @01:23PM (#9196597)
    I'm sure someone else will point this out as well but its worth noting. In 10.3 there is kernel level defragmentation. When a file is accessed the kernel checks to see if its fragmented, then moves it to a area of the disk where it can exist unfragmented. I think there is a limitation to file size under 20MB but it may be higher. This still gets rid of a great deal of fragmenation. Just food for thought.
  • HPFS (Score:3, Interesting)

    by gmuslera ( 3436 ) on Wednesday May 19, 2004 @01:23PM (#9196599) Homepage Journal
    When i had OS/2, i enjoyed the low hpfs fragmentation. When you copy a file it gives to it the next free block that fit in that size, as long you have a big enough free chunk of the disk, the file were not fragmentated. But also it unfragmented when more operations where done with the directory or the file system. I remember that a basic "unfragment" script was to go thru all directories and just copy or even rename the files to unfragment them.

    But not sure how this are managed in linux filesystems, not just ext2/3 and reiserfs, but also in xfs and jfs.

  • by chrysalis ( 50680 ) on Wednesday May 19, 2004 @01:24PM (#9196607) Homepage
    Recent 2.6-mm kernels contains Chris Mason's work in order to dramatically reduce the fragmentation of ReiserFS filesystems.

    It's really good on filesystems with a lot of files or on databases.

  • by greymond ( 539980 ) on Wednesday May 19, 2004 @01:25PM (#9196610) Homepage Journal
    Seriously, with NTFS and HFS+ I see very little fragmentation on both my Wintel and Apple machines.

    Both have 40gig HD's and both have applications installed/uninstalled quite often. My PC feels the worst of this as he gets games installed and uninstalled in addition to the apps.

    For example the last time I reinstalled either of these machines was back in january(new year fresh install) and since then my pc has felt the install/uninstal of various games usually ranging from 2-5 gigs each. The Apple has been installed and with the exception of updates, plugins, video codecs and basic small apps that get added/upgraded often has done alright.

    Right now Norton System Works on my PC is saying the drive is 4% fragmented. Disk Warrior on my Apple is saying the drive is 2% fragmented.

    Conclusion: Fragmentation is no longer an issue for the HOME USER(note how i'm not saying your companies network doesn't need to be concerned), unless there still running a FAT32 partition >. which well they deserve to have there computer explode at that point anyway.
  • by Malc ( 1751 ) on Wednesday May 19, 2004 @01:25PM (#9196612)
    You must be too young to remember FAT-based systems. Lost clusters and cross-linked chains... oooh, didn't I enjoy them! NTFS has proven rock-solid and I haven't looked back since I jumped Win95 to WinNT4.
  • by moonbender ( 547943 ) <moonbender@gmaEE ... inus threevowels> on Wednesday May 19, 2004 @01:29PM (#9196648)
    I wrote a script some time ago to more easily let me check how badly my partitions are fragmented, here's it's current output:
    C: 5,72 GB Total, 1,97 GB (34%) Free, 4% Fragmented (8% file fragmentation)
    D: 40,00 GB Total, 1,00 GB (2%) Free, 41% Fragmented (82% file fragmentation)
    E: 66,69 GB Total, 105 MB (0%) Free, 10% Fragmented (21% file fragmentation)
    F: 30,00 GB Total, 1,21 GB (4%) Free, 3% Fragmented (7% file fragmentation)
    G: 10,00 GB Total, 1,54 GB (15%) Free, 5% Fragmented (9% file fragmentation)
    H: 35,03 GB Total, 551 MB (1%) Free, 39% Fragmented (79% file fragmentation)

    D ("Dump") and H ("Online") get a lot of throughput, by personal computing standards anyway, E ("Games") doesn't get changed that much, but if it does, a lot of data leaves and comes. Seems like whenever I defrag D or H, they're back to the values above within days. I guess Win XP has a hard time doing the internal on-the-fly defragging of the hard drives that rarely have moer than 1% free space... Guess I should just get a new HD and have some more free space that way - but I bet I'd have that filled up with junk after some weeks, anyway.

    That said, I'm not sure how relevant this is for NTFS partitions, anyway. I recall hearing that they aren't affected by fragmentation as much as FAT partitions (which were a nightmare), however I'm not sure if that means they don't fragment that easily (heh) or whether accessing data isn't slowed down as much by any existing fragmentation.

    I've also rarely heard anyone talking about fragmentation in the popular Linux file systems, a Unix partisan I know actually thought they didn't fragment full stop, which I don't believe is possible, at least not if you consider situations which might not occur in practice. But then again, I suppose Linux might solve it the same way Apple seems to - I guess I'll know more after a couple of hundred comments on this article. :)
  • Defrag = placebo? (Score:3, Interesting)

    by justforaday ( 560408 ) on Wednesday May 19, 2004 @01:32PM (#9196670)
    I've often wondered if defragging and defrag utils are more of a placebo for people concernced with system performance. In my experience I've never noticed any perceivable difference after using a defrag util, on either OS8/9, OSX, 95, 98SE or XP. Then again, I've always made sure to have plenty of free space on my disks [and made sure they were fast enough] whenever I've done anything seriously disk intensive like multitrack audio...
  • Re:My stats (Score:1, Interesting)

    by Anonymous Coward on Wednesday May 19, 2004 @01:33PM (#9196679)
    how full is your disk. it's easier to stay mostly defragmented if you have lots of free space to play with.
  • by jdunn14 ( 455930 ) <jdunn@iguPERIODanaworks.net minus punct> on Wednesday May 19, 2004 @01:36PM (#9196709) Homepage
    In general, such a file system would have *horrible* performance, especially for writes, since it could require rearranging data on disk in order to allocate more space for a growing file. However, I would bet that some simple embedded filesystems do this sort of thing, especially if they are meant to be mainly read-only. Sorry, I can't just tell you the name of one, but you won't find such a filesystem made for regular desktop usage. Gonna be a special-purpose thing.
  • Re:Defrag = placebo? (Score:5, Interesting)

    by Greyfox ( 87712 ) on Wednesday May 19, 2004 @02:01PM (#9196904) Homepage Journal
    It shouldn't really be an issue post-FAT. I think most people's obsesison with fragementation are a remnant of having to defragment FAT drives regularly. One did it superstitiously in those days because an overly fragmented filesystem did slow down considerably. No modern filesystem has an excuse for not handling fragmentation with no interference from the user.

    As a cute side note, I remember having to explain fragmentation to my high school FORTRAN class and teacher back in the '80's. I'd changed schools in my senior year and the new school had just started using the Apple II FORTRAN environment, which happened to be the same as the Aple II Pascal environment that I'd used at the previous school. The file system was incapable of slapping files into whatever blocks happened to be available (I'm not even sure it used blocks. Probably not...) so you would not be able to save your files if it was too fragmented, even if there was enough space available to do so. Ah those were the days...

  • Defragging XP now... (Score:3, Interesting)

    by PhilHibbs ( 4537 ) <snarks@gmail.com> on Wednesday May 19, 2004 @02:03PM (#9196915) Journal
    My new laptop, with a 60GB 7200RPM disk, is under two months old, and I'm defragmenting it now. It's been running for 5 minutes, and is 3% complete, on a disk that is 62% full.

    20 minutes later, and it's on 17%. That's pretty damn fragmented, in my opinion.
  • by Anonymous Coward on Wednesday May 19, 2004 @02:08PM (#9196945)

    It's a crock and evenyone knows it. It was only put into the kernel to make him stop his whining. Only a fool uses reiserfs for a thing other than a freak show. A fool and his data are soon parted.

  • my stats (Score:3, Interesting)

    by MyDixieWrecked ( 548719 ) on Wednesday May 19, 2004 @02:14PM (#9197021) Homepage Journal
    Out of 232167 non-zero data forks total, 231181 (99.58 %) have no fragmentation.
    Out of 6528 non-zero resource forks total, 6478 (99.23 %) have no fragmentation.

    Not bad. That's 8 months of heavy use since my last format.

    I gotta bring this to work today and see what that machine's like. My co-worker has been complaining that he doesn't have a defrag utility since he got OSX. I've been telling him that I don't think it matters. Now I can prove it to him.

    I remember back in the days of my Powermac 8100/80av, we would leave the 2 800mb drives defragging over the weekend because they had like 75% fragmentation.

  • by NeedleSurfer ( 768029 ) on Wednesday May 19, 2004 @02:35PM (#9197263)
    Yes and no, it won't have any long time effect on your performance but there is a short time effect that can be usefull when dealing with audio. On a Mac, using a drive with block sizes of 64K to 256K (ideal when dealing with digital audio, as long as you set the buffer per track size of your daw to the same size as the blocks on your drive) you can gain up to 8 tracks by defraging your drive. Sometimes on large projects I have to record a file or playback the entire session in edit mode (no tracks frozen, everything real-time and not bounced), after editing for a while the daw refuses to play the project, lags, stutter or present some serious drop-outs, I defrag and this is where I get this 6-8 tracks headroom, but that will last only for a day of work and even then (Pro-Tools, Nuendo, Cubase, MOTU DP all present this caracteristic, as for the other I haven't tested them enough to provide meaningfull data).

    however, defraging is not the same for every defrag utility. For example, I was working with Avid Audiovision about 5-6 years ago on a TV show, it seems that defraging a drive hosting files created or edited with Audiovision with Speed Disk by Symantec would actually corrupt the entire projects contained on the drive (the biggest mistake and the only serious one I had in my career, I didn't loose my job but my boss did loose his temper, live and learn!), audio file were not readable at all after, it was actually a documented bug of Audiovision and I even think it was affecting every OMF files not just the ones used by Audiovision (not sure about this though), thats what happens when your boss won't let you RTFM. Only Disk Express, some Avid defrager or, later, Techtool could defrag those drives.

    On a side note, in the Classic mac (7-9.2), defragmenting your drive was also a way to prevent data corruption, actually its the other way around, not defraging would lead to data corruption. I don't know if its also the case with NTFS, EXT2 et al.
  • portable fragmenter (Score:3, Interesting)

    by harlows_monkeys ( 106428 ) on Wednesday May 19, 2004 @03:00PM (#9197447) Homepage
    Here's how you can write a portable fragmenter, if you need to get a disk very fragmented for testing.
    1. Create small files until you run out of disk space.
    2. Pick a few thousand of the small files at random, and delete them.
    3. Create a large file, large enough to fill the free space.
    4. Go back to #2, unless you are out of small files.
    5. Pick one of the large files, and delete it.

    Result: you have a bunch of large files, all very fragmented, and the free space is very fragmented.

  • Re:Huh? (Score:5, Interesting)

    by bogie ( 31020 ) on Wednesday May 19, 2004 @03:15PM (#9197575) Journal
    Actually the number of Windows users dwarfs the numbers of Linux users here these days. Sure Widows gets beatup on more because of the constant worms etc but have a look at the average "is linux ready for the desktop" thread. You get post after post of people critical of Linux on the desktop. At best some people will agree that linux is fine in some very specific situations. As I've said many times there is a reason why Slashdot won't show recent web browser statistics. My guess is it over 80% IE and not just because people are at work.

    For the record I also use XP on my laptop. Until everything works perfectly out of the box, ACPI and all, I'm not installing any nix on it.
  • by jimfrost ( 58153 ) * <jimf@frostbytes.com> on Wednesday May 19, 2004 @03:34PM (#9197729) Homepage
    Ok, we have this filesystem fragmentation buggaboo that's been plaguing MS-DOS and Windows for more than twenty years. We've got a whole industry built around building tools to fix it.

    That would be well and good if the problem were otherwise insurmountable. But, it turns out, we've known how to minimize, if not entirely eliminate, filesystem fragmentation for twenty years now - since the introduction of the BSD Fast File System.

    It doesn't take expensive (in time, if not in money) tools. All it takes is a moderately clever block allocation algorithm - one that tries to allocate a block close in seek time to the previous one, rather than just picking one at random.

    The fundamental insight that the authors of FFS had was that while there may only be one "optimal" block to pick for the next one in a file, there are tens of blocks that are "almost optimal" and hundreds that are "pretty darn good." This is because a filesystem is not a long linear row of storage bins, one after another, as it is treated by many simplistic filesystems. The bins are stacked on top of each other, and beside each other. While the bin right next to you might be "best", the one right next to that, or in another row beside the one you're on, or in another row above or below, is almost as good.

    The BSD folk decided to group nearby bins into collections and try to allocate from within collections. This organization is known as "cylinder groups" because of the appearance of the group on the disk as a cylinder. Free blocks are managed within cylinder groups rather than across the whole disk.

    It's a trivial concept, but very effective; fragmentation related delays on FFS systems are typically within 10% of optimum.

    This kind of effectiveness is, unfortunately, difficult to achieve when the geometry of the disk is unknown -- and with many modern disk systems the actual disk geometry is falsely reported (usually to work around limits or bugs in older controller software). There has been some research into auto-detecting geometry but an acceptable alternative is to simply group some number of adjacent blocks into an allocation cluster. In any case, many modern filesystems do something like this to minimize fragmentation-related latency.

    The gist of this is that Microsoft could have dramatically reduced the tendency towards fragmentation of any or all of their filesystems by doing nothing else but dropping in an improved block allocator, and done so with 100% backward compatibility (since there is no change to the on-disk format).

    Maybe it was reasonable for them to not bother to so extravagantly waste a few days of their developers' time with MS-DOS and FAT, seeing as they only milked that without significant improvement for eight or nine years, but it's hard to explain the omission when it came to Windows NT. NTFS is a derivative of HPFS which is a derivative of FFS. They had to have known about cylinder group optimizations.

    So the fact that, in 2004, we're still seeing problems with filesystem fragmentation absolutely pisses me off. There's no reason for it, and Microsoft in particular ought to be ashamed of themselves. It's ridiculous that I have to go and degragment my WinXP box every few months (which takes like 18 hours) when the FreeBSD box in the basement continues to run like a well-oiled machine despite the fact that it works with small files 24 hours a day, 365 days a year.

    Hey Microsoft: You guys have like fifty billion bucks in the bank (well, ok, 46 or 47 billion after all the antitrust suits) and yet you can't even duplicate the efforts of some hippy Berkeleyite some twenty years after the fact? What's up with that?

    (I mean "hippy Berkeleyite" in an affectionate way, Kirk. :-)

  • by moongha ( 179616 ) on Wednesday May 19, 2004 @05:58PM (#9199400)
    Case sensitivity is available on HFS+, it's just not the default.

    You can also use UFS.
  • by Anonymous Coward on Wednesday May 19, 2004 @08:25PM (#9200514)
    On any file system. You can have a very fragmented file system in some situations, but typically ANY file system is losing very little performance to fragmentation.

    And fragmentation is not a bugaboo. It's a fact. When you have random allocation on a volume, it will get fragmented. You can go back after the fact and unfragment it, but doing so in any serious fashion when writing files actually degrades performance due to the extra effort required.

    Also note NTFS is not a derivative of HPFS. I cannot speak as to whether HPFS is a derivative of FFS.

    HFS+ does nothing to prevent fragmentation except for use super-clusters. That is, when you extend a file, you get more than one block at at time. When you close the file, some of those blocks might be scavenged, or might not. NTFS could do this, but I believe they do not. However, NTFS on servers has an allocation block size of 8K, which isn't far off of the super-cluster size on HFS+ which I believe is 16K.

    Finally, note that on modern drives, you can seek all the way across the disk in only about 30-50% more time than you can seek a short seek. Thus keeping your blocks close to the current cylinder but not in it has very limited value. Note that this is not the case on optical (CD/DVD) disks.
  • Re:Offtopic (Score:3, Interesting)

    by amRadioHed ( 463061 ) on Wednesday May 19, 2004 @10:12PM (#9201048)
    I'd be interested in the metric you use to compute danger, seeing as how there have been exactly zero terrorist attacks on US soil since 9/11.
    And I'd be interested in the metric you use. Tell me, how often did we have terrorist attacks on US soil before 9/11? Well let's see, there was Oklahoma city, but that was an American so it doesn't really apply does it. So that leaves The first WTC bombing as the most recent attack preceding 9/11. 8 years lie between those two attacks.

    If we take the extremely generous assumption that foreign terrorists attack the US every 8 years, for you to make an even remotely reality based assessment of our relative security since 9/11 I'd say you need to wait at least 12 years without any attacks.

    Granted, the grandparent would have difficulty proving his assertion that we are in much greater danger now, but I'm sure it could be proven that we have many more enemies. That's not exactly comforting.
  • by swilver ( 617741 ) on Wednesday May 19, 2004 @10:43PM (#9201196)
    I've managed to get my download drive (NTFS) so fragmented that the defrag tool in Win2k/XP is unable to defragment it, no matter how often you run it.

    The files on the drive had an average size of 200 MB, were downloaded in 1kB increments several files at a time over a period of a week on average per file.

    The reason for it failing on defraging (it doesn't say it fails, it just doesn't do much and stops after a while) is because the free space was also so badly fragmented that it couldn't even defragment a single file (it expects there is free space in a single chunk large enough to defragment one file... which is hard since the files are all quite large). The worst fragmented files had all well over 5000 fragments, and none less than 100 orso.

    Even after making more than 50% space free on the drive, it was still suffering from fragmented free space and refused to defrag. After a while I decided it was far easier to just copy the whole drive (30 GB) and copy it back... writing the 30 GB back was about 20-30 times faster compared to reading the drive for the initial copy...

    On a side note, I've put the exact same stress on a ext3fs disc, and it also fragmented very badly, despite claims that ext3fs doesn't need defragmentation "because it won't fragment your files much". If free space was also very fragmented, I cannot say, but I assume it was as deleting a very fragmented file would result in a very fragmented area of free space.

    --Swilver

I find you lack of faith in the forth dithturbing. - Darse ("Darth") Vader

Working...