[NTLUG:Discuss] Is there a disk defragmenter for Linux

Greg Edwards greg at nas-inet.com
Sat Dec 28 11:26:27 CST 2002


Vaidya, Harshal (Cognizant) wrote:
> 
> Hey Greg,
> 
>   Thanks for this great insight. Just a little bit more curiosity :-
> 
> In the example gave by you, If another 500 bytes are added to the previous
> 100 bytes, you mentioned that the entire data of 600 bytes will be shifted
> to a consecutive location of 1024 blocks. 
> 
> If this would be true consider a scenario where 1 MB of space is already
> allocated to a file  all in consecutive blocks. Now I add another 400 bytes
> to it. Assume that there is no free block available consecutive to the 1 MB
> blocks allocated. What would happen in this case? Will the Filesystem search
> of 1 MB + 512 blocks all of  which are consecutive and then shift all the
> data from the previous position to the new position just to avoid
> fragmentation? Won't this be time consuming? Also consider that the data is
> 10 MB. What would happen in this case? Moving 10 MB for allocation of a
> single consecutive block.. does this make sense?
> 
> 
> Feel free to comment if I have gone wrong somewhere. The last time I learnt
> about Filesystem about 2 years before in college and hence its quite
> possible that my knowledge of file system concepts has dwindled a little.
> Your post on the topic just rejuvenated my curiosity.
> 
> 
> Regards,
> Harshal.
> 

You need to consider your application.  Most software will read an 
entire file and process it in memory.  When it is written back out to 
disk in a save operation the entire file is written back out.  In this 
case you are writing the entire file anyway.

The allocation is in 512 byte blocks so your example would be 1M + 1 
block (512 bytes in size).  Yes the *nix OSs would write the entire file 
to a new location.  If you have a system that will generally have large 
files you may want to format using a different value than the default 
block size of 512 bytes.  Look at "man mkfs" and friends.

Where you can end up with fragmentation problems with *nix OSs is in 
applications that update rather than write files.  Generally these apps 
are specialized, such as DBMSs.  A DBMS, such as Oracle and MySQL do 
things quite different than word processors, spreadsheets, or graphics 
programs.  They allocate large chunks at a time to get contiguous space 
and then manage the storage internally.  Oracle is happiest when you 
assign dedicated partitions for it's use.

I would speculate that 99% of the programs you normally use write data 
to disk as opposed to update the data already on disk.

-- 
Greg Edwards





More information about the Discuss mailing list