How to create external Journal device in Linux with EXT4

Among you, who have worked on AIX, must be smiling and thinking “Is this really something to write about on a blog?”. Well, it’s true for AIX, as external Journal device is an old story there. On the other hand, I have seen very few or close to none usage of external journal device in production Linux systems.

People who do not know what a Journaling filesystem is, this should be comprehensive enough: The whole idea of Journaling filesystem is to keep a write-ahead data of all the filesystem changes. In this way, creating/deleting/modifying a file becomes a transaction. Remember atomicity of transaction in DBMS? All or None law? The same idea works here. So in case if some thing goes wrong, the filesystem can always roll back to the last known good state. However, all awesome things come with a cost. Here the cost you pay is the filesystem write performance: anytime you want to write data to a file, the filesystem will write to the journal first and then it will write the actual data.

Here’s why you might want to have an external journal device for your ext4 file system:

1. You are avoiding corruption in the journal data itself by keeping it somewhere else than the original data
2. As in journaling, filesystem writes data twice, keeping a separate journal device i.e a partition or logical volume on a separate physical disk altogether will introduce a significant performance boost

There’s a downside though: You cannot have multiple EXT4 filesystems sharing the same journal device as of now (AIX folks have probably started laughing now).

So how do you actually create a external journal device? Here’s how:

mke2fs -O journal_dev /dev/block_device_name














While creating a new filesystem, you can easily point to the newly created journal device like this:

mke2fs -t ext4 -J device=/dev/journal_device_name /dev/block_device_for_new_fs

To change journaling from internal to external for an existing filesystem, first unmount the filesystem. Then, execute the following:

tune2fs -O ^has_journal /dev/blk_dev_for_existing_fs
tune2fs -o journal_dev -j -J device=/dev/device_name /dev/blk_dev_for_existing_fs

There are few things to remember though:
The size of the journal device should be at least 1024*block size of the file system. So a filesystem with 4kb block size should have a journal device of 4mb at least.
Block size of the journal device should be set to the same as that of the actual filesystem

You can gain around 40% performance boost with external journal device (provided, the journal device resides on a separate physical disk). Amazing huh?

Advertisements

About admin_xor

Un*x/Linux junkie, loves to program, automate, automate and automate
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to How to create external Journal device in Linux with EXT4

  1. Laurens D says:

    Thanks a lot, I was wondering does:
    There's a downside though: You cannot have multiple EXT4 filesystems sharing the same journal device as of now (AIX folks have probably started laughing now).

    mean that you can use only one per partition, and not bundled into one(aka two journals on 1 partition)?

    Do you suggest us to use mirrored ssd's for this?

    Thanks, really interesting tutorial. 🙂

  2. Hi Laurens.

    There's no way to add multiple journal devices for a single ext4 file system, nor does it support one journal device for more than one ext4 file systems.

    Mirrored SSDs should be good enough, but considering the cost and life span (journaling incurs more writes than reads, something that affects life of SSDs), I wouldn't go for it. Probably fast mirrored HDDs would be good enough.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s