瀏覽代碼

btrfs: don't add both copies of DUP to reada extent tree

Normally when there are 2 copies of a block, we add both to the
reada extent tree and prefetch only the one that is easier to reach.
This way we can better utilize multiple devices.
In case of DUP this makes no sense as both copies reside on the
same device.

Signed-off-by: Arne Jansen <sensille@gmx.net>
Arne Jansen 13 年之前
父節點
當前提交
207a232cca
共有 1 個文件被更改,包括 13 次插入0 次删除
  1. 13 0
      fs/btrfs/reada.c

+ 13 - 0
fs/btrfs/reada.c

@@ -326,6 +326,7 @@ static struct reada_extent *reada_find_extent(struct btrfs_root *root,
 	struct btrfs_mapping_tree *map_tree = &fs_info->mapping_tree;
 	struct btrfs_mapping_tree *map_tree = &fs_info->mapping_tree;
 	struct btrfs_bio *bbio = NULL;
 	struct btrfs_bio *bbio = NULL;
 	struct btrfs_device *dev;
 	struct btrfs_device *dev;
+	struct btrfs_device *prev_dev;
 	u32 blocksize;
 	u32 blocksize;
 	u64 length;
 	u64 length;
 	int nzones = 0;
 	int nzones = 0;
@@ -405,8 +406,20 @@ static struct reada_extent *reada_find_extent(struct btrfs_root *root,
 		spin_unlock(&fs_info->reada_lock);
 		spin_unlock(&fs_info->reada_lock);
 		goto error;
 		goto error;
 	}
 	}
+	prev_dev = NULL;
 	for (i = 0; i < nzones; ++i) {
 	for (i = 0; i < nzones; ++i) {
 		dev = bbio->stripes[i].dev;
 		dev = bbio->stripes[i].dev;
+		if (dev == prev_dev) {
+			/*
+			 * in case of DUP, just add the first zone. As both
+			 * are on the same device, there's nothing to gain
+			 * from adding both.
+			 * Also, it wouldn't work, as the tree is per device
+			 * and adding would fail with EEXIST
+			 */
+			continue;
+		}
+		prev_dev = dev;
 		ret = radix_tree_insert(&dev->reada_extents, index, re);
 		ret = radix_tree_insert(&dev->reada_extents, index, re);
 		if (ret) {
 		if (ret) {
 			while (--i >= 0) {
 			while (--i >= 0) {