• Filipe Manana's avatar
    btrfs: avoid expensive search when truncating inode items from the log · 4934a815
    Filipe Manana authored
    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: default avatarFilipe Manana <fdmanana@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    4934a815
tree-log.c 180 KB