* [PATCH] ext2: optimize ext2_xattr_get()
@ 2019-05-21 8:21 Chengguang Xu
2019-05-23 14:46 ` Jan Kara
0 siblings, 1 reply; 5+ messages in thread
From: Chengguang Xu @ 2019-05-21 8:21 UTC (permalink / raw)
To: jack; +Cc: linux-ext4, Chengguang Xu
Since xattr entry names are sorted, we don't have
to continue when current entry name is greater than
target.
Signed-off-by: Chengguang Xu <cgxu519@zoho.com.cn>
---
fs/ext2/xattr.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
index d21dbf297b74..f1f857b83b45 100644
--- a/fs/ext2/xattr.c
+++ b/fs/ext2/xattr.c
@@ -178,7 +178,7 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name,
struct ext2_xattr_entry *entry;
size_t name_len, size;
char *end;
- int error;
+ int error, not_found;
struct mb_cache *ea_block_cache = EA_BLOCK_CACHE(inode);
ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
@@ -220,10 +220,18 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name,
goto bad_block;
if (!ext2_xattr_entry_valid(entry, inode->i_sb->s_blocksize))
goto bad_block;
- if (name_index == entry->e_name_index &&
- name_len == entry->e_name_len &&
- memcmp(name, entry->e_name, name_len) == 0)
+
+ not_found = name_index - entry->e_name_index;
+ if (!not_found)
+ not_found = name_len - entry->e_name_len;
+ if (!not_found)
+ not_found = memcmp(name, entry->e_name,
+ name_len);
+ if (!not_found)
goto found;
+ if (not_found < 0)
+ break;
+
entry = next;
}
if (ext2_xattr_cache_insert(ea_block_cache, bh))
--
2.20.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] ext2: optimize ext2_xattr_get()
2019-05-21 8:21 [PATCH] ext2: optimize ext2_xattr_get() Chengguang Xu
@ 2019-05-23 14:46 ` Jan Kara
2019-05-24 2:07 ` cgxu519
0 siblings, 1 reply; 5+ messages in thread
From: Jan Kara @ 2019-05-23 14:46 UTC (permalink / raw)
To: Chengguang Xu; +Cc: jack, linux-ext4
On Tue 21-05-19 16:21:39, Chengguang Xu wrote:
> Since xattr entry names are sorted, we don't have
> to continue when current entry name is greater than
> target.
>
> Signed-off-by: Chengguang Xu <cgxu519@zoho.com.cn>
Thanks for the patch! If we are going to do these comparisons in multiple
places, then please create a helper function to do the comparison (so that
we have the same comparison in every place). Something like:
int ext2_xattr_cmp(int name_index, size_t name_len, const char *name,
struct ext2_xattr_entry *entry)
Thanks!
Honza
> ---
> fs/ext2/xattr.c | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
> index d21dbf297b74..f1f857b83b45 100644
> --- a/fs/ext2/xattr.c
> +++ b/fs/ext2/xattr.c
> @@ -178,7 +178,7 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name,
> struct ext2_xattr_entry *entry;
> size_t name_len, size;
> char *end;
> - int error;
> + int error, not_found;
> struct mb_cache *ea_block_cache = EA_BLOCK_CACHE(inode);
>
> ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
> @@ -220,10 +220,18 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name,
> goto bad_block;
> if (!ext2_xattr_entry_valid(entry, inode->i_sb->s_blocksize))
> goto bad_block;
> - if (name_index == entry->e_name_index &&
> - name_len == entry->e_name_len &&
> - memcmp(name, entry->e_name, name_len) == 0)
> +
> + not_found = name_index - entry->e_name_index;
> + if (!not_found)
> + not_found = name_len - entry->e_name_len;
> + if (!not_found)
> + not_found = memcmp(name, entry->e_name,
> + name_len);
> + if (!not_found)
> goto found;
> + if (not_found < 0)
> + break;
> +
> entry = next;
> }
> if (ext2_xattr_cache_insert(ea_block_cache, bh))
> --
> 2.20.1
>
>
>
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ext2: optimize ext2_xattr_get()
2019-05-23 14:46 ` Jan Kara
@ 2019-05-24 2:07 ` cgxu519
2019-05-24 8:07 ` Jan Kara
0 siblings, 1 reply; 5+ messages in thread
From: cgxu519 @ 2019-05-24 2:07 UTC (permalink / raw)
To: Jan Kara; +Cc: jack, linux-ext4
On Thu, 2019-05-23 at 16:46 +0200, Jan Kara wrote:
> On Tue 21-05-19 16:21:39, Chengguang Xu wrote:
> > Since xattr entry names are sorted, we don't have
> > to continue when current entry name is greater than
> > target.
> >
> > Signed-off-by: Chengguang Xu <cgxu519@zoho.com.cn>
>
> Thanks for the patch! If we are going to do these comparisons in multiple
> places, then please create a helper function to do the comparison (so that
> we have the same comparison in every place). Something like:
>
> int ext2_xattr_cmp(int name_index, size_t name_len, const char *name,
> struct ext2_xattr_entry *entry)
>
Hi Jan,
Thanks for the review and advice.
You are right we should introduce a helper to handle this part of work
and personally I think maybe implementing a helper to find target entry
will be more useful, do you think it makes sense?
Thanks,
Chengguang
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ext2: optimize ext2_xattr_get()
2019-05-24 2:07 ` cgxu519
@ 2019-05-24 8:07 ` Jan Kara
2019-05-24 8:58 ` cgxu519
0 siblings, 1 reply; 5+ messages in thread
From: Jan Kara @ 2019-05-24 8:07 UTC (permalink / raw)
To: cgxu519; +Cc: Jan Kara, jack, linux-ext4
On Fri 24-05-19 10:07:05, cgxu519@zoho.com.cn wrote:
> On Thu, 2019-05-23 at 16:46 +0200, Jan Kara wrote:
> > On Tue 21-05-19 16:21:39, Chengguang Xu wrote:
> > > Since xattr entry names are sorted, we don't have
> > > to continue when current entry name is greater than
> > > target.
> > >
> > > Signed-off-by: Chengguang Xu <cgxu519@zoho.com.cn>
> >
> > Thanks for the patch! If we are going to do these comparisons in multiple
> > places, then please create a helper function to do the comparison (so that
> > we have the same comparison in every place). Something like:
> >
> > int ext2_xattr_cmp(int name_index, size_t name_len, const char *name,
> > struct ext2_xattr_entry *entry)
> >
>
> Hi Jan,
>
> Thanks for the review and advice.
>
> You are right we should introduce a helper to handle this part of work
> and personally I think maybe implementing a helper to find target entry
> will be more useful, do you think it makes sense?
It makes sense but ext2_xattr_set() also computes min_offs and last during
the search so using the search function in that case won't be a readbility
win I guess. So I'm not sure the search function pays off in the end.
Honza
>
>
> Thanks,
> Chengguang
>
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ext2: optimize ext2_xattr_get()
2019-05-24 8:07 ` Jan Kara
@ 2019-05-24 8:58 ` cgxu519
0 siblings, 0 replies; 5+ messages in thread
From: cgxu519 @ 2019-05-24 8:58 UTC (permalink / raw)
To: Jan Kara; +Cc: jack, linux-ext4
On Fri, 2019-05-24 at 10:07 +0200, Jan Kara wrote:
> On Fri 24-05-19 10:07:05, cgxu519@zoho.com.cn wrote:
> > On Thu, 2019-05-23 at 16:46 +0200, Jan Kara wrote:
> > > On Tue 21-05-19 16:21:39, Chengguang Xu wrote:
> > > > Since xattr entry names are sorted, we don't have
> > > > to continue when current entry name is greater than
> > > > target.
> > > >
> > > > Signed-off-by: Chengguang Xu <cgxu519@zoho.com.cn>
> > >
> > > Thanks for the patch! If we are going to do these comparisons in multiple
> > > places, then please create a helper function to do the comparison (so that
> > > we have the same comparison in every place). Something like:
> > >
> > > int ext2_xattr_cmp(int name_index, size_t name_len, const char *name,
> > > struct ext2_xattr_entry *entry)
> > >
> >
> > Hi Jan,
> >
> > Thanks for the review and advice.
> >
> > You are right we should introduce a helper to handle this part of work
> > and personally I think maybe implementing a helper to find target entry
> > will be more useful, do you think it makes sense?
>
> It makes sense but ext2_xattr_set() also computes min_offs and last during
> the search so using the search function in that case won't be a readbility
> win I guess. So I'm not sure the search function pays off in the end.
Yes, I noticed that too, I plan to set min_offs pointer as function parameter
so that we can seperate different search modes based on it.
Thanks,
Chengguang
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-05-24 8:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-21 8:21 [PATCH] ext2: optimize ext2_xattr_get() Chengguang Xu
2019-05-23 14:46 ` Jan Kara
2019-05-24 2:07 ` cgxu519
2019-05-24 8:07 ` Jan Kara
2019-05-24 8:58 ` cgxu519
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).