Yan Zheng
2007-Sep-11 08:27 UTC
[btrfs-devel][patch]Cache blocks in the hole at beginning of a block group
Hi When first extent item in a block group isn't at beginning of that block group, blocks in the hole (at beginning of a block group) is free. Regards YZ diff -r 9cb5f0f5c713 extent-tree.c --- a/extent-tree.c Thu Aug 30 12:16:51 2007 -0400 +++ b/extent-tree.c Tue Sep 11 22:59:56 2007 +0800 @@ -102,15 +102,14 @@ static int cache_block_group(struct btrf } if (btrfs_key_type(&key) == BTRFS_EXTENT_ITEM_KEY) { if (!found) { - last = key.objectid + key.offset; + last = block_group->key.objectid; found = 1; - } else { - hole_size = key.objectid - last; - for (i = 0; i < hole_size; i++) { - set_radix_bit(extent_radix, last + i); - } - last = key.objectid + key.offset; - } + } + hole_size = key.objectid - last; + for (i = 0; i < hole_size; i++) { + set_radix_bit(extent_radix, last + i); + } + last = key.objectid + key.offset; } path->slots[0]++; } -------------- next part -------------- A non-text attachment was scrubbed... Name: extent-tree.patch Type: text/x-patch Size: 758 bytes Desc: not available Url : http://oss.oracle.com/pipermail/btrfs-devel/attachments/20070911/0e40e7e9/extent-tree.bin
Chris Mason
2007-Sep-11 10:27 UTC
[btrfs-devel][patch]Cache blocks in the hole at beginning of a block group
On Tue, 11 Sep 2007 23:26:40 +0800 "Yan Zheng" <yanzheng@21cn.com> wrote:> Hi > > When first extent item in a block group isn't at beginning of that > block group, blocks in the hole (at beginning of a block group) is > free.Thanks, you've definitely found a bug in the current code, but I'm afraid we can't assume the start of the block group is free. There could be an extent allocated in the last block group that extends into the current one. So, we need to find the previous extent and make sure it doesn't overlap. -chris
Yan Zheng
2007-Sep-14 09:18 UTC
[btrfs-devel][patch]Cache blocks in the hole at beginning of a block group
Hello everyone. Please consider this patch, the original one has duplicate codes in the loop body. The only change in this one is move the duplicate codes out from the loop body. Regards YZ diff -r 0d4a5b197024 extent-tree.c --- a/extent-tree.c Tue Sep 11 19:45:31 2007 -0400 +++ b/extent-tree.c Fri Sep 14 23:21:08 2007 +0800 @@ -39,6 +39,7 @@ static int cache_block_group(struct btrf u64 i; u64 last = 0; u64 hole_size; + u64 first_free; int found = 0; root = root->fs_info->extent_root; @@ -52,6 +53,7 @@ static int cache_block_group(struct btrf if (!path) return -ENOMEM; path->reada = 2; + first_free = block_group->key.objectid; key.objectid = block_group->key.objectid; key.flags = 0; key.offset = 0; @@ -71,50 +73,45 @@ static int cache_block_group(struct btrf if (ret == 0) { continue; } else { - if (found) { - hole_size = block_group->key.objectid + - block_group->key.offset - last; - } else { - last = block_group->key.objectid; - hole_size = block_group->key.offset; - } - for (i = 0; i < hole_size; i++) { - set_radix_bit(extent_radix, - last + i); - } break; } } btrfs_disk_key_to_cpu(&key, &leaf->items[slot].key); + if (key.objectid < block_group->key.objectid) { + if (key.objectid + key.offset > first_free) + first_free = key.objectid + key.offset; + goto next; + } if (key.objectid >= block_group->key.objectid + block_group->key.offset) { - if (found) { - hole_size = block_group->key.objectid + - block_group->key.offset - last; - } else { - last = block_group->key.objectid; - hole_size = block_group->key.offset; - } + break; + } + if (btrfs_key_type(&key) == BTRFS_EXTENT_ITEM_KEY) { + if (!found) { + last = first_free; + found = 1; + } + hole_size = key.objectid - last; for (i = 0; i < hole_size; i++) { set_radix_bit(extent_radix, last + i); } - break; - } - if (btrfs_key_type(&key) == BTRFS_EXTENT_ITEM_KEY) { - if (!found) { - last = key.objectid + key.offset; - found = 1; - } else { - hole_size = key.objectid - last; - for (i = 0; i < hole_size; i++) { - set_radix_bit(extent_radix, last + i); - } - last = key.objectid + key.offset; - } - } + last = key.objectid + key.offset; + } +next: path->slots[0]++; } + if (!found) + last = first_free; + if (block_group->key.objectid + + block_group->key.offset > last) { + hole_size = block_group->key.objectid + + block_group->key.offset - last; + for (i = 0; i < hole_size; i++) { + set_radix_bit(extent_radix, + last + i); + } + } block_group->cached = 1; err: btrfs_free_path(path); -------------- next part -------------- A non-text attachment was scrubbed... Name: extent-tree.patch Type: text/x-patch Size: 2511 bytes Desc: not available Url : http://oss.oracle.com/pipermail/btrfs-devel/attachments/20070915/f2e21b0b/extent-tree.bin