LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Linux file structure question about i-nodes and allocation (https://www.linuxquestions.org/questions/linux-newbie-8/linux-file-structure-question-about-i-nodes-and-allocation-879183/)

kienlarsen 05-06-2011 07:41 AM

Linux file structure question about i-nodes and allocation
 
I'm on files and file systems with UNIX Academy training DVDs and I'm preparing for my first exam. I have a question to which I can't find an answer. I learned from the training and accompanying books that file name and a pointer to its actual i-node are stores in directory record. I have no problem with that, as I can clearly verify all of it.
My question is, though, most files are much larger that one i-node can accommodate, so I logically conclude that it takes many more i-nodes to store a file.
Here's the question: how file knows where rest of its parts allocated? It is not in directory records, I checked. Apparently it is not in superblock. So where is the magic place that stores all file' pieces?

syg00 05-06-2011 08:00 AM

Try here.

kienlarsen 05-06-2011 02:36 PM

syg00, thanks! I don't know how I missed this article on Wikipedia.

kienlarsen 05-07-2011 10:26 AM

Would the design like that, as I see it, create very fragmented files?

kienlarsen 05-08-2011 08:03 AM

Can somebody to advise/comment about file system fragmentation in Linux and to deal with it?

carltm 05-08-2011 08:29 AM

Quote:

Originally Posted by kienlarsen (Post 4348322)
My question is, though, most files are much larger that one i-node can accommodate, so I logically conclude that it takes many more i-nodes to store a file.
Here's the question: how file knows where rest of its parts allocated? It is not in directory records, I checked. Apparently it is not in superblock. So where is the magic place that stores all file' pieces?

This is not really a Linux (kernel) question, it's more a filesystem
question. Most distributions use ext2, ext3 or ext4 by default, and
these filesystems use inodes. Most other filesystems don't use them.

An inode is a reference to the first sector on the harddrive where
the file is stored. At the end of each sector is the address of the
next sector or an indicator that there are no more sectors. This means
that each file has only one inode, regardless of how many sectors are
used to store the file's contents.

carltm 05-08-2011 08:33 AM

Quote:

Originally Posted by kienlarsen (Post 4349987)
Can somebody to advise/comment about file system fragmentation in Linux and to deal with it?

Generally you don't need to be concerned about fragmentation on Linux
filesystems. When the kernel writes a file it automatically finds a
place that requires minimal fragmentation.

kienlarsen 05-09-2011 09:08 AM

I see it this way, the fragmentation must occur as different file' pieces aren't written consequently, one after another. And as far as I understand from my training, the fragmentation is inevitable as files are many, and changing in size, updating etc. The way Linux handles the writing probably improves the situation, but it is incapable of preventing the fragmentation. The fragmentation occurs.

Soadyheid 05-09-2011 10:26 AM

More from Wikipedia...

See "ext3"

Quote:

DefragmentationThere is no online ext3 defragmentation tool that works on the filesystem level. An offline ext2 defragmenter, e2defrag, exists but requires that the ext3 filesystem be converted back to ext2 first. But depending on the feature bits turned on in the filesystem, e2defrag may destroy data; it does not know how to treat many of the newer ext3 features.[17]

There are userspace defragmentation tools like Shake[18] and defrag.[19][20] Shake works by allocating space for the whole file as one operation, which will generally cause the allocator to find contiguous disk space. It also tries to write files used at the same time next to each other. Defrag works by copying each file over itself. However they only work if the filesystem is reasonably empty. A true defragmentation tool does not exist for ext3.[21]

That being said, as the Linux System Administrator Guide states, "Modern Linux filesystem(s) keep fragmentation at a minimum by keeping all blocks in a file close together, even if they can't be stored in consecutive sectors. Some filesystems, like ext3, effectively allocate the free block that is nearest to other blocks in a file. Therefore it is not necessary to worry about fragmentation in a Linux system."[22]

While ext3 is more resistant to file fragmentation than the FAT filesystem, nonetheless ext3 filesystems can get fragmented over time or on specific usage patterns, like slowly-writing large files.[23][24] Consequently the successor to the ext3 filesystem, ext4, is planned to eventually include an online filesystem defragmentation utility,[25] and currently supports extents (contiguous file regions).
Play Bonny! :hattip:

kienlarsen 05-09-2011 05:09 PM

Does it mean there's no standard de-fragmentation tool in Linux? So how people deal with the fragmentation, or it is just ignored? In windows it is very efficient and useful tool.

frankbell 05-09-2011 08:00 PM

Fragmentation does not become significant enough to affect performance in native Linux file systems.

The inode system allows the kernel to find all the pieces of the file almost instantaneously. I have read (can't find the source) that, even with defragmentation, Linux file systems tend to maintain a steady, not an increasing rate of fragmentation because the file systems police themselves.

Frankly, fragmentation is not that much of an issue with NTFS, either. In FAT and FAT32, the system had to load the first block of a file to find the pointer to the second block; the second block to find the pointer to the third block; and so on. This is why fragmentation would slow performance of a machine as fragmentation increased over time.

In NTFS, my Windows 2000 instructor said that the pointers to all blocks for a file are contained in the MFT. A fragmentation map that might bring a FAT or FAT32 system to its knees will have only a marginal effect on an NTFS system--even though the map may seem scary to someone who cut his teeth on FAT, as I did--because the MFT works in the same general way as the inode system.

kienlarsen 05-10-2011 01:32 PM

frankbell, as I understand it from my Unix Academy DVD training, problem of fragmentation isn't that kernel has a difficulty finding i-nodes or data blocks, but that data block allocated all over the drive and takes many drive spins to read them (istead of one), so it's becoming inefficient and slow.

frankbell 05-10-2011 07:08 PM

Quote:

Originally Posted by kienlarsen (Post 4352258)
frankbell, as I understand it from my Unix Academy DVD training, problem of fragmentation isn't that kernel has a difficulty finding i-nodes or data blocks, but that data block allocated all over the drive and takes many drive spins to read them (istead of one), so it's becoming inefficient and slow.

Actually, it can be both. The longer seek times mean more drive spins during the seeking.

Fabrication is not an issue with the major Linux filesystems.

The kernel and the filesystems together police the system so that the percent of fragmentation remains well within limits and does not grow. Third party tools would be redundant.

Edit: Another way of looking at it would be to consider that fragmentation control (not elimination, but control) is built-in.

kienlarsen 05-11-2011 07:38 AM

How can it remain within limits? Imagine the system that has many data files (aka database) and the files often rewritten and their size is changing both ways. It is inevitable that fragmentation will occur and it will be growing. And it would be happening not because something is wrong with Linux file system, I think it is just the way it is. As I see it (may be I'm wrong), kernel has limited ability to control how and where it puts new data. Otherwise the data writing alone would become huge issue and entire disk map to be kept in memory and constantly calculate location/relocations. May be on some expensive disk controllers it would be possible (my wild guess). As I researched there are third party programs that admit and deal with fragmentation issue.

chrism01 05-11-2011 08:34 PM

Basically, the filesystem service called by the kernel is fairly clever and is designed to resist fragmentation in general.
Historically it's been so successful that no defrag tool has been supplied by the core code writers.
Don't forget that by default when you create a new fs on a disk it reserves 5% space (tunable) for exclusive use by root.
http://linux.die.net/man/8/mkfs.ext3

In extreme cases eg continually at 95% full and large files being created/deleted/updated, you will get some fragmentation, but by then you should allocate a bigger disk anyway.


All times are GMT -5. The time now is 06:40 PM.