Btrfs: improve performance on fsync of files with multiple hardlinks
PATCH 1/1 Btrfs: improve performance on fsync of files with multiple hardlinks
From: Filipe Manana <[email protected]>
Commit 41bd6067692382 ("Btrfs: fix fsync of files with multiple hard links in new directories") introduced a path that makes fsync fallback to a full transaction commit in order to avoid losing hard links and new ancestors of the fsynced inode. That path is triggered only when the inode has more than one hard link and either has a new hard link created in the current transaction or the inode was evicted and reloaded in the current transaction.
That path ends up getting triggered very often (hundreds of times) during the course of pgbench benchmarks, resulting in performance drops of about 20%.
This change restores the performance by not triggering the full transaction commit in those cases, and instead iterate the fs/subvolume tree in search of all possible new ancestors, for all hard links, to log them.
--- fs/btrfs/btrfs_inode.h | 6 -- fs/btrfs/inode.c | 17 ---- fs/btrfs/tree-log.c | 228 ++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 188 insertions(+), 63 deletions(-)
fs/btrfs/btrfs_inode.h +0 -6
@@ -148,12 +148,6 @@ struct btrfs_inode {u64 last_unlink_trans;/* -* Track the transaction id of the last transaction used to create a -* hard link for the inode. This is used by the log tree (fsync). -*/ -u64 last_link_trans; - -/* * Number of bytes outstanding that are going to need csums. This is * used in ENOSPC accounting. */
fs/btrfs/inode.c +0 -17
@@ -3699,21 +3699,6 @@ static int btrfs_read_locked_inode(struct inode *inode,* inode is not a directory, logging its parent unnecessarily. */ BTRFS_I (inode)->last_unlink_trans =BTRFS_I (inode)->last_trans; -/* -* Similar reasoning for last_link_trans, needs to be set otherwise -* for a case like the following: -* -* mkdir A -* touch foo -* ln foo A/bar -* echo 2 > /proc/sys/vm/drop_caches -* fsync foo -* <power failure> -* -* Would result in link bar and directory A not existing after the power -* failure. -*/ -BTRFS_I (inode)->last_link_trans =BTRFS_I (inode)->last_trans; path->slots[0 ]++; if (inode->i_nlink != 1 ||
@@ -6634,7 +6619,6 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,if (err) goto fail; } -BTRFS_I (inode)->last_link_trans = trans->transid;d_instantiate (dentry, inode); ret =btrfs_log_new_name (trans,BTRFS_I (inode),NULL , parent, true,NULL );
@@ -9161,7 +9145,6 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) ei->index_cnt = (u64)-1 ; ei->dir_index =0 ; ei->last_unlink_trans =0 ; - ei->last_link_trans =0 ; ei->last_log_commit =0 ;spin_lock_init (&ei->lock);
fs/btrfs/tree-log.c +188 -40
259 lines not on this page · raw message
Signature · 1 line
2.11.0
Quoted 14 lines · On Wed, Apr 17, 2019 at 11:31:06AM +0100, [email protected] wrote:
From: Filipe Manana <[email protected]>
Commit
41bd6067692382("Btrfs: fix fsync of files with multiple hard links in new directories") introduced a path that makes fsync fallback to a full transaction commit in order to avoid losing hard links and new ancestors of the fsynced inode. That path is triggered only when the inode has more than one hard link and either has a new hard link created in the current transaction or the inode was evicted and reloaded in the current transaction.That path ends up getting triggered very often (hundreds of times) during the course of pgbench benchmarks, resulting in performance drops of about 20%.
Quoted 7 lines
This change restores the performance by not triggering the full transaction commit in those cases, and instead iterate the fs/subvolume tree in search of all possible new ancestors, for all hard links, to log them.
Reported-by Zhao Yuhu <[email protected]>Tested-by James Wang <[email protected]>Signed-off-by Filipe Manana <[email protected]>
Added to misc-next, thanks.