• J
    btrfs: keep trim from interfering with transaction commits · 0a7f6c7e
    Jeff Mahoney 提交于
    commit fee7acc361314df6561208c2d3c0882d663dd537 upstream.
    
    Commit 499f377f (btrfs: iterate over unused chunk space in FITRIM)
    fixed free space trimming, but introduced latency when it was running.
    This is due to it pinning the transaction using both a incremented
    refcount and holding the commit root sem for the duration of a single
    trim operation.
    
    This was to ensure safety but it's unnecessary.  We already hold the the
    chunk mutex so we know that the chunk we're using can't be allocated
    while we're trimming it.
    
    In order to check against chunks allocated already in this transaction,
    we need to check the pending chunks list.  To to that safely without
    joining the transaction (or attaching than then having to commit it) we
    need to ensure that the dev root's commit root doesn't change underneath
    us and the pending chunk lists stays around until we're done with it.
    
    We can ensure the former by holding the commit root sem and the latter
    by pinning the transaction.  We do this now, but the critical section
    covers the trim operation itself and we don't need to do that.
    
    This patch moves the pinning and unpinning logic into helpers and unpins
    the transaction after performing the search and check for pending
    chunks.
    
    Limiting the critical section of the transaction pinning improves the
    latency substantially on slower storage (e.g. image files over NFS).
    
    Fixes: 499f377f ("btrfs: iterate over unused chunk space in FITRIM")
    CC: stable@vger.kernel.org # 4.4+
    Signed-off-by: NJeff Mahoney <jeffm@suse.com>
    Reviewed-by: NDavid Sterba <dsterba@suse.com>
    Signed-off-by: NDavid Sterba <dsterba@suse.com>
    Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    0a7f6c7e
extent-tree.c 300.3 KB