The third extended file system also known as Ext3 is a journaled file system . Linux Kernel uses this kind of File System. Therefore this paper explains Journaled File System first and then shows the difference between Journaled File System(Ext3 File System) and Non- Journaled File System(Ext2 File System).
INTRODUCTION:
WHAT IS A FILE SYSTEM AND HOW DOES IT WORK :
One of the most essential part of Operating System is File System. File System stores the data on the Hard Drive and it also manages the data which is present on the external Hard Drive or CD-ROMs. It maintains a table which tells us about the location of the blocks of the data. The data structure which gives the information about those blocks is called inode. Each inode has a unique identification number. Apart from storing the data the File System also creates and manages the information about these files. It also makes sure that the data present in the disk and the data written are same, in other words it maintains data integrity. Generally these file systems are extremely reliable and delivers very good performance.
RELIABILTY OF FILE SYSTEM:
A file system can be termed as a reliable file system when it is able to recover the data from the crashed file system successfully. Data which was present before the crash should never be lost. Data which was being written during the crash can be lost but not the one which was present before the crash.
Linux used to use Ext2 for many years. But due to increment in the popularity of the Linux it displaced many other operating systems in the computing world and Ext2 wasn't able to deliver the goods properly. As a result Ext3 was developed and it replaced Ext2. In fact, many now common requirements - large hard-disk partitions, quick recovery from crashes, high-performance I/O, and the need to store thousands and thousands of files representing terabytes of data - exceed the abilities of Ext2.[7].Ext2s are static file systems and static file system are not well defined for Hard Disk updates.
Apart from delivering the above mentioned requirements, file systems also provide Journaling. Journaling File System simplifies the I/O restart. In addition it also reduces fragmentation and Accelerates I/O. Usage of fscks can be avoided if we use Journaling File System.
Difference between Journaling File System (Ext3 File System) and Non-Journaling File System (Ext2 File System) &Need for Journaling:
If a Two Block File System is to be extended into a Five Block one, then the following steps have to be followed:
Firstly the extra three blocks must be added which would help us in holding the data.
Secondly, the file's inode (please check the glossary for its meaning) must be updated in order to record the two new block pointers and the new size of the file.
In the last step the procedure of writing the data into the Blocks is performed.
But writing the data into the blocks isn't a one step process. It consists of a number of steps. If everything pans out smoothly then there would be no problem and the file would be saved successfully. If due to some unforeseen conditions like (Power Failure etc.) the process is interrupted then the Non-Journaling File System would end up in an inconsistent state and the file would be corrupted.
Non-Journal File System:
When Linux is rebooted Non-Journal File System runs a program called fscks (file system consistency check) in order to detect the error and fix it. fscks checks the entire File System validating all the entries and making sure that each block is referenced and allocated correctly. But the File System generally has a lot of meta- data and examining all of them would be a time consuming process i.e. fsck has to scan a file system's entire repository of meta-data in order to ensure consistency and error-free operation. This shows that recovery time is greater in the case of Non-Journal File System. But the point to be noted here is that fsck doesn't provide any guarantee that it would repair the damaged part of the File System. Quite often it does not and during that situation the data in the corrupted file is lost.
Journaling File System:
The process of creating a new file system involves modification of meta-data structures. Before making the modifications the Journaling File System would store the pending changes in a special section of the disk called log. [Source Linux magazine]. The changes which are to made are written to the log first. After that using the data from the log it updates the file and the directory and marks that operation as committed or completed.
A typical journaling file system
Figure [Reference 4]
Whenever a request is placed for a particular file, the last snapshot of the file is retrieved from the disk and it is compared with the log in order to make sure that no unwanted changes are made to the that particular file. Synchronizing the operations of the file system with the log and committing the operations from the log is called a checkpoint. [Source Linux Magazine]
Every change to the file system structure is recorded in the log. Journaling File System maximizes system consistency as the changes are made to the log first and then they are made to the file system and the file system saves these records until the file system has been completely and safely updated.
After the crash the system recovery time is very less because only those entries which are after the check point have to be examined. Therefore the file system consistency can be checked without going through the entire file system. Since all the changes are made to the log, we can easily check the log and tell that the last change which was added to the log is the main reason for the problem.
Disadvantages of Journal System:
Unfortunately, we have to pay for the benefits of Journaling. Logging generally requires more disk writes and the main reason behind it is that we have to first add log records to the log and after that scan them against the File System. Hence the performance may suffer due to the mentioned reason.
EXT3 FILE SYSTEM:
BACKGROUND:
The third extended file system also known as Ext3 is a journaled file system . Linux Kernel uses this kind of File System.
WHY EXT3 FILE SYTEM WAS DEVELOPED AND IN WHAT WAY IT IS DIFFERENT FROM EXT2 FILE SYSTEM:
One main reason why Ext3 was developed is that Ext2 doesn't has Journaling capability .As mentioned above file systems with Journaling capability(Ext3) have higher efficiency than Non-Journaling file systems(Ext2).This paper throws light on the differences between Ext2 and Ext3 file in a tabular format as depicted below
The differences between Ext2 and Ext3 file systems are as follows.
Sl.No
EXT2
EXT3
Journaling
No journaling
Has journaling
Speed of file system(read-write)
Bit faster
Bit slower than ext2 file-system
Data corruption
File system may be corrupted due to unplanned reboots
Prevents file-system corruption
Online file system growth.
By default there is no Online file system growth.
Online file system growth
Commands to format
mkfs.ext2 or mke2fs
mkfs.ext3 or mke2fs -j
Max file size(if block size is 1kB)
2GB
16GB
Data accommodation
More data can be accommodated in a given space
Less date is written when compare to ext2 in a given space due to journaling.
Table [Reference 3]
Ext3 file system is compatible with ext2 file system, because it uses the same structure as ext2 and the only difference is addition of journal. It's even possible to mount an ext3fs partition as an ext2 file system or convert an ext2 file system to an ext3 file system [reference 4]
ON DISK REPRESENTATION:
Ext3 was built as an extension to Ext2 File System. Both data and metadata are stored in the standard fixed location structures in Ext3 File system just like in Ext2 file system. Here the disk is split into a number of different block groups like inode blocks, data blocks etc. as depicted in the figure. Even though the log file can be stored as a separate file it is placed inside the File System. Figure 2 depicts the Ext3 on-disk layout [Reference 2].
Figure shows the on disk representation of Ext3 file system. The Disk Address space is broken down into series of groups and each of the group has a bitmap. The bitmaps like inode bitmap, data bitmap gives the position or address of the Inode and Data block [Reference 2]
Mapping in Ext3 File System:
The following figure tells us that inside the inode block for Ext/3 15 block pointers are present. The first 12 blocks maps direct blocks. If the file size is less than 12 blocks then the location of the file would be inside the inode. If the file is bigger than 12 blocks then the file cannot be stored in the inode and then, the indirect block (represented by light blue) is used. A pointer is used which points towards that indirect block from the inode block. If the file is even bigger and first indirect block is not enough to store the information about it, then second indirect block (represented by blue) is used and again a pointer points towards the second indirect block, but this time from the indirect block. If the file is extremely large and even secondary indirect block is not able to store it then triple indirect block (represented by dark blue) is used and just like above a pointer is pointed towards the triple indirect block from the secondary triple block.
The main disadvantage with this architecture is that it is inefficient for large files. It would take long time in order to delete an ISO Image because it has to read all the indirect blocks and then free the block pointer and then indirect, double, triple indirect blocks and that would take very long time.
Figure4 [Reference 10]
JOURNALING MODES:
Basically there are three Journaling Modes
Write Back Mode(Most Risky)
Ordered Mode (Less Risky)
Data Journaling Mode(Least Risky)
Journal Mode:
This is the safest mode. In this mode both metadata and data are journaled. When a process writes a block it has to write it two times, once in the journal and after that to the fixed ext2 location.
Write Back Mode:
In this mode only metadata writes are journaled but not the data. Therefore this mode provides consistency in file system's metadata but not of data blocks. The content is written before or after journal is updated. Data corruption can occur when the system crashes after the metadata is journaled but before data block was written. Therefore it is more risky.
Ordered Mode:
In this mode also only metadata writes are journaled but not the data. But the difference here is the data is written to the location before journal writes of the metadata [reference 2]. But this mode provides better consistency than write back mode because we can recover both data and metadata after the crash and hence we can bring the system back to the consistent state.
The diagram depicts the three different journaling modes of ext3: write back, ordered, and data. In the diagram, time flows downward. Boxes represent updates to the file system, e.g., "Journal (Inode)" implies the write of an inode to the journal; the other destination for writes is labeled "Fixed", which is a write to the fixed in-place ext2 structures. An arrow labeled with"Sync" implies that the two blocks are written out in immediate succession synchronously, hence guaranteeing the first completes before the second. A curved arrow indicates ordering but not immediate succession; hence, the second write will happen at some later time. Finally, for write back mode, the dashed box around the "Fixed (Data)"block indicates that it may happen at any time in the sequence. In this example, we consider a data block write and its inode as the updates that need to be propagated to the file system; the diagrams show how the data flow is different for each of the ext3 journaling modes.[Reference 2]
COMPOUND TRANSACTION: When we have to update the same file there is no need to use single transactions, we can use Compound transaction. In compound transaction Ext3 groups many requests into one Compound transaction and then the target file is updated periodically.
CHECKPOINTING AND COMMITTING THE JOURNAL:-
The process of writing the journaled metadata and data to their respective blocks is called check pointing. Check pointing occurs when we have either low system buffer space or low free space in the journal. Committing a transaction means writing the updated file system permanently to the disk. But the old blocks must be stored before committing the journal so that data can be retrieved in case of the crash. Once this process of committing is completed then we can discard the old data. In order to completely commit and finish check pointing, one has to follow the below mentioned steps
Firstly the transaction should be closed and then a new transaction is initiated which will record all the future file system operations. If there are any existing incomplete operations, they would use the old transaction but not the new one i.e. a single file system cannot be split over multiple different transactions.
After that the transaction should be flushed to disk.
In the third step one should wait till all the outstanding operations of the file system in this transaction are completed, and before this process is completed we can and should start writing the journal as it results in increasing the speed.
We should wait till all the outstanding transactions updates are completely recorded in the journal.
Finally the header blocks of the journal should be updated in order to record the new head and tail of the log and committing the transaction to the disk.
CRASH RECOVERY : To recover from a crash we do relogging in the case of ext3 file system. The new updates (doesn't matter whether they are data or meta data) are written to the block first. During the crash recovery process the file system first scans the log for the completed transactions and it discards the incomplete one. Thus it recovers the consistent state from the inconsistent one.
ADVANTAGES OF EXT3 FILE SYSTEM:
These are the list of reasons why ext3 is good & what are the advantages of using it:
Ext3 file system is compatible with Ext2. It retains the ext2 file system but adds journaling capability to it. Therefore users can keep the existing file system and if they add journaling capability to it they can easily obtain Journaled File System.Ext3 file system is also backward compatible, as a result a user can un-journal a file system if he wishes to do so.
Ext3 provides and makes use of a generic journaling layer . It provides journaling not only within the file system but also to other devices. Therefore devices like NVRAM (Non-Volatile Random Memory) can implemented in the world of Linux and ext3 file system does provide support to them.
Ext3 has multiple journaling modes.
Write Back Mode: In this mode only metadata writes are journaled but not the data. Therefore this mode provides consistency in file system's metadata but not of data blocks.
Ordered Mode: In this mode also only metadata writes are journaled but not the data. But the difference here is the data is written to the location before journal writes of the metadata [reference 2]. But this mode provides better consistency than write back mode because we can recover both data and metadata after the crash and hence we can bring the system back to the consistent state.
Journal Mode: This is the safest mode. In this mode both metadata and data are journaled.
Therefore the administrator does have the power to make the trade off between speed and file data consistency and he can also tune the speed for specialized usage patterns.
Ext3 file system is platform independent .It can work on both 32 and 64 bit architectures. It can work both on little endian and big endian systems.
It is considered to be safest among all LINUX file system because of its simplicity and broad testing base.
Ext3 file system uses less power supply.
Ext3 file system provides better data integrity because it does guarantee safe recovery of the corrupted data.
Ext3 does not demand massive kernel changes and require no new system calls and therefore ext3 file system can be easily integrated with the new kernel releases.
It retains robustness of ext2 file system. Ext3 file system uses the same e2fsck code which helps in data recovery when corruption occurs due to hardware or software faults.
LIMITATIONS OF EXT3 FILESESYSTEM AND ADVANTAGES OF EXT4 OVER IT:
Ext4 has better speed, reliability, additional features than Ext3. Hence we can say it delivers better performance than Ext3.
Ext3 File System uses e2fsck for data recovery and even though it is a reliable one it takes a lot of time in scanning all the disks and hence in recovering the data. But in ext4 file system all the empty disks are watermarked and during the scan they are not checked and hence the data recovery speed in Ext4 File system drops off considerably.
Ext4 is fully compatible with Ext3.
Max volume size and Max File size is greater in the case of ext4 as compared to ext4.[please see the table]
The number of subdirectories contained in a directory in the case of Ext3 file system is 320000 but Ext4 has unlimited subdirectories.
Block allocator checks which blocks are free and then uses those free blocks when the need to write the data arises. But it allocates only one block (4KB) at a time. Therefore if a file of size 100 MB has to be written then the file system calls the block allocator 25600 number of times. This exhibits the inefficiency of Ext3 file system. But on the other hand Ext4 file system uses an allocator which allocates multi blocks at a time and hence avoids a lot of overhead. Due to this the performance of Ext4 is increased by many times as compared to Ext3 file system.
Ext4 has a feature which enables the user to turn off the journaling capability. Sometimes users don't require it and journaling capability comes with some overhead and hence they can increase the speed by turning off the journaling capability. But Ext3 does not have such facility.
Ext3
Ext4
Stands for
Third extended file system
Fourth extended file system
Original OS
Linux
Linux
Max Volume size
256 TB
1 EB - 16 TB
Max file size
16 GB - 2 TB
16 TB
Max filename length
254 bytes
256 bytes
Journaling with turning off
Capability
No , but it does have Journaling
Capability.
Yes
Number of Subdirectories
allowed per directory
32000
Unlimited
Table [Reference 6]
GLOSSARY:
Inodes:
Every file or directory is represented by an inode. The inode includes data about the size, permission, ownership, and location on disk of the file or directory.
Example of ext2 inode structure:
Estructure
[Reference 9]
TRANSACTION:
META DATA:
Internal data structure of the file system is called meta data. It includes everything about a file except the data like date, file size , location , security information etc.