* [PATCH] libxfs: Optimize the loop for xfs_bitmap_empty
@ 2015-11-09 14:31 Jia He
2015-11-10 12:54 ` Brian Foster
0 siblings, 1 reply; 6+ messages in thread
From: Jia He @ 2015-11-09 14:31 UTC (permalink / raw)
To: xfs; +Cc: Jia He, Brian Foster
If there is any non zero bit in a long bitmap, it can jump out of the for
loop and finish the function as soon as possible.
Signed-off-by: Jia He <hejianet@gmail.com>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Brian Foster <bfoster@redhat.com>
---
fs/xfs/libxfs/xfs_bit.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/xfs/libxfs/xfs_bit.c b/fs/xfs/libxfs/xfs_bit.c
index 0e8885a..84614b0 100644
--- a/fs/xfs/libxfs/xfs_bit.c
+++ b/fs/xfs/libxfs/xfs_bit.c
@@ -36,6 +36,8 @@ xfs_bitmap_empty(uint *map, uint size)
for (i = 0; i < size; i++) {
ret |= map[i];
+ if (ret != 0)
+ return 0;
}
return (ret == 0);
--
2.5.0
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] libxfs: Optimize the loop for xfs_bitmap_empty
2015-11-09 14:31 [PATCH] libxfs: Optimize the loop for xfs_bitmap_empty Jia He
@ 2015-11-10 12:54 ` Brian Foster
2015-11-11 6:37 ` hejianet
2015-11-11 7:49 ` [PATCH v2] " Jia He
0 siblings, 2 replies; 6+ messages in thread
From: Brian Foster @ 2015-11-10 12:54 UTC (permalink / raw)
To: Jia He; +Cc: xfs
On Mon, Nov 09, 2015 at 10:31:22PM +0800, Jia He wrote:
> If there is any non zero bit in a long bitmap, it can jump out of the for
> loop and finish the function as soon as possible.
>
> Signed-off-by: Jia He <hejianet@gmail.com>
> Cc: Dave Chinner <david@fromorbit.com>
> Cc: Brian Foster <bfoster@redhat.com>
> ---
> fs/xfs/libxfs/xfs_bit.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/fs/xfs/libxfs/xfs_bit.c b/fs/xfs/libxfs/xfs_bit.c
> index 0e8885a..84614b0 100644
> --- a/fs/xfs/libxfs/xfs_bit.c
> +++ b/fs/xfs/libxfs/xfs_bit.c
> @@ -36,6 +36,8 @@ xfs_bitmap_empty(uint *map, uint size)
>
> for (i = 0; i < size; i++) {
> ret |= map[i];
> + if (ret != 0)
> + return 0;
> }
>
Seems Ok to me, but if we're going to do this, why not just kill ret
entirely? For example, check 'if (map[i] != 0) return 0;' in the loop
and unconditionally return 1 if we make it to the end.
Brian
> return (ret == 0);
> --
> 2.5.0
>
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] libxfs: Optimize the loop for xfs_bitmap_empty
2015-11-10 12:54 ` Brian Foster
@ 2015-11-11 6:37 ` hejianet
2015-11-11 7:49 ` [PATCH v2] " Jia He
1 sibling, 0 replies; 6+ messages in thread
From: hejianet @ 2015-11-11 6:37 UTC (permalink / raw)
To: Brian Foster; +Cc: xfs
Hi Brian
Thanks, I will resend the patch V2
B.R.
Justin
在 11/10/15 8:54 PM, Brian Foster 写道:
> On Mon, Nov 09, 2015 at 10:31:22PM +0800, Jia He wrote:
>> If there is any non zero bit in a long bitmap, it can jump out of the for
>> loop and finish the function as soon as possible.
>>
>> Signed-off-by: Jia He <hejianet@gmail.com>
>> Cc: Dave Chinner <david@fromorbit.com>
>> Cc: Brian Foster <bfoster@redhat.com>
>> ---
>> fs/xfs/libxfs/xfs_bit.c | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/fs/xfs/libxfs/xfs_bit.c b/fs/xfs/libxfs/xfs_bit.c
>> index 0e8885a..84614b0 100644
>> --- a/fs/xfs/libxfs/xfs_bit.c
>> +++ b/fs/xfs/libxfs/xfs_bit.c
>> @@ -36,6 +36,8 @@ xfs_bitmap_empty(uint *map, uint size)
>>
>> for (i = 0; i < size; i++) {
>> ret |= map[i];
>> + if (ret != 0)
>> + return 0;
>> }
>>
> Seems Ok to me, but if we're going to do this, why not just kill ret
> entirely? For example, check 'if (map[i] != 0) return 0;' in the loop
> and unconditionally return 1 if we make it to the end.
>
> Brian
>
>> return (ret == 0);
>> --
>> 2.5.0
>>
>> _______________________________________________
>> xfs mailing list
>> xfs@oss.sgi.com
>> http://oss.sgi.com/mailman/listinfo/xfs
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
>
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] libxfs: Optimize the loop for xfs_bitmap_empty
2015-11-10 12:54 ` Brian Foster
2015-11-11 6:37 ` hejianet
@ 2015-11-11 7:49 ` Jia He
2015-11-11 12:48 ` Brian Foster
1 sibling, 1 reply; 6+ messages in thread
From: Jia He @ 2015-11-11 7:49 UTC (permalink / raw)
To: xfs; +Cc: Jia He, Brian Foster
If there is any non zero bit in a long bitmap, it can jump out of the
loop and finish the function as soon as possible.
Signed-off-by: Jia He <hejianet@gmail.com>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Brian Foster <bfoster@redhat.com>
---
fs/xfs/libxfs/xfs_bit.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/xfs/libxfs/xfs_bit.c b/fs/xfs/libxfs/xfs_bit.c
index 0e8885a..0a94cce 100644
--- a/fs/xfs/libxfs/xfs_bit.c
+++ b/fs/xfs/libxfs/xfs_bit.c
@@ -32,13 +32,13 @@ int
xfs_bitmap_empty(uint *map, uint size)
{
uint i;
- uint ret = 0;
for (i = 0; i < size; i++) {
- ret |= map[i];
+ if (map[i] != 0)
+ return 0;
}
- return (ret == 0);
+ return 1;
}
/*
--
2.5.0
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] libxfs: Optimize the loop for xfs_bitmap_empty
2015-11-11 7:49 ` [PATCH v2] " Jia He
@ 2015-11-11 12:48 ` Brian Foster
2015-12-16 3:04 ` hejianet
0 siblings, 1 reply; 6+ messages in thread
From: Brian Foster @ 2015-11-11 12:48 UTC (permalink / raw)
To: Jia He; +Cc: xfs
On Wed, Nov 11, 2015 at 03:49:01PM +0800, Jia He wrote:
> If there is any non zero bit in a long bitmap, it can jump out of the
> loop and finish the function as soon as possible.
>
> Signed-off-by: Jia He <hejianet@gmail.com>
> Cc: Dave Chinner <david@fromorbit.com>
> Cc: Brian Foster <bfoster@redhat.com>
> ---
Looks good to me:
Reviewed-by: Brian Foster <bfoster@redhat.com>
> fs/xfs/libxfs/xfs_bit.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/fs/xfs/libxfs/xfs_bit.c b/fs/xfs/libxfs/xfs_bit.c
> index 0e8885a..0a94cce 100644
> --- a/fs/xfs/libxfs/xfs_bit.c
> +++ b/fs/xfs/libxfs/xfs_bit.c
> @@ -32,13 +32,13 @@ int
> xfs_bitmap_empty(uint *map, uint size)
> {
> uint i;
> - uint ret = 0;
>
> for (i = 0; i < size; i++) {
> - ret |= map[i];
> + if (map[i] != 0)
> + return 0;
> }
>
> - return (ret == 0);
> + return 1;
> }
>
> /*
> --
> 2.5.0
>
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] libxfs: Optimize the loop for xfs_bitmap_empty
2015-11-11 12:48 ` Brian Foster
@ 2015-12-16 3:04 ` hejianet
0 siblings, 0 replies; 6+ messages in thread
From: hejianet @ 2015-12-16 3:04 UTC (permalink / raw)
To: xfs, david; +Cc: Brian Foster
Hi David
Do you have any comments from your point of view? Thanks ;)
B.R.
Justin
在 11/11/15 8:48 PM, Brian Foster 写道:
> On Wed, Nov 11, 2015 at 03:49:01PM +0800, Jia He wrote:
>> If there is any non zero bit in a long bitmap, it can jump out of the
>> loop and finish the function as soon as possible.
>>
>> Signed-off-by: Jia He <hejianet@gmail.com>
>> Cc: Dave Chinner <david@fromorbit.com>
>> Cc: Brian Foster <bfoster@redhat.com>
>> ---
> Looks good to me:
>
> Reviewed-by: Brian Foster <bfoster@redhat.com>
>
>> fs/xfs/libxfs/xfs_bit.c | 6 +++---
>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/fs/xfs/libxfs/xfs_bit.c b/fs/xfs/libxfs/xfs_bit.c
>> index 0e8885a..0a94cce 100644
>> --- a/fs/xfs/libxfs/xfs_bit.c
>> +++ b/fs/xfs/libxfs/xfs_bit.c
>> @@ -32,13 +32,13 @@ int
>> xfs_bitmap_empty(uint *map, uint size)
>> {
>> uint i;
>> - uint ret = 0;
>>
>> for (i = 0; i < size; i++) {
>> - ret |= map[i];
>> + if (map[i] != 0)
>> + return 0;
>> }
>>
>> - return (ret == 0);
>> + return 1;
>> }
>>
>> /*
>> --
>> 2.5.0
>>
>> _______________________________________________
>> xfs mailing list
>> xfs@oss.sgi.com
>> http://oss.sgi.com/mailman/listinfo/xfs
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
>
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-12-16 3:05 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-09 14:31 [PATCH] libxfs: Optimize the loop for xfs_bitmap_empty Jia He
2015-11-10 12:54 ` Brian Foster
2015-11-11 6:37 ` hejianet
2015-11-11 7:49 ` [PATCH v2] " Jia He
2015-11-11 12:48 ` Brian Foster
2015-12-16 3:04 ` hejianet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox