]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commit
btrfs: keep trim from interfering with transaction commits
authorJeff Mahoney <jeffm@suse.com>
Thu, 6 Sep 2018 21:18:16 +0000 (17:18 -0400)
committerDavid Sterba <dsterba@suse.com>
Mon, 15 Oct 2018 15:23:32 +0000 (17:23 +0200)
commitfee7acc361314df6561208c2d3c0882d663dd537
treed302291b655463c681d69feca558e7638ccc3b29
parent0be88e367fd8fbdb45257615d691f4675dda062f
btrfs: keep trim from interfering with transaction commits

Commit 499f377f49f08 (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: 499f377f49f08 ("btrfs: iterate over unused chunk space in FITRIM")
CC: stable@vger.kernel.org # 4.4+
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-tree.c