• Darrick J. Wong's avatar
    Merge tag 'xfs-iunlink-item-5.20' of... · 4613b17c
    Darrick J. Wong authored
    Merge tag 'xfs-iunlink-item-5.20' of git://git.kernel.org/pub/scm/linux/kernel/git/dgc/linux-xfs into xfs-5.20-mergeB
    
    xfs: introduce in-memory inode unlink log items
    
    To facilitate future improvements in inode logging and improving
    inode cluster buffer locking order consistency, we need a new
    mechanism for defering inode cluster buffer modifications during
    unlinked list modifications.
    
    The unlinked inode list buffer locking is complex. The unlinked
    list is unordered - we add to the tail, remove from where-ever the
    inode is in the list. Hence we might need to lock two inode buffers
    here (previous inode in list and the one being removed). While we
    can order the locking of these buffers correctly within the confines
    of the unlinked list, there may be other inodes that need buffer
    locking in the same transaction. e.g. O_TMPFILE being linked into a
    directory also modifies the directory inode.
    
    Hence we need a mechanism for defering unlinked inode list updates
    until a point where we know that all modifications have been made
    and all that remains is to lock and modify the cluster buffers.
    
    We can do this by first observing that we serialise unlinked list
    modifications by holding the AGI buffer lock. IOWs, the AGI is going
    to be locked until the transaction commits any time we modify the
    unlinked list. Hence it doesn't matter when in the unlink
    transactions that we actually load, lock and modify the inode
    cluster buffer.
    
    We add an in-memory unlinked inode log item to defer the inode
    cluster buffer update to transaction commit time where it can be
    ordered with all the other inode cluster operations that need to be
    done. Essentially all we need to do is record the inodes that need
    to have their unlinked list pointer updated in a new log item that
    we attached to the transaction.
    
    This log item exists purely for the purpose of delaying the update
    of the unlinked list pointer until the inode cluster buffer can be
    locked in the correct order around the other inode cluster buffers.
    It plays no part in the actual commit, and there's no change to
    anything that is written to the log. i.e. the inode cluster buffers
    still have to be fully logged here (not just ordered) as log
    recovery depedends on this to replay mods to the unlinked inode
    list.
    
    Hence if we add a "precommit" hook into xfs_trans_commit()
    to run a "precommit" operation on these iunlink log items, we can
    delay the locking, modification and logging of the inode cluster
    buffer until after all other modifications have been made. The
    precommit hook reuires us to sort the items that are going to be run
    so that we can lock precommit items in the correct order as we
    perform the modifications they describe.
    
    To make this unlinked inode list processing simpler and easier to
    implement as a log item, we need to change the way we track the
    unlinked list in memory. Starting from the observation that an inode
    on the unlinked list is pinned in memory by the VFS, we can use the
    xfs_inode itself to track the unlinked list. To do this efficiently,
    we want the unlinked list to be a double linked list. The problem
    here is that we need a list per AGI unlinked list, and there are 64
    of these per AGI. The approach taken in this patchset is to shadow
    the AGI unlinked list heads in the perag, and link inodes by agino,
    hence requiring only 8 extra bytes per inode to track this state.
    
    We can then use the agino pointers for lockless inode cache lookups
    to retreive the inode. The aginos in the inode are modified only
    under the AGI lock, just like the cluster buffer pointers, so we
    don't need any extra locking here.  The i_next_unlinked field tracks
    the on-disk value of the unlinked list, and the i_prev_unlinked is a
    purely in-memory pointer that enables us to efficiently remove
    inodes from the middle of the list.
    
    This results in moving a lot of the unlink modification work into
    the precommit operations on the unlink log item. Tracking all the
    unlinked inodes in the inodes themselves also gets rid of the
    unlinked list reference hash table that is used to track this back
    pointer relationship. This greatly simplifies the the unlinked list
    modification code, and removes memory allocations in this hot path
    to track back pointers. This, overall, slightly reduces the CPU
    overhead of the unlink path.
    
    The result of this log item means that we move all the actual
    manipulation of objects to be logged out of the iunlink path and
    into the iunlink item. This allows for future optimisation of this
    mechanism without needing changes to high level unlink path, as
    well as making the unlink lock ordering predictable and synchronised
    with other operations that may require inode cluster locking.
    Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
    Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
    
    * tag 'xfs-iunlink-item-5.20' of git://git.kernel.org/pub/scm/linux/kernel/git/dgc/linux-xfs:
      xfs: add in-memory iunlink log item
      xfs: add log item precommit operation
      xfs: combine iunlink inode update functions
      xfs: clean up xfs_iunlink_update_inode()
      xfs: double link the unlinked inode list
      xfs: introduce xfs_iunlink_lookup
      xfs: refactor xlog_recover_process_iunlinks()
      xfs: track the iunlink list pointer in the xfs_inode
      xfs: factor the xfs_iunlink functions
      xfs: flush inode gc workqueue before clearing agi bucket
    4613b17c
xfs_trans.h 9.89 KB