[1/3] btrfs: use ->devices list instead of ->alloc_list in btrfs_trim_fs
diff mbox series

Message ID 20180906211816.12121-2-jeffm@suse.com
State New
Headers show
Series
  • btrfs: trim latency improvements
Related show

Commit Message

Jeff Mahoney Sept. 6, 2018, 9:18 p.m. UTC
From: Jeff Mahoney <jeffm@suse.com>

btrfs_trim_fs iterates over the fs_devices->alloc_list while holding
the device_list_mutex.  The problem is that ->alloc_list is protected
by the chunk mutex.  We don't want to hold the chunk mutex over
the trim of the entire file system.  Fortunately, the ->dev_list
list is protected by the dev_list mutex and while it will give us
all devices, including read-only devices, we already just skip the
read-only devices.  Then we can continue to take and release the chunk
mutex while scanning each device.

Fixes: 499f377f49f (btrfs: iterate over unused chunk space in FITRIM)
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/extent-tree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

David Sterba Sept. 14, 2018, 4:22 p.m. UTC | #1
On Thu, Sep 06, 2018 at 05:18:14PM -0400, jeffm@suse.com wrote:
> From: Jeff Mahoney <jeffm@suse.com>
> 
> btrfs_trim_fs iterates over the fs_devices->alloc_list while holding
> the device_list_mutex.  The problem is that ->alloc_list is protected
> by the chunk mutex.  We don't want to hold the chunk mutex over
> the trim of the entire file system.  Fortunately, the ->dev_list
> list is protected by the dev_list mutex and while it will give us
> all devices, including read-only devices, we already just skip the
> read-only devices.  Then we can continue to take and release the chunk
> mutex while scanning each device.
> 
> Fixes: 499f377f49f (btrfs: iterate over unused chunk space in FITRIM)
> Signed-off-by: Jeff Mahoney <jeffm@suse.com>

Reviewed-by: David Sterba <dsterba@suse.com>

Patch
diff mbox series

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 3d9fe58c0080..a0e82589c3e8 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -11008,8 +11008,8 @@  int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range)
 	}
 
 	mutex_lock(&fs_info->fs_devices->device_list_mutex);
-	devices = &fs_info->fs_devices->alloc_list;
-	list_for_each_entry(device, devices, dev_alloc_list) {
+	devices = &fs_info->fs_devices->devices;
+	list_for_each_entry(device, devices, dev_list) {
 		ret = btrfs_trim_free_extents(device, range->minlen,
 					      &group_trimmed);
 		if (ret)