OSDN Git Service

btrfs: avoid expensive search when truncating inode items from the log
authorFilipe Manana <fdmanana@suse.com>
Tue, 31 Aug 2021 14:30:37 +0000 (15:30 +0100)
committerDavid Sterba <dsterba@suse.com>
Tue, 26 Oct 2021 17:08:01 +0000 (19:08 +0200)
Whenever we are logging a file inode in full sync mode we call
btrfs_truncate_inode_items() to delete items of the inode we may have
previously logged.

That results in doing a btree search for deletion, which is expensive
because it always acquires write locks for extent buffers at levels 2, 1
and 0, and it balances any node that is less than half full. Acquiring
the write locks can block the task if the extent buffers are already
locked by another task or block other tasks attempting to lock them,
which is specially bad in case of log trees since they are small due to
their short life, with a root node at a level typically not greater than
level 2.

If we know that we are logging the inode for the first time in the current
transaction, we can skip the call to btrfs_truncate_inode_items(), avoiding
the deletion search. This change does that.

This patch is part of a patch set comprised of the following patches:

  btrfs: check if a log tree exists at inode_logged()
  btrfs: remove no longer needed checks for NULL log context
  btrfs: do not log new dentries when logging that a new name exists
  btrfs: always update the logged transaction when logging new names
  btrfs: avoid expensive search when dropping inode items from log
  btrfs: add helper to truncate inode items when logging inode
  btrfs: avoid expensive search when truncating inode items from the log
  btrfs: avoid search for logged i_size when logging inode if possible
  btrfs: avoid attempt to drop extents when logging inode for the first time
  btrfs: do not commit delayed inode when logging a file in full sync mode

This is patch 7/10 and test results are listed in the change log of the
last patch in the set.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/tree-log.c

index 2d92187..94964e6 100644 (file)
@@ -5488,7 +5488,9 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
                                          &inode->runtime_flags);
                                clear_bit(BTRFS_INODE_COPY_EVERYTHING,
                                          &inode->runtime_flags);
-                               ret = truncate_inode_items(trans, log, inode, 0, 0);
+                               if (inode_logged(trans, inode))
+                                       ret = truncate_inode_items(trans, log,
+                                                                  inode, 0, 0);
                        }
                } else if (test_and_clear_bit(BTRFS_INODE_COPY_EVERYTHING,
                                              &inode->runtime_flags) ||