Filipe David Borba Manana
2013-Jul-03 12:19 UTC
[PATCH] Btrfs: optimize function btrfs_read_chunk_tree
After reading all device items from the chunk tree, don''t exit the loop and then navigate down the tree again to find the chunk items. Instead, if while reading the device items we find a chunk item in the leaf keep iterating over the leaf and process the chunk items - at the moment chunk items always follow immediately the device items in the chunk tree, and if this fact changes in the future, revert back to previous behaviour of exiting the loop and navigate down the tree again to search for chunk items, but use BTRFS_FIRST_CHUNK_TREE_OBJECTID as the object id for the search key, as any chunk item has a key that has this object id. Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com> --- fs/btrfs/volumes.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index b2d1eac..4e969db 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5668,8 +5668,13 @@ again: } btrfs_item_key_to_cpu(leaf, &found_key, slot); if (key.objectid == BTRFS_DEV_ITEMS_OBJECTID) { - if (found_key.objectid != BTRFS_DEV_ITEMS_OBJECTID) + if (found_key.objectid != BTRFS_DEV_ITEMS_OBJECTID) { + if (found_key.type == BTRFS_CHUNK_ITEM_KEY) { + key.objectid = found_key.objectid; + continue; + } break; + } if (found_key.type == BTRFS_DEV_ITEM_KEY) { struct btrfs_dev_item *dev_item; dev_item = btrfs_item_ptr(leaf, slot, @@ -5688,7 +5693,7 @@ again: path->slots[0]++; } if (key.objectid == BTRFS_DEV_ITEMS_OBJECTID) { - key.objectid = 0; + key.objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID; btrfs_release_path(path); goto again; } -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Filipe David Borba Manana
2013-Jul-29 18:22 UTC
[PATCH v2] Btrfs: optimize function btrfs_read_chunk_tree
After reading all device items from the chunk tree, don''t exit the loop and then navigate down the tree again to find the chunk items. Instead just read all device items and chunk items with a single tree search. This is possible because all device items are found before any chunk item in the chunks tree. Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com> --- V2: Simplified logic inside the loop (suggested by Josef Bacik on irc). fs/btrfs/volumes.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 090f57c..45c5ec3 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5676,14 +5676,13 @@ int btrfs_read_chunk_tree(struct btrfs_root *root) mutex_lock(&uuid_mutex); lock_chunks(root); - /* first we search for all of the device items, and then we - * read in all of the chunk items. This way we can create chunk - * mappings that reference all of the devices that are afound - */ + /* Read all device items, and then all the chunk items. All + device items are found before any chunk item (their object id + is smaller than the lowest possible object id for a chunk + item - BTRFS_FIRST_CHUNK_TREE_OBJECTID). */ key.objectid = BTRFS_DEV_ITEMS_OBJECTID; key.offset = 0; key.type = 0; -again: ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); if (ret < 0) goto error; @@ -5699,17 +5698,13 @@ again: break; } btrfs_item_key_to_cpu(leaf, &found_key, slot); - if (key.objectid == BTRFS_DEV_ITEMS_OBJECTID) { - if (found_key.objectid != BTRFS_DEV_ITEMS_OBJECTID) - break; - if (found_key.type == BTRFS_DEV_ITEM_KEY) { - struct btrfs_dev_item *dev_item; - dev_item = btrfs_item_ptr(leaf, slot, + if (found_key.type == BTRFS_DEV_ITEM_KEY) { + struct btrfs_dev_item *dev_item; + dev_item = btrfs_item_ptr(leaf, slot, struct btrfs_dev_item); - ret = read_one_dev(root, leaf, dev_item); - if (ret) - goto error; - } + ret = read_one_dev(root, leaf, dev_item); + if (ret) + goto error; } else if (found_key.type == BTRFS_CHUNK_ITEM_KEY) { struct btrfs_chunk *chunk; chunk = btrfs_item_ptr(leaf, slot, struct btrfs_chunk); @@ -5719,11 +5714,6 @@ again: } path->slots[0]++; } - if (key.objectid == BTRFS_DEV_ITEMS_OBJECTID) { - key.objectid = 0; - btrfs_release_path(path); - goto again; - } ret = 0; error: unlock_chunks(root); -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Miao Xie
2013-Jul-30 03:09 UTC
Re: [PATCH v2] Btrfs: optimize function btrfs_read_chunk_tree
On mon, 29 Jul 2013 19:22:34 +0100, Filipe David Borba Manana wrote:> After reading all device items from the chunk tree, don''t > exit the loop and then navigate down the tree again to find > the chunk items. Instead just read all device items and > chunk items with a single tree search. This is possible > because all device items are found before any chunk item in > the chunks tree. > > Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com> > --- > > V2: Simplified logic inside the loop > (suggested by Josef Bacik on irc). > > fs/btrfs/volumes.c | 30 ++++++++++-------------------- > 1 file changed, 10 insertions(+), 20 deletions(-) > > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c > index 090f57c..45c5ec3 100644 > --- a/fs/btrfs/volumes.c > +++ b/fs/btrfs/volumes.c > @@ -5676,14 +5676,13 @@ int btrfs_read_chunk_tree(struct btrfs_root *root) > mutex_lock(&uuid_mutex); > lock_chunks(root); > > - /* first we search for all of the device items, and then we > - * read in all of the chunk items. This way we can create chunk > - * mappings that reference all of the devices that are afound > - */ > + /* Read all device items, and then all the chunk items. All > + device items are found before any chunk item (their object id > + is smaller than the lowest possible object id for a chunk > + item - BTRFS_FIRST_CHUNK_TREE_OBJECTID). */According to the coding style of the kernel(Documentation/CodingStyle), the preferred style for long (multi-line) comments is: /* * This is the preferred style for multi-line * comments in the Linux kernel source code. * * Description: A column of asterisks on the left side, * with beginning and ending almost-blank lines. */ The other code is OK. Reviewed-by: Miao Xie <miaox@cn.fujitsu.com>> key.objectid = BTRFS_DEV_ITEMS_OBJECTID; > key.offset = 0; > key.type = 0; > -again: > ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); > if (ret < 0) > goto error; > @@ -5699,17 +5698,13 @@ again: > break; > } > btrfs_item_key_to_cpu(leaf, &found_key, slot); > - if (key.objectid == BTRFS_DEV_ITEMS_OBJECTID) { > - if (found_key.objectid != BTRFS_DEV_ITEMS_OBJECTID) > - break; > - if (found_key.type == BTRFS_DEV_ITEM_KEY) { > - struct btrfs_dev_item *dev_item; > - dev_item = btrfs_item_ptr(leaf, slot, > + if (found_key.type == BTRFS_DEV_ITEM_KEY) { > + struct btrfs_dev_item *dev_item; > + dev_item = btrfs_item_ptr(leaf, slot, > struct btrfs_dev_item); > - ret = read_one_dev(root, leaf, dev_item); > - if (ret) > - goto error; > - } > + ret = read_one_dev(root, leaf, dev_item); > + if (ret) > + goto error; > } else if (found_key.type == BTRFS_CHUNK_ITEM_KEY) { > struct btrfs_chunk *chunk; > chunk = btrfs_item_ptr(leaf, slot, struct btrfs_chunk); > @@ -5719,11 +5714,6 @@ again: > } > path->slots[0]++; > } > - if (key.objectid == BTRFS_DEV_ITEMS_OBJECTID) { > - key.objectid = 0; > - btrfs_release_path(path); > - goto again; > - } > ret = 0; > error: > unlock_chunks(root); >-- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Filipe David Borba Manana
2013-Jul-30 11:03 UTC
[PATCH v3] Btrfs: optimize function btrfs_read_chunk_tree
After reading all device items from the chunk tree, don''t exit the loop and then navigate down the tree again to find the chunk items. Instead just read all device items and chunk items with a single tree search. This is possible because all device items are found before any chunk item in the chunks tree. Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com> --- V2: Simplified logic inside the loop (suggested by Josef Bacik on irc). V3: Updated comment to comply with kernel coding style. fs/btrfs/volumes.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 090f57c..125a60e 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5676,14 +5676,15 @@ int btrfs_read_chunk_tree(struct btrfs_root *root) mutex_lock(&uuid_mutex); lock_chunks(root); - /* first we search for all of the device items, and then we - * read in all of the chunk items. This way we can create chunk - * mappings that reference all of the devices that are afound + /* + * Read all device items, and then all the chunk items. All + * device items are found before any chunk item (their object id + * is smaller than the lowest possible object id for a chunk + * item - BTRFS_FIRST_CHUNK_TREE_OBJECTID). */ key.objectid = BTRFS_DEV_ITEMS_OBJECTID; key.offset = 0; key.type = 0; -again: ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); if (ret < 0) goto error; @@ -5699,17 +5700,13 @@ again: break; } btrfs_item_key_to_cpu(leaf, &found_key, slot); - if (key.objectid == BTRFS_DEV_ITEMS_OBJECTID) { - if (found_key.objectid != BTRFS_DEV_ITEMS_OBJECTID) - break; - if (found_key.type == BTRFS_DEV_ITEM_KEY) { - struct btrfs_dev_item *dev_item; - dev_item = btrfs_item_ptr(leaf, slot, + if (found_key.type == BTRFS_DEV_ITEM_KEY) { + struct btrfs_dev_item *dev_item; + dev_item = btrfs_item_ptr(leaf, slot, struct btrfs_dev_item); - ret = read_one_dev(root, leaf, dev_item); - if (ret) - goto error; - } + ret = read_one_dev(root, leaf, dev_item); + if (ret) + goto error; } else if (found_key.type == BTRFS_CHUNK_ITEM_KEY) { struct btrfs_chunk *chunk; chunk = btrfs_item_ptr(leaf, slot, struct btrfs_chunk); @@ -5719,11 +5716,6 @@ again: } path->slots[0]++; } - if (key.objectid == BTRFS_DEV_ITEMS_OBJECTID) { - key.objectid = 0; - btrfs_release_path(path); - goto again; - } ret = 0; error: unlock_chunks(root); -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Miao Xie
2013-Jul-31 01:12 UTC
Re: [PATCH v3] Btrfs: optimize function btrfs_read_chunk_tree
On tue, 30 Jul 2013 12:03:04 +0100, Filipe David Borba Manana wrote:> After reading all device items from the chunk tree, don''t > exit the loop and then navigate down the tree again to find > the chunk items. Instead just read all device items and > chunk items with a single tree search. This is possible > because all device items are found before any chunk item in > the chunks tree. > > Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com> > --- > > V2: Simplified logic inside the loop > (suggested by Josef Bacik on irc). > V3: Updated comment to comply with kernel coding style.Reviewed-by: Miao Xie <miaox@cn.fujitsu.com>> > fs/btrfs/volumes.c | 30 +++++++++++------------------- > 1 file changed, 11 insertions(+), 19 deletions(-) > > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c > index 090f57c..125a60e 100644 > --- a/fs/btrfs/volumes.c > +++ b/fs/btrfs/volumes.c > @@ -5676,14 +5676,15 @@ int btrfs_read_chunk_tree(struct btrfs_root *root) > mutex_lock(&uuid_mutex); > lock_chunks(root); > > - /* first we search for all of the device items, and then we > - * read in all of the chunk items. This way we can create chunk > - * mappings that reference all of the devices that are afound > + /* > + * Read all device items, and then all the chunk items. All > + * device items are found before any chunk item (their object id > + * is smaller than the lowest possible object id for a chunk > + * item - BTRFS_FIRST_CHUNK_TREE_OBJECTID). > */ > key.objectid = BTRFS_DEV_ITEMS_OBJECTID; > key.offset = 0; > key.type = 0; > -again: > ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); > if (ret < 0) > goto error; > @@ -5699,17 +5700,13 @@ again: > break; > } > btrfs_item_key_to_cpu(leaf, &found_key, slot); > - if (key.objectid == BTRFS_DEV_ITEMS_OBJECTID) { > - if (found_key.objectid != BTRFS_DEV_ITEMS_OBJECTID) > - break; > - if (found_key.type == BTRFS_DEV_ITEM_KEY) { > - struct btrfs_dev_item *dev_item; > - dev_item = btrfs_item_ptr(leaf, slot, > + if (found_key.type == BTRFS_DEV_ITEM_KEY) { > + struct btrfs_dev_item *dev_item; > + dev_item = btrfs_item_ptr(leaf, slot, > struct btrfs_dev_item); > - ret = read_one_dev(root, leaf, dev_item); > - if (ret) > - goto error; > - } > + ret = read_one_dev(root, leaf, dev_item); > + if (ret) > + goto error; > } else if (found_key.type == BTRFS_CHUNK_ITEM_KEY) { > struct btrfs_chunk *chunk; > chunk = btrfs_item_ptr(leaf, slot, struct btrfs_chunk); > @@ -5719,11 +5716,6 @@ again: > } > path->slots[0]++; > } > - if (key.objectid == BTRFS_DEV_ITEMS_OBJECTID) { > - key.objectid = 0; > - btrfs_release_path(path); > - goto again; > - } > ret = 0; > error: > unlock_chunks(root); >-- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html