Defragmentation of Linux Filesystems

[ Friday, 23 May 2008, optimizationkit ]

There is a myth that “linux filesystems don’t need to be defragmented.” As it may be truth in general, it still can be dispelled by a simple script, which creates a certain number of directories and in each of them creates and deletes a certain number of files - in, let’s say, two passes. So, does your filesystem need defragmentation?

(!!!WARNING!!! In this article we use the fsck.ext3 program to check the degree of filesystem fragmentation - before using this program on your own better get familiar with its documentation. An unskilled use of fsck on a mounted filesystem can cause data failure. !!!WARNING!!!)

Let’s make an experiment - we’re going to start with creating a filesystem image:

dd if=/dev/zero of=filesystem.img bs=256M count=1

Next we’re going to create a new filesystem (I suggest ext2 or ext3, because it’s easy to obtain information about the degree of filesystem fragmentation for those).

/sbin/mkfs.ext3 filesystem.img

Now we can check the fragmentation degree of the newly-created filesystem:

/sbin/fsck.ext3 -nfv filesystem.img
e2fsck 1.40.4 (31-Dec-2007)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

11 inodes used (0.02%)
1 non-contiguous inode (9.1%)
number of inodes with blocks ind/dind/tind: 0/0/0
18561 blocks used (7.08%)
0 bad blocks
0 large files

0 regular files
2 directories
0 character device files
0 block device files
0 fifos
0 links
0 symbolic links (0 fast symbolic links)
0 sockets
--------
2 files

The information about the fragmentation degree contains the line:

1 non-contiguous inode (9.1%)

This is how the situation looks like on a “fresh” filesystem. It’s very easy to simulate how it would look like on an frequently used filesystem (on which we delete and save new files a lot). Let’s execute a the frag.sh script

It’s enough to mount a test-filesystem-image:

mount -o loop filesystem.img /mnt/loop0/

and next give to the script the directory name, in which the filesystem image is mounted:

frag.sh /mnt/loop0/

The script will show many notifications, like:

Creating file /mnt/loop0//8/file-128
28444+0 records read
28444+0 records saved
85332 bytes (85 kB) copied, 0,173525 s, 492 kB/s
step = 6
Deleting file /mnt/loop0//8/file-0

Next we have to unmount our test-filesystem:

umount /mnt/loop0/

and again check the fragmentation degree:

/sbin/fsck.ext3 -nfv filesystem.img

Because the script creates randomly sized files and deletes randomly chosen files, the data can significantly differ from the given below

e2fsck 1.40.4 (31-Dec-2007)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

895 inodes used (1.37%)
315 non-contiguous inodes (35.2%)
number of inodes with blocks ind/dind/tind: 735/0/0
77202 blocks used (29.45%)
0 bad blocks
0 large files

875 regular files
11 directories
0 character device files
0 block device files
0 fifos
0 links
0 symbolic links (0 fast symbolic links)
0 sockets
--------
886 files

As you can see — 35.2% of the inodes are not placed continuously — the fragmentation degree of files in our image is very high.

To have a point of reference for further experiments I suggest to make a backup of this image:

cp filesystem.img filesystem-backup.img

The ok_defrag program that we’re going to use for defragmenting can be downloaded from here.

In order to for the program to work, the python-dialog package is required, so install it using your package manager of choice.

The working principles of this program are based on the ones shown in Con Kolivas’ defrag. However, ok_defrag doesn’t fumble at the filesystem’s data structures, as professional programs like Diskeeper or Windows Defrag do.

The program is to be executed as follows:

ok_defrag -l log.txt -d /mnt/loop0/

The flags -l and -d are obligatory. The log of the program work will let us recover data, if something goes wrong, e.g. if the power-supply would fail during the job. The -d flag shows the directory with files, which we want to defragment.

First ok_defrag creates a list of directories, which are placed in the pointed directory — the list is sorted by directory size - from the largest to the smallest. Next for each directory of the list, the program creates a list of files, which are placed in those directories - it’s also sorted by size, from the largest to the smallest. Such a file sorting method should provide the best results during defragmentation.

Each file is copied to the /tmp/ok_defrag_tmp file, and then the content of this file is moved to the original location - such a simple method repeated a few times for each file (3 times by default) should provide the desired result. Let’s see, how it works out.

We have to mount our test-filesystem again:

sudo mount -o loop filesystem.img /mnt/loop0/

Then we run ok_defrag:

ok_defrag -l log.txt -d /mnt/loop0/

Now we have to wait a while (!!!WARNING!!! The defragmentation process should not be interrupted !!!WARNING!!!)… When the process finishes, we can unmount the filesystem:

umount /mnt/loop0/

and check the final result:

/sbin/fsck.ext3 -nfv filesystem.img
e2fsck 1.40.4 (31-Dec-2007)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

895 inodes used (1.37%)
84 non-contiguous inodes (9.4%)
number of inodes with blocks ind/dind/tind: 735/0/0
77202 blocks used (29.45%)
0 bad blocks
0 large files

875 regular files
11 directories
0 character device files
0 block device files
0 fifos
0 links
0 symbolic links (0 fast symbolic links)
0 sockets
--------
886 files

It was able to decrease fragmentation level from 35.2% to 9.4%. Another run of the process should decrease the fragmentation level even more. Instead of running ok_defrag a couple of times, you can add a -f flag to the program command line — then the defragmentation process will be repeated a specified number of times.

Opposite to Con Kolivas’ defrag, ok_defrag has a paranoic approach to data safety. Each defragment operation is divided into the following stages:

  • writing down the time of the last file modification,
  • writing down the file’s checksum,
  • copying the file to /tmp/ok_defrag_tmp,
  • testing the checksum of the /tmp/ok_defrag_tmp file,
  • comparing both checksums — if they differ from each other, it means you have problems with your hardware or our system — the defragmentation process for this file is interrupted,
  • another testing of the modification time for the original file — if it has been modified after the copy had been made, the defragmentation process for this file is interrupted,
  • if all of the above stages are completed successfully, the content of the /tmp/ok_defrag_tmp file is moved to the original file,
  • another testing of the file’s checksum - if the checksum differs from the original, it means something went really wrong - the program terminates.

An attentive user will notice that on the seventh stage, when moving the content of /tmp/ok_defrag_tmp to the original file, /tmp/ok_defrag_tmp is not being blocked for writing to other programs. It’s a defect, which (I hope) can be eliminated, because it hinders the defragmentation process in some directories, in which the data is still being written, e.g. logs.

If something during the data defragmentation process went wrong, e.g. unexpected power failure occurred - you need to run fsck on the filesystem. Filesystems with journaling should handle this problem - because ok_defrag doesn’t really make any abracadabra, but only moves files.

But if a file got damaged, you need to check the log - there is information about the performed tasks and checksums of files from all stages.

Checking /mnt/loop0/8/file-91 md5sum
md5sum = b8b828bda1b12173f8f8b0b87d8cd872
Copying /mnt/loop0/8/file-91 to /tmp/ok_defrag_tmp
Done.
Checking /tmp/ok_defrag_tmp md5sum
md5sum = b8b828bda1b12173f8f8b0b87d8cd872
Moving /tmp/ok_defrag_tmp to /mnt/loop0/8/file-91
Done.
Checking /mnt/loop0/8/file-91 md5sum
md5sum = b8b828bda1b12173f8f8b0b87d8cd872

If, e.g. a log breaks at “Moving /tmp/ok_defrag_tmp to /foo/bar/bas” it means, the file hasn’t realy been fully moved — its copy is placed in /tmp/ok_defrag_tmp — you just need to replace the file.

Some systems have a functionality to remove files located in /tmp during bootup. The best thing would be to turn it off for the time of defragmentation.

To check the effects of defragmentation the best thing is to use seekwatcher (it requires blktrace, CONFIG_BLK_DEV_IO_TRACE and CONFIG_DEBUG_FS options in kernel, and python-matplotlib with its dependencies).

A simple test:

seekwatcher -t find.trace -o find.png -p
'sync; echo 1 > /proc/sys/vm/drop_caches; for file in `find /mnt/loop0/ \
-type f`; do cat $file > /dev/null; done '
-d /dev/

shows the difference in file reading speed between a fragmented filesystem (filesystem-copy.img)

and a defragmented filesystem (filesystem.img)

I suggest to perform the defragmentation of directories, where the system can write data, after the system bootup to /bin/sh — parameter init=/bin/sh in the kernel command line. This should guarantee a trouble-free operation without worries about any data failure.

