[Btrfs-devel] fix block readahead in btrfs_next_leaf
Yan Zheng
yanzheng at 21cn.com
Mon Aug 27 06:10:01 PDT 2007
2007/8/27, Chris Mason <chris.mason at oracle.com>:
> It is hard to comment on this patch because there's no description for
> why you think it fixes block readahead. But, reada_for_search tries to
> cluster blocks close to the one indicated in path->nodes[level][slot],
> so always using slot=zero should make us cluster by the first block
> pointer in the node.
> The defrag code tries to keep the nodes mostly contiguous, but it
> should be better to cluster by the block we're actually looking for.
> -chris
>
int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path)
{
int slot;
int level = 1;
u64 blocknr;
struct buffer_head *c;
struct btrfs_node *c_node;
struct buffer_head *next = NULL;
while(level < BTRFS_MAX_LEVEL) {
if (!path->nodes[level])
return 1;
slot = path->slots[level] + 1;
c = path->nodes[level];
c_node = btrfs_buffer_node(c);
if (slot >= btrfs_header_nritems(&c_node->header)) {
level++;
continue;
}
blocknr = btrfs_node_blockptr(c_node, slot);
if (next)
btrfs_block_release(root, next);
if (path->reada)
reada_for_search(root, path, level, slot);
next = read_tree_block(root, blocknr);
BUG_ON (!next);
break;
}
path->slots[level] = slot;
while(1) {
level--;
c = path->nodes[level];
btrfs_block_release(root, c);
path->nodes[level] = next;
path->slots[level] = 0;
if (!level)
break;
if (path->reada)
reada_for_search(root, path, level, slot);
next = read_tree_block(root,
btrfs_node_blockptr(btrfs_buffer_node(next), 0));
}
return 0;
}
I think in the second while loop, slot should set to 0.
Regards
YZ
More information about the Btrfs-devel
mailing list