Journaling file system
RAID Recovery - Journaling file system
A journaling file system is file system that before submitting the changes to the main file system logs them to a journal with the objective of protecting the file systems against any probable form of corruption in the event of power failure or system crash. These logs are usually circular logs in a dedicated area. Quite a many write operations are required so that the update of the files reflect the changes to the files and directories. Hence the requirement of a race condition comes up wherein f there is an interruption between the writes can leave data structures in an invalid intermediate stage.
In a journal file system the changes that are intended to be made are maintained in a journal ahead of time. The changes are replayed from the journal until the file system is consistent again. The recovery process is therefore simple and the changes are atomic or indivisible because they either succeed or are not replayed at all.
Most of the file systems put the journal in a special hidden file or a contiguous area that has a guarantee that it won’t move or change size while the file system is mounted. Verbatim copies of the blocks that are to be written later are logged by a physical journal. The information about the changes are logged by a logical journal in a special, compact format such as XFS or the USN journal (NTFS). The amount of data that is required to be read from and written to the journal in large metadata-heavy operations is reduced when journals are logged in the above mentioned way.
The error checking codes that are used by the disk drives apply to the whole disk blocks and not the individual bits or bytes and this prevents the code from that block from getting updated and resulting in all the bytes in the block becoming unreadable in case of a power failure in the middle of a write. In this exercise a physical journal that can overwrite entire blocks without needing to access their old content is comparatively less risky than the logical drives.
There are certain UFS implementations that avoid journaling and implement soft updates. The writes are ordered in such a way that the on-disk file system is never inconsistent and if there is an inconsistency like storage leak in case of crash, it can be treated. At the next mount the free space map is reconciled against a full walk of the file system and these leaks are treated. Usually in the background the garbage collection is done.
As journaling requires the data to be written twice, journaling can have a serious impact on performance. In metadata-journaling, only the changes to the file metadata are stored in the journal and hence it is a compromise between reliability and performance. In this process, the unjournaled file data and the journaled metadata can fall out of sync and hence opportunities are left for data corruption.
Write-twice penalty do not apply in the log-structured file systems as the journal itself is in the file system. In order to avoid double write penalty certain UNIX systems do apply similar techniques though commonly UNIX systems are not log structured.


