Patchwork [2/2] ext4: avoid finding next leaf if newext->ee_block smaller than fex->ee_block

login
register
mail settings
Submitter Robin Dong
Date June 30, 2011, 8:03 a.m.
Message ID <1309421014-6148-2-git-send-email-sanbai@taobao.com>
Download mbox | patch
Permalink /patch/102716/
State Superseded
Headers show

Comments

Robin Dong - June 30, 2011, 8:03 a.m.
If newext->ee_block is smaller than (or equal to) fex->ee_block, the call of
ext4_ext_next_leaf_block will be useless. We need to call it only after
newext->ee_block is greater than fex->ee_block.

Signed-off-by: Robin Dong <sanbai@taobao.com>
---
 fs/ext4/extents.c |   37 ++++++++++++++++++++-----------------
 1 files changed, 20 insertions(+), 17 deletions(-)
Yongqiang Yang - June 30, 2011, 8:42 a.m.
On Thu, Jun 30, 2011 at 4:03 PM, Robin Dong <hao.bigrat@gmail.com> wrote:
> If newext->ee_block is smaller than (or equal to) fex->ee_block, the call of
> ext4_ext_next_leaf_block will be useless. We need to call it only after
> newext->ee_block is greater than fex->ee_block.
>
> Signed-off-by: Robin Dong <sanbai@taobao.com>
> ---
>  fs/ext4/extents.c |   37 ++++++++++++++++++++-----------------
>  1 files changed, 20 insertions(+), 17 deletions(-)
>
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index dc5ef91..0ee475a 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -1765,24 +1765,27 @@ int ext4_ext_insert_extent(handle_t *handle, struct inode *inode,
>
>        /* probably next leaf has space for us? */
>        fex = EXT_LAST_EXTENT(eh);
> -       next = ext4_ext_next_leaf_block(inode, path);
> -       if (le32_to_cpu(newext->ee_block) > le32_to_cpu(fex->ee_block)
> -           && next != EXT_MAX_BLOCKS) {
How about:
           next = EXT_MAX_BLOCKS;
           if (le32_to_cpu(newext->ee_block) > le32_to_cpu(fex->ee_block)
                   next = ext4_ext_next_leaf_block(inode, path);
           if (next != EXT_MAX_BLOCKS) {
Code above can reduce an indent.

Yongqiang.
> -               ext_debug("next leaf block - %d\n", next);
> -               BUG_ON(npath != NULL);
> -               npath = ext4_ext_find_extent(inode, next, NULL);
> -               if (IS_ERR(npath))
> -                       return PTR_ERR(npath);
> -               BUG_ON(npath->p_depth != path->p_depth);
> -               eh = npath[depth].p_hdr;
> -               if (le16_to_cpu(eh->eh_entries) < le16_to_cpu(eh->eh_max)) {
> -                       ext_debug("next leaf isn't full(%d)\n",
> -                                 le16_to_cpu(eh->eh_entries));
> -                       path = npath;
> -                       goto has_space;
> +       if (le32_to_cpu(newext->ee_block) > le32_to_cpu(fex->ee_block)) {
> +               next = ext4_ext_next_leaf_block(inode, path);
> +               if (next != EXT_MAX_BLOCKS) {
> +                       ext_debug("next leaf block - %d\n", next);
> +                       BUG_ON(npath != NULL);
> +                       npath = ext4_ext_find_extent(inode, next, NULL);
> +                       if (IS_ERR(npath))
> +                               return PTR_ERR(npath);
> +                       BUG_ON(npath->p_depth != path->p_depth);
> +                       eh = npath[depth].p_hdr;
> +                       if (le16_to_cpu(eh->eh_entries) <
> +                                       le16_to_cpu(eh->eh_max)) {
> +                               ext_debug("next leaf isn't full(%d)\n",
> +                                         le16_to_cpu(eh->eh_entries));
> +                               path = npath;
> +                               goto has_space;
> +                       }
> +                       ext_debug("next leaf has no free space(%d,%d)\n",
> +                               le16_to_cpu(eh->eh_entries),
> +                               le16_to_cpu(eh->eh_max));
>                }
> -               ext_debug("next leaf has no free space(%d,%d)\n",
> -                         le16_to_cpu(eh->eh_entries), le16_to_cpu(eh->eh_max));
>        }
>
>        /*
> --
> 1.7.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
Theodore Ts'o - July 11, 2011, 5:07 p.m.
On Thu, Jun 30, 2011 at 04:03:34PM +0800, Robin Dong wrote:
> If newext->ee_block is smaller than (or equal to) fex->ee_block, the call of
> ext4_ext_next_leaf_block will be useless. We need to call it only after
> newext->ee_block is greater than fex->ee_block.
> 
> Signed-off-by: Robin Dong <sanbai@taobao.com>

Added to the ext4 tree, but I cleaned up the one-line summary of the
patch:

    ext4: remove redundant goto in ext4_ext_insert_extent()

It's important that the one-line summary be much more "big picture" so
that people who are looking through the git history can understand
what the commit does.  Also, I added an explicit

From: Robin Dong <sanbai@taobao.com>

.... so that the attribution was the same as what was in your
Signed-off-by (instead of your hao.bigrat address).  If that wasn't
your intent, let me know and I'll fix it before I lock it into the
master branch.

In the future, if you are sending the patch from a different e-mail
address, it would be useful if you explicitly add a "From: " line in
the body so it's clear.  I made the assumption in this case based on
the general practice of other taobao engineers, but as I said, let me
know if you would want something else.

Thanks!!

							- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index dc5ef91..0ee475a 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -1765,24 +1765,27 @@  int ext4_ext_insert_extent(handle_t *handle, struct inode *inode,
 
 	/* probably next leaf has space for us? */
 	fex = EXT_LAST_EXTENT(eh);
-	next = ext4_ext_next_leaf_block(inode, path);
-	if (le32_to_cpu(newext->ee_block) > le32_to_cpu(fex->ee_block)
-	    && next != EXT_MAX_BLOCKS) {
-		ext_debug("next leaf block - %d\n", next);
-		BUG_ON(npath != NULL);
-		npath = ext4_ext_find_extent(inode, next, NULL);
-		if (IS_ERR(npath))
-			return PTR_ERR(npath);
-		BUG_ON(npath->p_depth != path->p_depth);
-		eh = npath[depth].p_hdr;
-		if (le16_to_cpu(eh->eh_entries) < le16_to_cpu(eh->eh_max)) {
-			ext_debug("next leaf isn't full(%d)\n",
-				  le16_to_cpu(eh->eh_entries));
-			path = npath;
-			goto has_space;
+	if (le32_to_cpu(newext->ee_block) > le32_to_cpu(fex->ee_block)) {
+		next = ext4_ext_next_leaf_block(inode, path);
+		if (next != EXT_MAX_BLOCKS) {
+			ext_debug("next leaf block - %d\n", next);
+			BUG_ON(npath != NULL);
+			npath = ext4_ext_find_extent(inode, next, NULL);
+			if (IS_ERR(npath))
+				return PTR_ERR(npath);
+			BUG_ON(npath->p_depth != path->p_depth);
+			eh = npath[depth].p_hdr;
+			if (le16_to_cpu(eh->eh_entries) <
+					le16_to_cpu(eh->eh_max)) {
+				ext_debug("next leaf isn't full(%d)\n",
+					  le16_to_cpu(eh->eh_entries));
+				path = npath;
+				goto has_space;
+			}
+			ext_debug("next leaf has no free space(%d,%d)\n",
+				le16_to_cpu(eh->eh_entries),
+				le16_to_cpu(eh->eh_max));
 		}
-		ext_debug("next leaf has no free space(%d,%d)\n",
-			  le16_to_cpu(eh->eh_entries), le16_to_cpu(eh->eh_max));
 	}
 
 	/*