linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Lukáš Czerner" <lczerner@redhat.com>
To: "Theodore Ts'o" <tytso@mit.edu>
Cc: Ext4 Developers List <linux-ext4@vger.kernel.org>
Subject: Re: [PATCH 2/2] libext2fs: optimize rb_test_bit
Date: Mon, 8 Oct 2012 10:08:54 +0200 (CEST)	[thread overview]
Message-ID: <alpine.LFD.2.00.1210080952390.25096@localhost> (raw)
In-Reply-To: <1349408695-11661-2-git-send-email-tytso@mit.edu>

On Thu, 4 Oct 2012, Theodore Ts'o wrote:

> Date: Thu,  4 Oct 2012 23:44:55 -0400
> 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 2/2] libext2fs: optimize rb_test_bit
> 
> Optimize testing for a bit in an rbtree-based bitmap for the case
> where the calling application is scanning through the bitmap
> sequentially.  Previously, we did this for a set of bits which were
> inside an allocated extent, but we did not optimize the case where
> there was a large number of bits after an allocated extents which were
> not in use.
> 
>              1111111111111110000000000000000000
>              ^ optimized    ^not optimized
> 
> In my tests of a roughly half-filled file system, the run time of
> e2freefrag was halved, and the cpu time spent in userspace was during
> e2fsck's pass 5 was reduced by a factor of 30%.

Hi Ted,

the patch and the idea behind it look fine, especially when we're
walking the bitmap sequentially not modifying it simultaneously, but
I have one question/suggestion below.

> 
> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
> ---
>  lib/ext2fs/blkmap64_rb.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/ext2fs/blkmap64_rb.c b/lib/ext2fs/blkmap64_rb.c
> index a83f8ac..c9006f8 100644
> --- a/lib/ext2fs/blkmap64_rb.c
> +++ b/lib/ext2fs/blkmap64_rb.c
> @@ -314,8 +314,8 @@ static errcode_t rb_resize_bmap(ext2fs_generic_bitmap bmap,
>  inline static int
>  rb_test_bit(struct ext2fs_rb_private *bp, __u64 bit)
>  {
> -	struct bmap_rb_extent *rcursor;
> -	struct rb_node *parent = NULL;
> +	struct bmap_rb_extent *rcursor, *next_ext;
> +	struct rb_node *parent = NULL, *next;
>  	struct rb_node **n = &bp->root.rb_node;
>  	struct bmap_rb_extent *ext;
>  
> @@ -330,6 +330,18 @@ rb_test_bit(struct ext2fs_rb_private *bp, __u64 bit)
>  		return 1;
>  	}
>  
> +	next = ext2fs_rb_next(&rcursor->node);
> +	if (next) {
> +		next_ext = ext2fs_rb_entry(next, struct bmap_rb_extent, node);
> +		if ((bit >= rcursor->start + rcursor->count) &&
> +		    (bit < next_ext->start)) {

what about using the next_ext once we're holding it to check the bit
? On sequential walk this shout make sense to do so since we
actually should hit this if we're not in rcursor nor between rcursor
and next_ext.

So maybe something like this ?  (untested)

	if (next && (bit >= rcursor->start + rcursor->count)) {
		next_ext = ext2fs_rb_entry(next, struct bmap_rb_extent, node);
		if (bit < next_ext->start)) {
#ifdef BMAP_STATS_OPS
			bp->test_hit++;
#endif
			return 0;
		} else if (bit < next_ext->start + next_ext->count) {
#ifdef BMAP_STATS_OPS
			bp->test_hit++;
#endif
			*bp->rcursor = next_ext;
			return 1;
		}

What do you think ? Maybe it is worth testing, whether
the advantages are higher than additional condition ?

Thanks!
-Lukas


> +	}
> +
>  	rcursor = *bp->wcursor;
>  	if (!rcursor)
>  		goto search_tree;
> 

  parent reply	other threads:[~2012-10-08  8:08 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-05  3:44 [PATCH 1/2] e2freefrag: use 64-bit rbtree bitmaps Theodore Ts'o
2012-10-05  3:44 ` [PATCH 2/2] libext2fs: optimize rb_test_bit Theodore Ts'o
2012-10-06  2:04   ` [PATCH 1/3] libext2fs: remove pointless indirection in rbtree bitmaps Theodore Ts'o
2012-10-06  2:04     ` [PATCH 2/3] libext2fs: further optimize rb_test_bit Theodore Ts'o
2012-10-06  2:04     ` [PATCH 3/3] Fix makefiles to compile e2freefrag with profiling Theodore Ts'o
2012-10-06 15:54       ` Eric Sandeen
2012-10-06 15:52     ` [PATCH 1/3] libext2fs: remove pointless indirection in rbtree bitmaps Eric Sandeen
2012-10-08  8:08   ` Lukáš Czerner [this message]
2012-10-08  8:25     ` [PATCH 2/2] libext2fs: optimize rb_test_bit Lukáš Czerner
2012-10-08 18:17       ` Theodore Ts'o
2012-10-09  7:18         ` Lukáš Czerner
2012-10-09 19:55           ` Theodore Ts'o

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.2.00.1210080952390.25096@localhost \
    --to=lczerner@redhat.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).