2011-06-30 08:03:45

by Robin Dong

[permalink] [raw]
Subject: [PATCH 1/2] ext4: remove redundant goto tag "repeat"

If eh->eh_entries is smaller than eh->eh_max, the routine will
go to the "repeat" and then go to "has_space" directlly ,
since argument "depth" and "eh" are not even changed.

Therefore, goto "has_space" directly and remove redundant "repeat" tag.

Signed-off-by: Robin Dong <[email protected]>
---
fs/ext4/extents.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index eb63c7b..dc5ef91 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -1758,7 +1758,6 @@ int ext4_ext_insert_extent(handle_t *handle, struct inode *inode,
goto merge;
}

-repeat:
depth = ext_depth(inode);
eh = path[depth].p_hdr;
if (le16_to_cpu(eh->eh_entries) < le16_to_cpu(eh->eh_max))
@@ -1780,7 +1779,7 @@ repeat:
ext_debug("next leaf isn't full(%d)\n",
le16_to_cpu(eh->eh_entries));
path = npath;
- goto repeat;
+ 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));
--
1.7.1



2011-06-30 08:03:48

by Robin Dong

[permalink] [raw]
Subject: [PATCH 2/2] ext4: avoid finding next leaf if newext->ee_block smaller than fex->ee_block

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 <[email protected]>
---
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) {
- 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


2011-06-30 08:42:32

by Yongqiang Yang

[permalink] [raw]
Subject: Re: [PATCH 2/2] ext4: avoid finding next leaf if newext->ee_block smaller than fex->ee_block

On Thu, Jun 30, 2011 at 4:03 PM, Robin Dong <[email protected]> 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 <[email protected]>
> ---
> ?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 [email protected]
> More majordomo info at ?http://vger.kernel.org/majordomo-info.html
>



--
Best Wishes
Yongqiang Yang

2011-06-30 11:56:48

by Lukas Czerner

[permalink] [raw]
Subject: Re: [PATCH 1/2] ext4: remove redundant goto tag "repeat"

On Thu, 30 Jun 2011, Robin Dong wrote:

> If eh->eh_entries is smaller than eh->eh_max, the routine will
> go to the "repeat" and then go to "has_space" directlly ,
> since argument "depth" and "eh" are not even changed.
>
> Therefore, goto "has_space" directly and remove redundant "repeat" tag.

The patch looks good. Thanks!

-Lukas

>
> Signed-off-by: Robin Dong <[email protected]>
> ---
> fs/ext4/extents.c | 3 +--
> 1 files changed, 1 insertions(+), 2 deletions(-)
>
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index eb63c7b..dc5ef91 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -1758,7 +1758,6 @@ int ext4_ext_insert_extent(handle_t *handle, struct inode *inode,
> goto merge;
> }
>
> -repeat:
> depth = ext_depth(inode);
> eh = path[depth].p_hdr;
> if (le16_to_cpu(eh->eh_entries) < le16_to_cpu(eh->eh_max))
> @@ -1780,7 +1779,7 @@ repeat:
> ext_debug("next leaf isn't full(%d)\n",
> le16_to_cpu(eh->eh_entries));
> path = npath;
> - goto repeat;
> + 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));
>

2011-07-11 15:45:36

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH 1/2] ext4: remove redundant goto tag "repeat"

On Thu, Jun 30, 2011 at 04:03:33PM +0800, Robin Dong wrote:
> If eh->eh_entries is smaller than eh->eh_max, the routine will
> go to the "repeat" and then go to "has_space" directlly ,
> since argument "depth" and "eh" are not even changed.
>
> Therefore, goto "has_space" directly and remove redundant "repeat" tag.
>
> Signed-off-by: Robin Dong <[email protected]>

Thanks, added to the ext4 tree.

- Ted

2011-07-11 17:07:22

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH 2/2] ext4: avoid finding next leaf if newext->ee_block smaller than fex->ee_block

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 <[email protected]>

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 <[email protected]>

.... 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

2011-07-11 19:52:15

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH 2/2] ext4: avoid finding next leaf if newext->ee_block smaller than fex->ee_block

On Thu, Jun 30, 2011 at 04:42:31PM +0800, Yongqiang Yang wrote:
> 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) {

Agreed, that's a better way of doing things. Also, Robin, please
compare and contrast your description with mine. The commit
description shouldn't just be a textual description of the change. It
should give the larger context of the change and why it's important.

- Ted

commit 2a3f7e0e0e55f8817fbe92d111ef2a06e6b8ef18
Author: Robin Dong <[email protected]>
Date: Mon Jul 11 15:43:38 2011 -0400

ext4: avoid unneeded ext4_ext_next_leaf_block() while inserting extents

Optimize ext4_exT_insert_extent() by avoiding
ext4_ext_next_leaf_block() when the result is not used/needed.

Signed-off-by: Robin Dong <[email protected]>
Signed-off-by: "Theodore Ts'o" <[email protected]>

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 9cbdcb2..f1c538e 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -1730,9 +1730,10 @@ 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) {
+ 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) {
ext_debug("next leaf block - %d\n", next);
BUG_ON(npath != NULL);
npath = ext4_ext_find_extent(inode, next, NULL);

2011-07-12 01:33:27

by Robin Dong

[permalink] [raw]
Subject: Re: [PATCH 2/2] ext4: avoid finding next leaf if newext->ee_block smaller than fex->ee_block

2011/7/12 Ted Ts'o <[email protected]>:
> On Thu, Jun 30, 2011 at 04:42:31PM +0800, Yongqiang Yang wrote:
>> 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) {
>
> Agreed, that's a better way of doing things. ?Also, Robin, please
> compare and contrast your description with mine. ?The commit
> description shouldn't just be a textual description of the change. ?It
> should give the larger context of the change and why it's important.
>
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? - Ted
>
> commit 2a3f7e0e0e55f8817fbe92d111ef2a06e6b8ef18
> Author: Robin Dong <[email protected]>
> Date: ? Mon Jul 11 15:43:38 2011 -0400
>
> ? ?ext4: avoid unneeded ext4_ext_next_leaf_block() while inserting extents
>
> ? ?Optimize ext4_exT_insert_extent() by avoiding
> ? ?ext4_ext_next_leaf_block() when the result is not used/needed.
>
> ? ?Signed-off-by: Robin Dong <[email protected]>
> ? ?Signed-off-by: "Theodore Ts'o" <[email protected]>
>
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index 9cbdcb2..f1c538e 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -1730,9 +1730,10 @@ 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) {
> + ? ? ? 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) {
> ? ? ? ? ? ? ? ?ext_debug("next leaf block - %d\n", next);
> ? ? ? ? ? ? ? ?BUG_ON(npath != NULL);
> ? ? ? ? ? ? ? ?npath = ext4_ext_find_extent(inode, next, NULL);
>

It seems much better than my description. Thanks!

--
--
Best Regard
Robin Dong