When is there no need to perform a defragmentation? Generally speaking, if fsck returns non-contiguous inode below 10%.

How long does the defragmentation process take? It depends on the disk speed, the amount and size of files — each file is copied and moved several times, so this operation can take a very long, long time if you have thousands of files.

I also have to remind of one more thing - it’s worth to check, how much free space we have on /tmp — the lack of free space won’t cause file damage — the checksums are tested the whole time — but it’s still worth doing. Remember that the defragmented disk should always have a reasonable amount of free space. If this is always the case, it may happen that you indeed will never need to perform the process. But it’s still good to be aware of the fact that you may occassionally do it on Linux as well.

This is a translation of the article Defragmentacja linuksowych systemów plików. Translated by Adam Dziuba. Proof-read by michuk.

Subscribe to RSS feed for this article!

54 Comments

fold this thread Rambo Tribble  Friday, 23 May 2008 o godz. 4:57 pm #  Add karma Subtract karma  +0

As a control it might be worthwhile to run your fragmentation script, run the system normally for a period, say a week or so, then check the fragmentation level to see if the fragmentation has been decreased by the normal filesystem operation.

 
fold this thread chlue  Friday, 23 May 2008 o godz. 10:52 pm #  Add karma Subtract karma  +0

I still wonder if it would not be easier to just copy a whole partition to another partition/harddrive, wipe the original data and then copy it back. (make two copies and checksums for added security)

Only real problem I see is, that you need way more diskspace to do that. Is there something more that I miss?

fold this thread optimizationkit  Friday, 23 May 2008 o godz. 11:01 pm #  Add karma Subtract karma  --2

“Is there something more that I miss?”

No, this is the main problem.

 
fold this thread Chris Lees  Saturday, 24 May 2008 o godz. 6:17 am #  Add karma Subtract karma  +0

That brings back old memories of my Macintosh and the very roomy (for the time) 1 gigabyte external hard disk I owned. I couldn’t be bothered buying Norton Utilities, so I just defragmented by copying everything over to the external drive, formatting the internal, and copying back.

 
fold this thread AzP  Monday, 26 May 2008 o godz. 3:25 pm #  Add karma Subtract karma  +0

This is also the only way of defragging a ReiserFS drive. And they fragment like a mutha******. At first they are great, but after about a year the’re so sluggish it’s very very very painful.

 
 
fold this thread EdwardOCallaghan  Saturday, 24 May 2008 o godz. 4:56 am #  Add karma Subtract karma  +1

How about ZFS in opensolaris ?

 
fold this thread roger64  Saturday, 24 May 2008 o godz. 10:01 am #  Add karma Subtract karma  +0

I tried to launch ok_defrag but failed -no such command).

Previously, I downloaded the python-dialog packet and I did an image disk of my partition which needs defrag after four successive upgrades.

Could there be some more explicit information about it ?

Thanks for help.

fold this thread michuk  Saturday, 24 May 2008 o godz. 10:29 am #  Add karma Subtract karma  +1

Have you downloded ok_defrag from here http://download.tuxfamily.org/optimization/OptimizationKit/v0.1/tmp/ and installed it and put on your $PATH?

 
fold this thread optimizationkit  Saturday, 24 May 2008 o godz. 10:37 am #  Add karma Subtract karma  +1

“I tried to launch ok_defrag but failed -no such command). ”

ok_defrag uses the following commands: find, md5sum, mv and cp.

fold this thread B. Katz  Tuesday, 27 May 2008 o godz. 2:11 am #  Add karma Subtract karma  +0

swbobcat@ What I’d like to know is *WHERE* I can download ok_defrag. When I tried to download the utility I got 404 Error Message.

(Comments wont nest below this level)
 
 
 
fold this thread Jon  Sunday, 25 May 2008 o godz. 11:15 am #  Add karma Subtract karma  +2

“When is there no need to perform a defragmentation? Generally speaking, if fsck returns non-contiguous inode below 10%.”

Why? Not “Why is higher fragmentation *possibly* worse than lower fragmentation” - I already know this.

I’m asking: why did you pick the nice, round, base-10 friendly number “10%” as your recommended threshold?

Could it be because you’re picking numbers out of thin air? If not - if you’ve actually performed some real-world, performance-oriented benchmarks on filesystems with different fragmentation levels - then post these results. They’d be useful.

Having read your article, I’m quite confident you haven’t. It lacks any kind of rigour. For instance, why say that “35.2% of the inodes are not placed continuously — the fragmentation degree of files in our image is very high”? Surely “99.9%” is “very high”, and “35.2%” is rather lower?

It’s *relative* and, depending on the access patterns of the files that are fragmented, may be utterly unimportant in determining the performance of the containing system.

TL;DR Don’t give up the day job.

fold this thread optimizationkit  Sunday, 25 May 2008 o godz. 12:16 pm #  Add karma Subtract karma  +0

“Could it be because you’re picking numbers out of thin air?”

No - because it is difficult to go down below 10% with current ok_defrag file sorting method.

Also, many users will never exceed 10%.

 
fold this thread Name (required)  Sunday, 25 May 2008 o godz. 3:01 pm #  Add karma Subtract karma  +3

I’m going to agree with jon. This smacks of noobishness. Using shell scripts and python to defrag a filesystem? Copying files in and out of /tmp? This seems like a rediculous idea, and I would not let this near any system with data on it that I care about.

Additionally, I really don’t care about manufactured cases of fragmentation … I have never seen the levels of fragmentation mentioned in this article in real world experience using ext2/3.

So, yes, if you force bad things to happen to your filesystem … bad things will happen to your filesystem. Shocking, I know.

This is completely unneccesary.

 
 
fold this thread Jon  Sunday, 25 May 2008 o godz. 12:29 pm #  Add karma Subtract karma  +1

“Also, many users will never exceed 10%.”

Sounds like another fact, pulled from thin air!

If they won’t generally exceed 10%, and this method can’t take you much below 10%, and a newly created FS is at ~10% defragmentation, what does that tell you?

Perhaps that “10%” is *meaningless*! The only thing that matters is the performance of the system that contains the FS.

Professionally, as a *nix sysadmin who maintains many hundreds of Linux, *BSD and Solaris boxes for a tier-2 UK ISP, I’ve never defragmented any system. Ever. The time it’ll take to do, coupled with the risk inherent in moving *all* your data off one partition, onto another, and back again, coupled with the fact that this *only* helps with frequently read, infrequently written data, makes me doubt its overall usefulness in anything other than very very specific circumstances.

YMMV.

fold this thread optimizationkit  Sunday, 25 May 2008 o godz. 1:12 pm #  Add karma Subtract karma  --1

“Perhaps that “10%” is *meaningless*!”

I don’t want to start another flame war (see the discussion under the original article). You have your arguments, I’ve got my arguments.

EOD from my side.

 
 
fold this thread Greg  Sunday, 25 May 2008 o godz. 12:31 pm #  Add karma Subtract karma  +1

In terms of native Linux defrag support:
Ext4 will have (online) defragmentation built in. Currently XFS has defrag support. I think you have to take the disk offline first.

fold this thread optimizationkit  Sunday, 25 May 2008 o godz. 1:17 pm #  Add karma Subtract karma  +0

“Ext4 will have (online) defragmentation built in”

Defragmentation in Ext4 is not a built-in. It is a set of patches

ext4-online-defrag-exchange-blocks-between-two-inodes.patch
ext4-online-defrag-relocate-file-data.patch
ext4-online-defrag-alloc-contiguous-blks.patch
ext4-online-defrag-ext4-defrag.patch
ext4-online-defrag-for-relevant-files.patch
ext4-online-defrag-check-for-freespace-fragmentation.patch
ext4-online-defrag-move-victim-files.patch

www dot kernel dot org/pub/linux/kernel/people/tytso/ext4-patches/2.6.26-rc2-git5-ext4-1/broken-out.tar.bz2

and proffesional defragmentation program ext4-online-defrag-command.patch

 
 
fold this thread dexen deVries  Sunday, 25 May 2008 o godz. 12:58 pm #  Add karma Subtract karma  +0

Just as a sidenote, XFS comes with a tool for performing on-line defragmentation by means of copying files: xfs_fsr

 
fold this thread Crismon  Sunday, 25 May 2008 o godz. 1:48 pm #  Add karma Subtract karma  +0

Hi guys I have some problem during the procedure. Actually when I try to launch the command /sbin/fsck.ext3 -nfv filesystem.img there are several errors. In particular: /sbin/fsck.ext2 -nfv filesystem.img
e2fsck 1.40.2 (12-Jul-2007)
Impossible to find the block ext2 trying backup blocks…
/sbin/fsck.ext2: Bad magic number in super-block during filesystem.img opening

Super block is not readable, or is not describing filesystem ext2
If the device is valid and contains a filesystem ext2
(e non swap, ufs o altro),the super block is corrupted, you could try to execute e2fsck with an alternativ super block:
e2fsck -b 8193

what am I supposed to do now? thanks for your help

fold this thread optimizationkit  Sunday, 25 May 2008 o godz. 1:58 pm #  Add karma Subtract karma  +1

Did you created ext{2,3} fs on this image?

 
 
fold this thread Crismon  Sunday, 25 May 2008 o godz. 2:11 pm #  Add karma Subtract karma  +0

Yes with this command:

/sbin/mkfs.ext3 filesystem.img

fold this thread optimizationkit  Sunday, 25 May 2008 o godz. 2:35 pm #  Add karma Subtract karma  +0

Strange, it might be the problem with your e2fstools.

 
 
fold this thread carolinason  Sunday, 25 May 2008 o godz. 2:13 pm #  Add karma Subtract karma  +0

I never defrag my linux boxes, but I think about ‘defraging’ sometimes, since I’m using windows alot :-(

 
fold this thread jugular  Sunday, 25 May 2008 o godz. 2:16 pm #  Add karma Subtract karma  +0

It’s funny how so many people can take very simple comparisons and completely screw them up to make their case. Anyone looking at the graphs for comparisons will quickly see differences, bu if you look at the numbers, the scales are different, and maybe the numbers aren’t quite so different.

Can we see the graphs with identical scales for both situations?

Thanks

fold this thread optimizationkit  Sunday, 25 May 2008 o godz. 2:33 pm #  Add karma Subtract karma  +0

“Can we see the graphs with identical scales for both situations?”

Ask Chris Mason for a better scales in seekwatcher.

fold this thread Rob Lazzurs  Thursday, 29 May 2008 o godz. 11:05 am #  Add karma Subtract karma  +0

Might it be worth posting a spreadsheet with the original data then so other people can see the results and judge them?

Nice article, thanks. I have to say that I am not sure how useful this would be in my environment but I will be checking.

I think a lot of people replying need to remember YMMV, just because this does not apply to your environment does not mean this is not a worthwhile article.

Take care all.

(Comments wont nest below this level)
 
 
 
fold this thread Leon  Sunday, 25 May 2008 o godz. 3:17 pm #  Add karma Subtract karma  +1

IMO there isn’t much that this blog post can make conclusion of.

And that’s not only because I feel that the difference in performance is so unsubstantial.

The very fact that the test is conducted on a loop device makes all the numbers invalid. There is high likelyhood that the .img file itself is defragmented on the host fs. Before and after moving data, the performance of the host fs may in its way affect the data collected for this “test”.

For example, there’s chance that before defrag, the files in the loop device somehow were written across defragmentation points of the img file itself and luckily after defragmentation the files ended up on a continuous part of the img on the host device. This definitely affects throughput measured.

If you ask me, Jon had a point. The recommendations were given pretty baselessly, and needless to say, without any substantial evidence or reasoning to back up the claim that those were the optimal numbers. optimizationkit tried to defend by throwing more numbers around but again, they were to be marked “citation needed”.

Possibly if anyone has free time, do some tests on fs on real disks, with accountability for caches, begin/end of disk, max/min, types/sizes of files, relation to everyday usage of disk etc. Now that will more likely help us server administrators. =)

So far I have not noticed any difference between speeds of my own fragged/defragged every-day filesystems (I used the copy out all, verify, delete all, copy in method), but hey, that’s just me and only yours truely.

 
fold this thread optimizationkit  Sunday, 25 May 2008 o godz. 4:13 pm #  Add karma Subtract karma  --1

“This seems like a rediculous idea”

“I have never seen the levels of fragmentation mentioned in this article in real world experience using ext2/3.”

et all

Publication of this article was a _bad_ idea, even worse idea was to translate it into English.

Why? Guess what - I _really_ _don’t_ _care_ about your opinion.

I wrote this tool for myself - like an other OK tools. I did not want to cause fscking holly wars. Since I do not want to cause further flame wars, I will not publish any future OK daemon/tools versions or articles about it.

fold this thread scorp123  Sunday, 25 May 2008 o godz. 10:19 pm #  Add karma Subtract karma  --7

We’re very thankful for that and we don’t really need your crappy tools and your BS FUD articles. Seriously. WTF are you thinking??? Any newbie on UbuntuForums could have done a better job at researching the facts before posting this pile of nonsense that you dare to call “article”. Just to make sure you don’t make an idiot of yourself again, you might want to read on FHS (Wikipedia is your friend), you might want to research why “UNIX style” partitioning is a good idea and why one should keep partitions such as /var and /home that get plenty of write-access on separate places than partitions such as /boot, /usr and /opt that mostly get lots of read-access and why this helps a great deal to keep fragmentation down to a minimum. After you have read this stuff you might get an idea why your tools are so totally not needed and why your article is utter nonsense.

fold this thread damentz  Monday, 26 May 2008 o godz. 1:16 am #  Add karma Subtract karma  +5

We’re very thankful for you’re crappy reply and your BS and FUD opinions. Seriously, WTF are you accomplishing by bashing OK? Any noob reading your comment can see through your intentions like purified glass.

Just to make sure you don’t look like an idiot again, you might want to google some howto’s not -HOW NOT TO BE AN @SSHOLE- and why some random jack*ss cares that you’re bullying someone who published this information with good intentions.

And hey, dumbass, we know about distributing data storage across multiple partitions, but holy shit! this is actually a story on single partition (omg!) fragmentation as we’re isolating the fragmentation level, not reinventing the wheel.

After you have read this stuff, you might get an idea why you’re post was meaningless and only full of sound and fury.

(Comments wont nest below this level)
fold this thread scorp123  Monday, 26 May 2008 o godz. 8:09 am #  Add karma Subtract karma  --7

Just like the author of this crap article: Get a life! And stay the hell out of issues you don’t understand, yes?

And besides: YES, I AM AN A$$HOLE. I am not even trying to hide it. LOL.

 
 
 
 
fold this thread Blaque  Sunday, 25 May 2008 o godz. 4:18 pm #  Add karma Subtract karma  +1

Now I’m no Linux guru (I do know some however) but it does seem that this article is bent on fabricating a problem with Linux that does not cause problems on the level of a Windows system. The deciding factor should be performance not the fact that fragmentation exists.

 
fold this thread Anon  Sunday, 25 May 2008 o godz. 4:28 pm #  Add karma Subtract karma  +0

If you are only interested in the fragmentation of a specifically small set of files on an ext3 system you can use the filefrag command as root to find out how many extents a file is taking up.

 
fold this thread hirni  Sunday, 25 May 2008 o godz. 4:38 pm #  Add karma Subtract karma  +0

if you’re using XFS - you can do all that ONLINE:
-xfs_fsr -v /mountpoint
((defrags the filesystem while mounted))
-echo “frag\n” | xfs_db -r /dev/sda
((displays fragmentation ONLINE))

you can clearly see by that, that not every fragmentation is bad:
If a huge file has 2 extents instead of 1, no big deal.
If there are a total of 200.000 files in /, what’s the
problem - if 10000 of them are non-ideal ?
etc. etc.

I don’t think fragmentation plays any significant role nowadays, where you have megabytes of disk-cache and an efficient block-buffering in (gigabytes of) RAM.

 
fold this thread blah  Sunday, 25 May 2008 o godz. 4:50 pm #  Add karma Subtract karma  +0

It’s only a myth if someone knows nothing about disk storage.
The real advantage Linux, or any U**X derivative, has is that the defrag process is inherentaly faster than Windows. While Windows attempts to move around a bunch of files and place the contents in the correct order, any U**X operating system needs only to move a set of the files to another drive, then move back. You don’t need to copy the entire drive at once, only large chunks…say the size of your biggest file or 10% of drive space.
Even with a 300GB drive, this can be accomplished in a matter of hours, while a Windows system would probably take a couple of days.

 
fold this thread rjb  Sunday, 25 May 2008 o godz. 5:05 pm #  Add karma Subtract karma  +1

