View previous topic :: View next topic |
Author |
Message |
gnychis Veteran


Joined: 23 Mar 2005 Posts: 1004 Location: Pittsburgh, PA
|
Posted: Sun Jul 31, 2005 5:16 am Post subject: disk management? defragment? [SOLVED] |
|
|
Hi,
In windows I got used to defragmenting the hard drive. I was wondering if this is still needed in linux. I am not familiar with how linux file systems work. Is defragging needed? Is there any other sort of disk management i should be doing to keep performance optimal? I use reiserfs.
Thanks!
George
Last edited by gnychis on Fri Aug 05, 2005 10:46 pm; edited 1 time in total |
|
Back to top |
|
 |
TheRAt Veteran


Joined: 03 Jun 2002 Posts: 1580
|
Posted: Sun Jul 31, 2005 5:32 am Post subject: Re: disk management? defragment? |
|
|
Lew Pitcher wrote: | Short answer: No.
Long answer: see below
In a single-user, single-tasking OS, it's best to keep all blocks for a file together, because _most_ of the disk accesses over a given period of time will be against a single file. In this scenario, the read-write heads of your HD advance sequentially through the hard disk. In the same sort of system, if your file is fragmented, the read-write heads jump all over the place, adding seek time to the hard disk access time.
In a multi-user, multi-tasking, multi-threaded OS, many files are being accessed at any time, and, if left unregulated, the disk read-write heads would jump all over the place all the time. Even with 'defragmented' files, there would be as much seek-time delay as there would be with a single-user single-tasking OS and fragmented files.
Fortunately, multi-user, multi-tasking, multi-threaded OSs are usually built smarter than that. Since file access is multiplexed from the point of view of the device (multiple file accesses from multiple, unrelated processes, with no order imposed on the sequence of blocks requested), the device driver reorders the requests into something sensible for the device (i.e elevator algorithm).
In other words, fragmentation is a concern when one (and only one) process access data from one (and only one) file. When more than one file is involved, the disk addresses being requested are 'fragmented' wrt the sequence that the driver has to service them, and thus it doesn't matter to the device driver whether or not a file was fragmented.
To illustrate:
I have two programs executing simultaneously, each reading two different files.
The files are organized sequentially (unfragmented) on disk...
[1.1][1.2][1.3][2.1][2.2][2.3][3.1][3.2][3.3][4.1][4.2][4.3][4.4]
Program 1 reads file 1, block 1
file 1, block 2
file 2, block 1
file 2, block 2
file 2, block 3
file 1, block 3
Program 2 reads file 3, block 1
file 4, block 1
file 3, block 2
file 4, block 2
file 3, block 3
file 4, block 4
The OS scheduler causes the programs to be scheduled and executed such that the device driver receives requests
file 3, block 1
file 1, block 1
file 4, block 1
file 1, block 2
file 3, block 2
file 2, block 1
file 4, block 2
file 2, block 2
file 3, block 3
file 2, block 3
file 4, block 4
file 1, block 3
Graphically, this looks like...
Code: |
[1.1][1.2][1.3][2.1][2.2][2.3][3.1][3.2][3.3][4.1][4.2][4.3][4.4]
}------------------------------>[3.1]
[1.1]<-----------------------'
`-------------------------------------->[4.1]
[1.2]<---------------------------------'
`----------------------->[3.2]
[2.1]<-------------'
`---------------------------->[4.2]
[2.2]<-----------------------'
`------------->[3.3]
[2.3]<-------'
`---------------------------->[4.4]
[1.3]<------------------------------------------'
|
As you can see, the accesses are already 'fragmented' and we haven't even reached the disk yet. I have to stress this, the above situation is _no different_ from an MSDOS single file access against a fragmented file.
So, how do we minimize the effect seen above? If you are MSDOS, you reorder the blocks on disk to match the (presumed) order in which they will be requested. OTOH, if you are Linux, you reorder the _requests_ into a regular sequence that minimizes disk access. You also buffer most of the data in memory, and you only write dirty blocks. In other words, you minimize the effect of 'disk file fragmentation' as part of the other optimizations you perform on the _access requests_ before you execute them.
Now, this is not to say that 'disk file fragmentation' is a good thing. It's just that 'disk file fragmentation' doesn't have the *impact* here that it would have in MSDOS-based systems. The performance difference between a 'disk file fragmented' Linux file system and a 'disk file unfragmented' Linux file system is minimal to none, where the same performance difference under MSDOS would be huge.
Under the right circumstances, fragmentation is a neutral thing, neither bad nor good. As to defraging a Linux filesystem (ext2fs), there are tools available, but (because of the design of the system) these tools are rarely (if ever) needed or used. That's the impact of designing up front the multi-processing/multi-tasking multi-user capacity of the OS into it's facilities, rather than tacking multi-processing/multi-tasking multi-user support on to an inherently single-processing/single-tasking single-user system.
--
Lew Pitcher
Master Codewright and JOAT-in-training
Registered Linux User #112576 |
_________________ All reality is the construct of the observer.
Get Firefox and rediscover the web!
BOFH Excuse #295:
The Token fell out of the ring. Call us when you find it. |
|
Back to top |
|
 |
YD Guru


Joined: 30 Oct 2004 Posts: 466 Location: Riga, Latvia
|
Posted: Sun Jul 31, 2005 5:34 am Post subject: |
|
|
defragmentation? Year 1995, the past century Nowadays it does a very little job. Probably, Linux filesystems don't need any of such. But sometimes old fs performance is a little bit lower than on a fresh system. "Sometimes" ? Portage partition, there are a lot of writes of small files with every sync, so it's normal. However, you can make a backup tarball, unmount partition, reformat, mount, restore backup. You can gain some speed only on such specific partitions.
IMHO. |
|
Back to top |
|
 |
jwj Apprentice


Joined: 07 May 2004 Posts: 240
|
Posted: Sun Jul 31, 2005 8:04 am Post subject: |
|
|
You can check fragmentation of XFS partitions with xfs_db
Code: |
xfs_db -r /dev/hdXX
frag
quit
|
The mounted partition can be defrag with xfs_fsr
The commands are part of sys-fs/xfsdump. |
|
Back to top |
|
 |
gnychis Veteran


Joined: 23 Mar 2005 Posts: 1004 Location: Pittsburgh, PA
|
Posted: Fri Aug 05, 2005 10:46 pm Post subject: |
|
|
that answers my questions
no need for defrag... thanks guys |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|