Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Why don't Linux drive fragment?

  1. #1
    Join Date
    May 2005
    Location
    Indiana
    Beans
    1,933
    Distro
    Hardy Heron (Ubuntu Development)

    Why don't Linux drive fragment?

    It's only logical for a hard drive to get fragmented. Here's a simple example:

    You put files A, B, and C on your drive. Then you delete file B leaving a gap on your physical drive. Then you put file D on your drive. There are only two possibilities. Either your computer will put file D after file C, and there will still be a big gap between A and C, or file D can be put in the gap between A and C. Then the odds are that D isn't exactly the size that B was. So either there will be a smaller gap there, or if it's too big, the computer will put part of D between A and C and the rest of D at the end.

    This is how hard drives get fragmented. So how can a Linux drive not get fragmented?

  2. #2
    Join Date
    Feb 2007
    Beans
    29

    Re: Why don't Linux drive fragment?

    Because Linux systems generally use a journaling file system. What this means is that the file system checks first where the file can fit and puts it there instead of just writing the data starting from the first available block in the hard drive.

    http://en.wikipedia.org/wiki/Journaling_file_system
    Last edited by jariku; April 27th, 2007 at 08:30 PM.

  3. #3
    Join Date
    Aug 2006
    Location
    non-local
    Beans
    2,753

    Re: Why don't Linux drive fragment?


  4. #4
    psusi is offline Ubuntu addict and loving it
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Beans
    3,980
    Distro
    Ubuntu Development Release

    Re: Why don't Linux drive fragment?

    Jariku, you completely misunderstand what a journal does. A journal has nothing to do with fragmentation at all; it is a place where the kernel records what changes it is about to make before it makes them, so that if it crashes in the middle of making those changes, it can finish making them when the volume is next mounted. Thus you don't get a set of related changes that are only half done, causing inconsistencies in the filesystem.

    As for the original question, you are correct; all filesystems become fragmented, but linux uses good allocation algorithms that minimize fragmentation so it generally doesn't become a problem, unlike windows, which uses what has been known as the worst allocation algorithm for at least 20 years.

    If you really like watching the disk blocks move around you can use the defrag package in the universe repository to defragment ext2/3 partitions that are not currently mounted. You almost certainly won't be able to tell any difference though, and there is a slight chance it can screw up your disk, so make sure you backup first.

  5. #5
    Join Date
    May 2005
    Location
    Indiana
    Beans
    1,933
    Distro
    Hardy Heron (Ubuntu Development)

    Re: Why don't Linux drive fragment?

    Thanks. This website explained a lot to me. So it's better to have your files scattered all over the hard drive than it is to have them all in one place, but fragmented. The only problem I see with this method is that it would make it a lot harder to shrink a partition.

  6. #6
    Join Date
    Nov 2006
    Location
    Belgium
    Beans
    3,023
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Why don't Linux drive fragment?

    Journaling has nothing to do with it. The non-journaling ext2 filesystem also doesn't fragment (much).
    It's in the way space is pre-allocated for files, so that they can grow without having to be split into two (or more) fragments. As for your example : the free space between 2 files, the result of deleting a file, will only be used for files that fit in there.
    The algoritms used for this are apparently very efficient, and fragmentation only occurs when there is only about 5 % of free disk space left. Fragmentation can be higher in directories with lots of writes and ever changing files (/var, /tmp , space for caches such as on a http proxy server) so on servers these are placed on separate drives so that the read/write actions don't affect other drives with 'normal' files.


    Linux also uses a read-ahead mechanism to cache files (or fragments thereof, if any) in a buffer so that the processor doesn't have to wait for the disk read head to move to the next fragment. So, if fragmentation should occur, it would still not affect the speed at which data is made available.

    http://en.opensuse.org/SDB:EXT2_Fragmentation
    Last edited by koenn; April 27th, 2007 at 09:10 PM. Reason: apparently mist a fews posts

  7. #7
    Join Date
    Jul 2006
    Location
    Washington, DC
    Beans
    1,678
    Distro
    Kubuntu Development Release

    Re: Why don't Linux drive fragment?

    While that site linked is good (the geekblog one), it's not true that it doesn't fragment at all. It does once the drive gets full enough not to leave enough space between files for future writes. Then again, by the time it's that full, you've got more to worry about than fragmentation...like deleting a bunch of stuff...and once you clear off space, unless you manage to clear off space only in one section (good luck), it'll have enough space again not to fragment. My root partition has some fragmentation because it's rather small and rather full. I can see it when fsck runs at startup every 30th mount. It says something about x% non-continuous or something.

    LinuxChix | Linux User #432169 | Ubuntu User #8495 | IRC: maco @ irc.linuxchix.org or irc.freenode.net

  8. #8
    Join Date
    May 2005
    Location
    Indiana
    Beans
    1,933
    Distro
    Hardy Heron (Ubuntu Development)

    Re: Why don't Linux drive fragment?

    Quote Originally Posted by macogw View Post
    While that site linked is good (the geekblog one), it's not true that it doesn't fragment at all. It does once the drive gets full enough not to leave enough space between files for future writes. Then again, by the time it's that full, you've got more to worry about than fragmentation...like deleting a bunch of stuff...and once you clear off space, unless you manage to clear off space only in one section (good luck), it'll have enough space again not to fragment. My root partition has some fragmentation because it's rather small and rather full. I can see it when fsck runs at startup every 30th mount. It says something about x% non-continuous or something.
    Actually, that website says that when a drive gets to be more than 80% full, fragmentation may start to occur.

  9. #9
    Join Date
    Mar 2008
    Location
    Hawaii
    Beans
    806
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Why don't Linux drive fragment?

    Well I don't know about that 80% stuff. My /boot partition is 18% non-continuous, / patiton is 16% non-continuous, /home 17%... and /boot is 18% full, / is 21% full, /home is 23% full.......... ((the non-continuous "%" are not exact.... from memory... But darn close)) So, maybe it is not doing that grate of a job hu... maybe I need to tweek something or just not care at all? My Box is still way faster then it ever was running Ubuntu.... Vista---well we all know the answer to that one The thing that I don't understand is how did the /boot partition get fragmented I guess it all dosn't matter do to the pre-chaches. I see now why partitoning like everything is a good Idea. That will totally save you from problems caused by fragmentation.
    Thinkpad W510, i7-720QM, Nvidia Quadro FX 880m (nouveau), Intel X25-M G2 80GB (OCZ are better), 1080p Wacom Multi-Touch Screen, Intel Centrino Advanced-N + WiMAX 6250, Yubikey OTP

  10. #10
    Join Date
    Jun 2007
    Location
    Melbourne, Australia
    Beans
    17
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Why don't Linux drive fragment?

    When a figure is quoted as the threshold for fragmentation, you need to consider the size of the existing files. Eg, 80% full with 1GB files is different to 80% full with 1MB files.... Take these figures with a pinch of salt.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •