libxfs: Optimize the loop for xfs_bitmap_empty
PATCH 1/1 libxfs: Optimize the loop for xfs_bitmap_empty
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.
--- fs/xfs/libxfs/xfs_bit.c | 2 ++ 1 file changed, 2 insertions(+)
fs/xfs/libxfs/xfs_bit.c +2 -0
@@ -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 );
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 15 lines · Jia He
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 <[email protected]>Cc Dave Chinner <[email protected]>Cc Brian Foster <[email protected]>--- fs/xfs/libxfs/xfs_bit.c | 2 ++ 1 file changed, 2 insertions(+)fs/xfs/libxfs/xfs_bit.c +0
-0
fs/xfs/libxfs/xfs_bit.c xfs_bitmap_empty(uint *map, uint size) · line 42
Quoted 7 lines
fs/xfs/libxfs/xfs_bit.c +2
-0@@ -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
Quoted 8 lines
fs/xfs/libxfs/xfs_bit.c +0
-0return (ret ==0 );Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Hi Brian
Thanks, I will resend the patch V2
B.R.
Justin
Quoted 33 lines · Brian Foster
Quoted 15 lines · Jia He
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 <[email protected]>Cc Dave Chinner <[email protected]>Cc Brian Foster <[email protected]>--- fs/xfs/libxfs/xfs_bit.c | 2 ++ 1 file changed, 2 insertions(+)fs/xfs/libxfs/xfs_bit.c +0
-0fs/xfs/libxfs/xfs_bit.c xfs_bitmap_empty(uint *map, uint size) · line 42
Quoted 7 lines
fs/xfs/libxfs/xfs_bit.c +2
-0@@ -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
Quoted 4 lines
fs/xfs/libxfs/xfs_bit.c +0
-0return (ret ==0 );Signature · 1 line
2.5.0
Quoted 9 lines
Quoted 4 lines
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v2 1/1 libxfs: Optimize the loop for xfs_bitmap_empty
In reply to Brian FosterIf 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.
--- fs/xfs/libxfs/xfs_bit.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/xfs/libxfs/xfs_bit.c +3 -3
@@ -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 ; }/*
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 7 lines · Jia He
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 <[email protected]>Cc Dave Chinner <[email protected]>Cc Brian Foster <[email protected]>---
Looks good to me:
Quoted 31 lines
fs/xfs/libxfs/xfs_bit.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)fs/xfs/libxfs/xfs_bit.c +3
-3@@ -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 ; }/* Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Hi David
Do you have any comments from your point of view? Thanks ;)
B.R.
Justin
Quoted 39 lines · Brian Foster
Quoted 7 lines · Jia He
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 <[email protected]>Cc Dave Chinner <[email protected]>Cc Brian Foster <[email protected]>---
Looks good to me:
Reviewed-by Brian Foster <[email protected]>Quoted 27 lines
fs/xfs/libxfs/xfs_bit.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)fs/xfs/libxfs/xfs_bit.c +3
-3@@ -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 ; }/* Signature · 1 line
2.5.0
Quoted 9 lines
Quoted 4 lines
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs