[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: ext2 fs question



On Thu, Jun 07, 2001 at 09:46:25PM +1000, Steve Kowalik wrote:
> On Wed, Jun 06, 2001 at 04:13:09PM -0500, Andrew D Dixon uttered:
> > What I'm trying to figure out specifically is if I have a file, or a
> > directory, at the beginning of my disk and it start to get bigger and
> > bigger will it push the rest of the file system towards the end of the
> > disk or will it just write all of the new bits at the end of the disk?
> > 
> Writing to a drive does not work like this.
> All a directory is a list of inodes. (In the case of ext2, anyway), so if
> you add files to the directory, the new inodes (which can, and usually are,
> all over the disk) will be appended to the list.

Erm, no, that's not how it works at all.  A directory is not a list of
inodes.  A directory is a file containing directory entries.  A
directory entry is not the same thing as an inode (for example, inodes
don't have names, the way files do.  Multiple directory entries can have
different names but point to the same inode).

Inodes are also not "all over the disk".  (except in NetApp's WAFL
filesystem).  There is a specific section of the disk allocated to
inodes, and it is static and not a part of the filesystem at all.  Once
this portion is created it can't (easily) be changed.  You are stuck
with the number of inodes you've created.

What the person is asking about is not "garbage collection" but
fragmentation.  They are asking, basically, whether or not a file that
grows (syslog, for example) will get fragmented when it tries to grow
but runs up against a block that has already be allocated to another
file.

The answer to their question is yes, the file will get fragmented.
However, the way Unix filesystems work (or any non-FAT FS) is that they
take steps to minimize fragmentation.  Often this is done by over
allocating space for a file.  The average file on a Unix system is
something like 4 KB, so the FS allocates more than that initially.

When you boot your linux system, fsck will let you know how fragmented
the filesystem is (it will say something like "8.4% non-contiguous").
This number will typically be small, less than 10.  Only if the disk
becomes very full do you risk a lot of fragmentation, and that's because
there's no longer enough space for the FS to leave gaps between newly
created files, so they may not be able to grow much at all before
fragmenting.

As it turns out, it's often better to have large files fragmented
anyway.  I don't remember why this is, but I suspect it has something to
do with the fact that they'll wind up on different drive heads and will
have the effect of actually speeding up seek times.  I could be
completely wrong about that, though.

noah

-- 
 _______________________________________________________
| Web: http://web.morgul.net/~frodo/
| PGP Public Key: http://web.morgul.net/~frodo/mail.html 

Attachment: pgpFW3UQOAOXO.pgp
Description: PGP signature


Reply to: