Message ID | 1353803794-11593-6-git-send-email-tytso@mit.edu |
---|---|
State | Superseded, archived |
Headers | show |
On Sat, 24 Nov 2012, Theodore Ts'o wrote: > Date: Sat, 24 Nov 2012 19:36:33 -0500 > From: Theodore Ts'o <tytso@mit.edu> > To: Ext4 Developers List <linux-ext4@vger.kernel.org> > Cc: Theodore Ts'o <tytso@mit.edu> > Subject: [PATCH 5/6] libext2fs: optimize rb_get_bmap_range() for mostly > allocated bmaps > > This optimizies the CPU utilization of the rb_get_bmap_range() > function when most of the bitmap is allocated. > > Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> > --- > lib/ext2fs/blkmap64_rb.c | 29 ++++++++++++++++++++++++----- > 1 file changed, 24 insertions(+), 5 deletions(-) > > diff --git a/lib/ext2fs/blkmap64_rb.c b/lib/ext2fs/blkmap64_rb.c > index 0705cf2..3a5518b 100644 > --- a/lib/ext2fs/blkmap64_rb.c > +++ b/lib/ext2fs/blkmap64_rb.c > @@ -721,6 +721,7 @@ static errcode_t rb_get_bmap_range(ext2fs_generic_bitmap bitmap, > struct rb_node *parent = NULL, *next, **n; > struct ext2fs_rb_private *bp; > struct bmap_rb_extent *ext; > + int count; > __u64 pos; > > bp = (struct ext2fs_rb_private *) bitmap->private; > @@ -748,14 +749,32 @@ static errcode_t rb_get_bmap_range(ext2fs_generic_bitmap bitmap, > ext = ext2fs_rb_entry(parent, struct bmap_rb_extent, node); > > pos = ext->start; > - if (pos < start) > + count = ext->count; > + if (pos > start+num) Missing spacing around '+'. Also I think that the condition should rather be: if (pos >= start + num) > + break; > + if (pos < start) { > + count -= start - pos; > + if (count < 0) > + continue; > pos = start; > - > - while (pos < (ext->start + ext->count)) { > - if ((pos - start) >= num) > - return 0; > + } > + if (pos+count > start+num) > + count = start+num - pos; missing spacing around '+' > + > + while (count > 0) { > + if ((count >= 8) && > + ((pos - start) % 8) == 0) { > + int nbytes = count >> 3; > + int offset = (pos -start) >> 3; missing spacing around '-' > + > + memset(out + offset, 0xFF, nbytes); > + pos += nbytes << 3; > + count -= nbytes << 3; > + continue; > + } > ext2fs_fast_set_bit64((pos - start), out); > pos++; > + count--; > } > } > return 0; > -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Mon, Nov 26, 2012 at 12:22:42PM +0100, Lukáš Czerner wrote: > > + if (pos > start+num) > > Missing spacing around '+'. I'll fix all of the spacing comments, thanks. > Also I think that the condition should rather be: > > if (pos >= start + num) Yes. I believe the case where pos = start + num gets caught later on when we check the count variable, but it's cleaner/faster to bail out here. - Ted -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/lib/ext2fs/blkmap64_rb.c b/lib/ext2fs/blkmap64_rb.c index 0705cf2..3a5518b 100644 --- a/lib/ext2fs/blkmap64_rb.c +++ b/lib/ext2fs/blkmap64_rb.c @@ -721,6 +721,7 @@ static errcode_t rb_get_bmap_range(ext2fs_generic_bitmap bitmap, struct rb_node *parent = NULL, *next, **n; struct ext2fs_rb_private *bp; struct bmap_rb_extent *ext; + int count; __u64 pos; bp = (struct ext2fs_rb_private *) bitmap->private; @@ -748,14 +749,32 @@ static errcode_t rb_get_bmap_range(ext2fs_generic_bitmap bitmap, ext = ext2fs_rb_entry(parent, struct bmap_rb_extent, node); pos = ext->start; - if (pos < start) + count = ext->count; + if (pos > start+num) + break; + if (pos < start) { + count -= start - pos; + if (count < 0) + continue; pos = start; - - while (pos < (ext->start + ext->count)) { - if ((pos - start) >= num) - return 0; + } + if (pos+count > start+num) + count = start+num - pos; + + while (count > 0) { + if ((count >= 8) && + ((pos - start) % 8) == 0) { + int nbytes = count >> 3; + int offset = (pos -start) >> 3; + + memset(out + offset, 0xFF, nbytes); + pos += nbytes << 3; + count -= nbytes << 3; + continue; + } ext2fs_fast_set_bit64((pos - start), out); pos++; + count--; } } return 0;
This optimizies the CPU utilization of the rb_get_bmap_range() function when most of the bitmap is allocated. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> --- lib/ext2fs/blkmap64_rb.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-)