What is a Journaling file system?

What is a Journaling file system?

Even wikipedia doesn't give much information. Apart from NTFS which other file systems(on Windows / Linux) support journaling and how does it give a performance boost?


Solution 1:

A journaling filesystem records changes to the filesystem before it actually performs them. In this way it is able to recover after a failure (e.g. power fail) with minimal loss of data.

The Features section of Wikipedia's comparison of filesystems gives which are journaled.

Journaling does not give a performance boost. In fact, the journaling operationn reduces the speed slightly, in exchange for the above reliability.

Solution 2:

In essence, what a journaling file system does is add an extra level of abstraction between the hard drive and the operating system. Rather than perform operations directly on the disk, it keeps track of what it's trying to do first, then whether or not it succeeds.

For example, if you wanted to move a file from one drive to another, the procedure would look something like the following:

  • Physically copy old file to new location
  • Update directory entry on new drive
  • Remove directory entry from old drive
  • Free space on old drive

Exact process is filesystem dependent, but you get the idea. This would normally work fine, but in the off chance of a system crash, things could be interrupted halfway through. You may end up with the file physically copied, but no directory entry pointing to it. You may end up with the directory reference removed on the old drive, but the space not freed. In some cases, you may end up with a corrupted filesystem which won't even work anymore because a directory entry is only partially written.

In other words, a lot can go wrong.

A journalled file system would use the same basic procedure, with a few additional steps. Something like:

  • Journal entry: Moving file from A to B
    • Physically copy old file to new location
    • Update directory entry on new drive
    • Remove directory entry from old drive
    • Free space on old drive
  • Journal entry: Done moving file from A to B

If this process gets interrupted for any reason, such as a system crash, the filesystem now knows what was in progress, and whether it completed or not. It can then recover quickly and gracefully, either by trying to complete the transaction from the beginning, or by putting the filesystem back to the state it was in before. All this without needing to resort to a block-by-block check of the filesystem to find errors, which can be painfully time-consuming given the size of modern hard drives.

This can significantly improve the robustness of the filesystem, and speed up recovery time in the case of failure. Different levels of reliability can be gained by changing the granularity of the journal entries -- this again is filesystem dependent.

Since journalling inevitably involves more steps than the alternative, there would not be any performance boost unless you feel like crashing a lot. However, the difference in performance is often negligible compared to the advantages.

Solution 3:

The wikipedia article on Journaling file system contains a lot more details on what it is, how it works, and why.