Skip to contentSkip to conversation

understanding the tree-log

DISCUSSION Phillip Susi 2 participants 3 messages Nov 4, 2011 Btrfs file system

lore
Share & tools
lore
#0 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Given how a transaction is committed, why is there a tree-log? When modifying the tree, either the super block is still pointing to the old tree root, or the new generation has been fully committed, so how can there ever be an intermediate state that needs a log to recover? -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk6zWiwACgkQJ4UciIs+XuK+FQCfTnTIu8iYgW38Qk3YoZ4KjA/9 uhwAnjOH36EkQ1EhoUdWg7OJr+0L0lbA
=7DUz
-----END PGP SIGNATURE-----

#1 lore raw
Quoted 4 lines · Phillip Susi

Given how a transaction is committed, why is there a tree-log? When modifying the tree, either the super block is still pointing to the old tree root, or the new generation has been fully committed, so how can there ever be an intermediate state that needs a log to recover?

tree-log is for improving the preformance of fsync and and O_SYNCs.

Btrfs has an expensive "commit transaction", if we commit a transaction every time we fsync, the performance is not that good. Instead of this, we introduce a write-ahead log to make our fsync faster.

So if you do fsync for your data, it means your data is safely in the log tree, then if a crash takes place, the data can be recovered from log.

More details are in tree-log.c.

thanks,
liubo

#2 lore raw
Quoted 6 lines · Liu Bo

Btrfs has an expensive "commit transaction", if we commit a transaction every time we fsync, the performance is not that good. Instead of this, we introduce a write-ahead log to make our fsync faster.

So if you do fsync for your data, it means your data is safely in the log tree, then if a crash takes place, the data can be recovered from log.

How can you write to the log tree without a full commit? The tree of tree roots has to point to the root node of the log tree, so when you write out the log tree, that needs updated too, which requires a full commit doesn't it?