the / partition on my laptop is 21 G, contains 245089 files, is 89.61% used (in terms of blocks), and has been heavily used for many months (since last reformatted), with many files changed and thrown around (like by a dist-upgrade). The fragmentation in term of non-contiguous inodes is 4.4%.

I am not convinced that I need to worry about fragmentation on ext3.

 
fold this thread bill  Sunday, 25 May 2008 o godz. 7:38 pm #  Add karma Subtract karma  +1

Very nice article.

I just did not understand what the contiguous inodes mean.

Keep up the good work.

Thank you very much for the information.

 
fold this thread James Justin Harrell  Sunday, 25 May 2008 o godz. 7:53 pm #  Add karma Subtract karma  error

Refusal of the ext filesystem developers to accept that defragmentation is needed reminds me of the refusal of Apple to bundle in a mouse with more than one button.

 
fold this thread ropers  Sunday, 25 May 2008 o godz. 8:59 pm #  Add karma Subtract karma  +0

It says above:

> Some systems have a functionality to remove files located in /tmp
> during bootup. The best thing would be to turn it off for the time of
> defragmentation.

Why not make the defrag script use /var/tmp instead?

/var/tmp, according to the Linux Filesystem Hierarchy Standard (FHS), is preserved between boots.

 
fold this thread scorp123  Sunday, 25 May 2008 o godz. 10:10 pm #  Add karma Subtract karma  --3

This article is idiotic, sorry to say so. In 12 years of UNIX + Linux administration I have never ever seen a system suffering from fragmentation. This entire “Linux needs a defrag tool as well” nonsense is just that: nonsense.

fold this thread AzP  Monday, 26 May 2008 o godz. 3:30 pm #  Add karma Subtract karma  +0

What about ReiserFS?

 
fold this thread B. Katz  Wednesday, 28 May 2008 o godz. 1:09 am #  Add karma Subtract karma  +0

While I have never seen any need to defrag my system, every once in a while BAD things happen: I get a power surge, power outage, etc., (yes I do have both a surge protector and a UPS, its interesting see what is left of a surge protector after a MAJOR voltage spike… And when the power goes down in the middle of the night… well you get the picture). and some files end up corrupted for no apparent reason, at while point something happens behind the seems and I sit for a minute or two twiddling my thumbs at which point it says that that whatever was wrong is now “PASSED”, “FIXED” or “OK” (I suspect this has something to do with the inodes). That was my major interest in this. I have NEVER had a problem per se UNLESS something like a power surge, outage etc., and then it is not one computer, its my entire network (of three computers) that seem to be whacked. Thank God I make periodic BACKUPS

 
 
fold this thread Henaway  Monday, 26 May 2008 o godz. 1:27 am #  Add karma Subtract karma  +0

I could be COMPLETELY wrong here, but my understanding of the difference between linux and Windows filesystems here (ext2/3 vs FAT/NTFS) is that linux writes an entire file in a contiguous block whenever possible whereas Windows will write a little piece of a file in scattered blocks all over the hard drive until it’s finished writing the file. This means that, by default, linux is FAR less prone to file fragmentation than Windows. Windows fragments by default. Linux does not.

So fragmentation on linux would only become a problem if an insanely huge number of tiny files were written and deleted on a regular basis over a very long period of time. (To the point where all the contiguous blocks have been used and now the filesystem has to write to blocks freed up by deleted files.) At THAT point a defrag would be beneficial to the system … but not until the entire disk had essentially been filled.

With terabyte drives now on the market for a couple hundred bucks … how often is that going to happen?

That is MY understanding and I could be wrong. So take it with a grain of salt.

 
fold this thread JT  Monday, 26 May 2008 o godz. 5:05 am #  Add karma Subtract karma  --2

Why does this issue keep coming up despite the fact that numerous sources and numerous debated going back more than a decade show that degramentation is not a problem? First, start with understanding what “non-contiguous inode” means in ext3. Then understand how that number will rarely, if ever exceed 10%. Then look back at the hundreds of debates on this issue and see that each time it has been proven defragmentation in Linux is not a problem. This article is irresponsible and ignortant, you should remove it and offer a retraction.

 
fold this thread Bbob  Monday, 26 May 2008 o godz. 5:17 am #  Add karma Subtract karma  --1
 
fold this thread solca  Monday, 26 May 2008 o godz. 5:56 am #  Add karma Subtract karma  +1