2020-02-26 09:57:53

by Ritesh Harjani

[permalink] [raw]
Subject: [PATCHv3 2/6] ext4: Optimize ext4_ext_precache for 0 depth

This patch avoids the memory alloc & free path when depth is 0,
since anyway there is no extra caching done in that case.
So on checking depth 0, simply return early.

Signed-off-by: Ritesh Harjani <[email protected]>
---
fs/ext4/extents.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index ee83fe7c98aa..0de548bb3c90 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -594,6 +594,12 @@ int ext4_ext_precache(struct inode *inode)
down_read(&ei->i_data_sem);
depth = ext_depth(inode);

+ /* Don't cache anything if there are no external extent blocks */
+ if (!depth) {
+ up_read(&ei->i_data_sem);
+ return ret;
+ }
+
path = kcalloc(depth + 1, sizeof(struct ext4_ext_path),
GFP_NOFS);
if (path == NULL) {
@@ -601,9 +607,6 @@ int ext4_ext_precache(struct inode *inode)
return -ENOMEM;
}

- /* Don't cache anything if there are no external extent blocks */
- if (depth == 0)
- goto out;
path[0].p_hdr = ext_inode_hdr(inode);
ret = ext4_ext_check(inode, path[0].p_hdr, depth, 0);
if (ret)
--
2.21.0


2020-02-26 12:32:50

by Jan Kara

[permalink] [raw]
Subject: Re: [PATCHv3 2/6] ext4: Optimize ext4_ext_precache for 0 depth

On Wed 26-02-20 15:27:04, Ritesh Harjani wrote:
> This patch avoids the memory alloc & free path when depth is 0,
> since anyway there is no extra caching done in that case.
> So on checking depth 0, simply return early.
>
> Signed-off-by: Ritesh Harjani <[email protected]>

Looks good to me. You can add:

Reviewed-by: Jan Kara <[email protected]>

Honza

> ---
> fs/ext4/extents.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index ee83fe7c98aa..0de548bb3c90 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -594,6 +594,12 @@ int ext4_ext_precache(struct inode *inode)
> down_read(&ei->i_data_sem);
> depth = ext_depth(inode);
>
> + /* Don't cache anything if there are no external extent blocks */
> + if (!depth) {
> + up_read(&ei->i_data_sem);
> + return ret;
> + }
> +
> path = kcalloc(depth + 1, sizeof(struct ext4_ext_path),
> GFP_NOFS);
> if (path == NULL) {
> @@ -601,9 +607,6 @@ int ext4_ext_precache(struct inode *inode)
> return -ENOMEM;
> }
>
> - /* Don't cache anything if there are no external extent blocks */
> - if (depth == 0)
> - goto out;
> path[0].p_hdr = ext_inode_hdr(inode);
> ret = ext4_ext_check(inode, path[0].p_hdr, depth, 0);
> if (ret)
> --
> 2.21.0
>
--
Jan Kara <[email protected]>
SUSE Labs, CR