浏览代码

Btrfs: do less aggressive btree readahead

Just before reading a leaf, btrfs scans the node for blocks that are
close by and reads them too.  It tries to build up a large window
of IO looking for blocks that are within a max distance from the top
and bottom of the IO window.

This patch changes things to just look for blocks within 64k of the
target block.  It will trigger less IO and make for lower latencies on
the read size.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
Chris Mason 16 年之前
父节点
当前提交
a717531942
共有 1 个文件被更改,包括 5 次插入16 次删除
  1. 5 16
      fs/btrfs/ctree.c

+ 5 - 16
fs/btrfs/ctree.c

@@ -1210,8 +1210,7 @@ static noinline void reada_for_search(struct btrfs_root *root,
 	struct btrfs_disk_key disk_key;
 	struct btrfs_disk_key disk_key;
 	u32 nritems;
 	u32 nritems;
 	u64 search;
 	u64 search;
-	u64 lowest_read;
-	u64 highest_read;
+	u64 target;
 	u64 nread = 0;
 	u64 nread = 0;
 	int direction = path->reada;
 	int direction = path->reada;
 	struct extent_buffer *eb;
 	struct extent_buffer *eb;
@@ -1235,8 +1234,7 @@ static noinline void reada_for_search(struct btrfs_root *root,
 		return;
 		return;
 	}
 	}
 
 
-	highest_read = search;
-	lowest_read = search;
+	target = search;
 
 
 	nritems = btrfs_header_nritems(node);
 	nritems = btrfs_header_nritems(node);
 	nr = slot;
 	nr = slot;
@@ -1256,24 +1254,15 @@ static noinline void reada_for_search(struct btrfs_root *root,
 				break;
 				break;
 		}
 		}
 		search = btrfs_node_blockptr(node, nr);
 		search = btrfs_node_blockptr(node, nr);
-		if ((search >= lowest_read && search <= highest_read) ||
-		    (search < lowest_read && lowest_read - search <= 16384) ||
-		    (search > highest_read && search - highest_read <= 16384)) {
+		if ((search <= target && target - search <= 65536) ||
+		    (search > target && search - target <= 65536)) {
 			readahead_tree_block(root, search, blocksize,
 			readahead_tree_block(root, search, blocksize,
 				     btrfs_node_ptr_generation(node, nr));
 				     btrfs_node_ptr_generation(node, nr));
 			nread += blocksize;
 			nread += blocksize;
 		}
 		}
 		nscan++;
 		nscan++;
-		if (path->reada < 2 && (nread > (64 * 1024) || nscan > 32))
+		if ((nread > 65536 || nscan > 32))
 			break;
 			break;
-
-		if (nread > (256 * 1024) || nscan > 128)
-			break;
-
-		if (search < lowest_read)
-			lowest_read = search;
-		if (search > highest_read)
-			highest_read = search;
 	}
 	}
 }
 }