Journaling block device explained

JBD, or journaling block device, is a generic block device journaling layer in the Linux kernel written by Stephen Tweedie from Red Hat. JBD is filesystem-independent. ext3, ext4 and OCFS2 are known to use JBD.[1] [2]

JBD exists in two versions, JBD and JBD2. JBD was created with ext3 in 1998.[3] JBD2 was forked from JBD in 2006 with ext4, with the goal of supporting a 64-bit (as opposed to 32-bit-only in JBD) block number. As a result, the maximum volume size in ext4 is increased to 1 EiB compared to 16 TiB in ext3 (assuming 4 KiB blocks).[4] JBD2 is backward-compatible. OCFS2 starting from Linux 2.6.28 uses JBD2.[5] The old JBD was removed with the dedicated ext3 driver in Linux 4.3 (2015).[6]

JBD structures

Atomic handle

An atomic handle is basically a collection of all the low-level changes that occur during a single high-level atomic update to the file system. The atomic handle guarantees that the high-level update either happens or not, because the actual changes to the file system are flushed only after logging the atomic handle in the journal.[2]

Transaction

For the sake of efficiency and performance, JBD groups several atomic handles into a single transaction, which is written to the journal after a fixed amount of time elapses or there is no free space left on the journal to fit it.

The transaction has several states:[2]

Recovery

Based on the transaction states, the JBD is able to determine which transactions need to be replayed (or reapplied) to the file system.[2]

Notes and References

  1. Web site: The Linux Journalling API . The Linux Kernel documentation.
  2. Web site: https://web.archive.org/web/20070926223043/http://kerneltrap.org/node/6741. 2007-09-26. Linux: The Journaling Block Device . Kedar Sovani . KernelTrap. June 20, 2006.
  3. Stephen C. Tweedie . Journaling the Linux ext2fs Filesystem . Proceedings of the 4th Annual LinuxExpo, Durham, NC . May 1998 . 2007-06-23. PDF.
  4. Mingming Cao . 9 August 2006 . Forking ext4 filesystem and JBD2 . Linux kernel mailing list .
  5. Web site: Linux 2.6.28. kernelnewbies.org. 2008.
  6. Web site: Corbet . Jonathan . rm -r fs/ext3 . LWN.net.