linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext4: ext4_trim_fs() load buddy only when it is needed
@ 2011-04-18 16:32 Lukas Czerner
  2011-04-19 19:16 ` Amir Goldstein
  2011-05-24 22:18 ` [PATCH] ext4: ext4_trim_fs() load buddy only when it is needed Ted Ts'o
  0 siblings, 2 replies; 7+ messages in thread
From: Lukas Czerner @ 2011-04-18 16:32 UTC (permalink / raw)
  To: linux-ext4; +Cc: tytso, lczerner

Currently we are loading buddy ext4_mb_load_buddy() for every block
group we are going through in ext4_trim_fs() in many cases just to find
out that there is not enough space to be bothered with. As Amir Goldstein
suggested we can use bb_free information directly from ext4_group_info.

This commit removes ext4_mb_load_buddy() from ext4_trim_fs() and rather
get the ext4_group_info via ext4_get_group_info() and use the bb_free
information directly from that. This avoids unnecessary call to load
buddy in the case the group does not have enough free space to trim.
Loading buddy is now moved to ext4_trim_all_free().

Tested by me with xfstests 251.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
 fs/ext4/mballoc.c |   48 ++++++++++++++++++++++++++----------------------
 1 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index d8a16ee..776d7a8 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -4760,20 +4760,25 @@ static int ext4_trim_extent(struct super_block *sb, int start, int count,
  * the group buddy bitmap. This is done until whole group is scanned.
  */
 static ext4_grpblk_t
-ext4_trim_all_free(struct super_block *sb, struct ext4_buddy *e4b,
-		ext4_grpblk_t start, ext4_grpblk_t max, ext4_grpblk_t minblocks)
+ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
+		   ext4_grpblk_t start, ext4_grpblk_t max,
+		   ext4_grpblk_t minblocks)
 {
 	void *bitmap;
 	ext4_grpblk_t next, count = 0;
-	ext4_group_t group;
+	struct ext4_buddy e4b;
 	int ret = 0;
 
-	BUG_ON(e4b == NULL);
+	ret = ext4_mb_load_buddy(sb, group, &e4b);
+	if (ret) {
+		ext4_error(sb, "Error in loading buddy "
+				"information for %u", group);
+		return ret;
+	}
 
-	bitmap = e4b->bd_bitmap;
-	group = e4b->bd_group;
-	start = (e4b->bd_info->bb_first_free > start) ?
-		e4b->bd_info->bb_first_free : start;
+	bitmap = e4b.bd_bitmap;
+	start = (e4b.bd_info->bb_first_free > start) ?
+		e4b.bd_info->bb_first_free : start;
 	ext4_lock_group(sb, group);
 
 	while (start < max) {
@@ -4784,7 +4789,7 @@ ext4_trim_all_free(struct super_block *sb, struct ext4_buddy *e4b,
 
 		if ((next - start) >= minblocks) {
 			ret = ext4_trim_extent(sb, start,
-				next - start, group, e4b);
+				next - start, group, &e4b);
 			if (ret < 0)
 				break;
 			count += next - start;
@@ -4802,10 +4807,11 @@ ext4_trim_all_free(struct super_block *sb, struct ext4_buddy *e4b,
 			ext4_lock_group(sb, group);
 		}
 
-		if ((e4b->bd_info->bb_free - count) < minblocks)
+		if ((e4b.bd_info->bb_free - count) < minblocks)
 			break;
 	}
 	ext4_unlock_group(sb, group);
+	ext4_mb_unload_buddy(&e4b);
 
 	ext4_debug("trimmed %d blocks in the group %d\n",
 		count, group);
@@ -4830,11 +4836,11 @@ ext4_trim_all_free(struct super_block *sb, struct ext4_buddy *e4b,
  */
 int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
 {
-	struct ext4_buddy e4b;
+	struct ext4_group_info *grp;
 	ext4_group_t first_group, last_group;
 	ext4_group_t group, ngroups = ext4_get_groups_count(sb);
 	ext4_grpblk_t cnt = 0, first_block, last_block;
-	uint64_t start, len, minlen, trimmed;
+	uint64_t start, len, minlen, trimmed = 0;
 	ext4_fsblk_t first_data_blk =
 			le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block);
 	int ret = 0;
@@ -4842,7 +4848,6 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
 	start = range->start >> sb->s_blocksize_bits;
 	len = range->len >> sb->s_blocksize_bits;
 	minlen = range->minlen >> sb->s_blocksize_bits;
-	trimmed = 0;
 
 	if (unlikely(minlen > EXT4_BLOCKS_PER_GROUP(sb)))
 		return -EINVAL;
@@ -4863,11 +4868,12 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
 		return -EINVAL;
 
 	for (group = first_group; group <= last_group; group++) {
-		ret = ext4_mb_load_buddy(sb, group, &e4b);
-		if (ret) {
-			ext4_error(sb, "Error in loading buddy "
-					"information for %u", group);
-			break;
+		grp = ext4_get_group_info(sb, group);
+		/* We only do this if the grp has never been initialized */
+		if (unlikely(EXT4_MB_GRP_NEED_INIT(grp))) {
+			ret = ext4_mb_init_group(sb, group);
+			if (ret)
+				break;
 		}
 
 		/*
@@ -4880,16 +4886,14 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
 			last_block = first_block + len;
 		len -= last_block - first_block;
 
-		if (e4b.bd_info->bb_free >= minlen) {
-			cnt = ext4_trim_all_free(sb, &e4b, first_block,
+		if (grp->bb_free >= minlen) {
+			cnt = ext4_trim_all_free(sb, group, first_block,
 						last_block, minlen);
 			if (cnt < 0) {
 				ret = cnt;
-				ext4_mb_unload_buddy(&e4b);
 				break;
 			}
 		}
-		ext4_mb_unload_buddy(&e4b);
 		trimmed += cnt;
 		first_block = 0;
 	}
-- 
1.7.4.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] ext4: ext4_trim_fs() load buddy only when it is needed
  2011-04-18 16:32 [PATCH] ext4: ext4_trim_fs() load buddy only when it is needed Lukas Czerner
@ 2011-04-19 19:16 ` Amir Goldstein
  2011-04-21  9:36   ` Lukas Czerner
  2011-05-24 22:18 ` [PATCH] ext4: ext4_trim_fs() load buddy only when it is needed Ted Ts'o
  1 sibling, 1 reply; 7+ messages in thread
From: Amir Goldstein @ 2011-04-19 19:16 UTC (permalink / raw)
  To: Lukas Czerner; +Cc: linux-ext4, tytso

On Mon, Apr 18, 2011 at 7:32 PM, Lukas Czerner <lczerner@redhat.com> wrote:
> Currently we are loading buddy ext4_mb_load_buddy() for every block
> group we are going through in ext4_trim_fs() in many cases just to find
> out that there is not enough space to be bothered with. As Amir Goldstein
> suggested we can use bb_free information directly from ext4_group_info.
>
> This commit removes ext4_mb_load_buddy() from ext4_trim_fs() and rather
> get the ext4_group_info via ext4_get_group_info() and use the bb_free
> information directly from that. This avoids unnecessary call to load
> buddy in the case the group does not have enough free space to trim.
> Loading buddy is now moved to ext4_trim_all_free().
>
> Tested by me with xfstests 251.
>
> Signed-off-by: Lukas Czerner <lczerner@redhat.com>
> ---
>  fs/ext4/mballoc.c |   48 ++++++++++++++++++++++++++----------------------
>  1 files changed, 26 insertions(+), 22 deletions(-)
>
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index d8a16ee..776d7a8 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -4760,20 +4760,25 @@ static int ext4_trim_extent(struct super_block *sb, int start, int count,
>  * the group buddy bitmap. This is done until whole group is scanned.
>  */
>  static ext4_grpblk_t
> -ext4_trim_all_free(struct super_block *sb, struct ext4_buddy *e4b,
> -               ext4_grpblk_t start, ext4_grpblk_t max, ext4_grpblk_t minblocks)
> +ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
> +                  ext4_grpblk_t start, ext4_grpblk_t max,
> +                  ext4_grpblk_t minblocks)
>  {
>        void *bitmap;
>        ext4_grpblk_t next, count = 0;
> -       ext4_group_t group;
> +       struct ext4_buddy e4b;
>        int ret = 0;
>
> -       BUG_ON(e4b == NULL);
> +       ret = ext4_mb_load_buddy(sb, group, &e4b);
> +       if (ret) {
> +               ext4_error(sb, "Error in loading buddy "
> +                               "information for %u", group);
> +               return ret;
> +       }
>
> -       bitmap = e4b->bd_bitmap;
> -       group = e4b->bd_group;
> -       start = (e4b->bd_info->bb_first_free > start) ?
> -               e4b->bd_info->bb_first_free : start;
> +       bitmap = e4b.bd_bitmap;
> +       start = (e4b.bd_info->bb_first_free > start) ?
> +               e4b.bd_info->bb_first_free : start;

not related to the patch, but bb_first_free sound like something that
needs lock_group
protection. I didn't check it though.
other than that, patch looks fine to me.

>        ext4_lock_group(sb, group);
>
>        while (start < max) {
> @@ -4784,7 +4789,7 @@ ext4_trim_all_free(struct super_block *sb, struct ext4_buddy *e4b,
>
>                if ((next - start) >= minblocks) {
>                        ret = ext4_trim_extent(sb, start,
> -                               next - start, group, e4b);
> +                               next - start, group, &e4b);
>                        if (ret < 0)
>                                break;
>                        count += next - start;
> @@ -4802,10 +4807,11 @@ ext4_trim_all_free(struct super_block *sb, struct ext4_buddy *e4b,
>                        ext4_lock_group(sb, group);
>                }
>
> -               if ((e4b->bd_info->bb_free - count) < minblocks)
> +               if ((e4b.bd_info->bb_free - count) < minblocks)
>                        break;
>        }
>        ext4_unlock_group(sb, group);
> +       ext4_mb_unload_buddy(&e4b);
>
>        ext4_debug("trimmed %d blocks in the group %d\n",
>                count, group);
> @@ -4830,11 +4836,11 @@ ext4_trim_all_free(struct super_block *sb, struct ext4_buddy *e4b,
>  */
>  int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
>  {
> -       struct ext4_buddy e4b;
> +       struct ext4_group_info *grp;
>        ext4_group_t first_group, last_group;
>        ext4_group_t group, ngroups = ext4_get_groups_count(sb);
>        ext4_grpblk_t cnt = 0, first_block, last_block;
> -       uint64_t start, len, minlen, trimmed;
> +       uint64_t start, len, minlen, trimmed = 0;
>        ext4_fsblk_t first_data_blk =
>                        le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block);
>        int ret = 0;
> @@ -4842,7 +4848,6 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
>        start = range->start >> sb->s_blocksize_bits;
>        len = range->len >> sb->s_blocksize_bits;
>        minlen = range->minlen >> sb->s_blocksize_bits;
> -       trimmed = 0;
>
>        if (unlikely(minlen > EXT4_BLOCKS_PER_GROUP(sb)))
>                return -EINVAL;
> @@ -4863,11 +4868,12 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
>                return -EINVAL;
>
>        for (group = first_group; group <= last_group; group++) {
> -               ret = ext4_mb_load_buddy(sb, group, &e4b);
> -               if (ret) {
> -                       ext4_error(sb, "Error in loading buddy "
> -                                       "information for %u", group);
> -                       break;
> +               grp = ext4_get_group_info(sb, group);
> +               /* We only do this if the grp has never been initialized */
> +               if (unlikely(EXT4_MB_GRP_NEED_INIT(grp))) {
> +                       ret = ext4_mb_init_group(sb, group);
> +                       if (ret)
> +                               break;
>                }
>
>                /*
> @@ -4880,16 +4886,14 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
>                        last_block = first_block + len;
>                len -= last_block - first_block;
>
> -               if (e4b.bd_info->bb_free >= minlen) {
> -                       cnt = ext4_trim_all_free(sb, &e4b, first_block,
> +               if (grp->bb_free >= minlen) {
> +                       cnt = ext4_trim_all_free(sb, group, first_block,
>                                                last_block, minlen);
>                        if (cnt < 0) {
>                                ret = cnt;
> -                               ext4_mb_unload_buddy(&e4b);
>                                break;
>                        }
>                }
> -               ext4_mb_unload_buddy(&e4b);
>                trimmed += cnt;
>                first_block = 0;
>        }
> --
> 1.7.4.2
>
> --
> 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
>
--
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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] ext4: ext4_trim_fs() load buddy only when it is needed
  2011-04-19 19:16 ` Amir Goldstein
@ 2011-04-21  9:36   ` Lukas Czerner
  2011-04-21 10:26     ` [PATCH] ext4: protect bb_first_free in ext4_trim_all_free() with group lock Lukas Czerner
  0 siblings, 1 reply; 7+ messages in thread
From: Lukas Czerner @ 2011-04-21  9:36 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: Lukas Czerner, linux-ext4, tytso

[-- Attachment #1: Type: TEXT/PLAIN, Size: 7200 bytes --]

On Tue, 19 Apr 2011, Amir Goldstein wrote:

> On Mon, Apr 18, 2011 at 7:32 PM, Lukas Czerner <lczerner@redhat.com> wrote:
> > Currently we are loading buddy ext4_mb_load_buddy() for every block
> > group we are going through in ext4_trim_fs() in many cases just to find
> > out that there is not enough space to be bothered with. As Amir Goldstein
> > suggested we can use bb_free information directly from ext4_group_info.
> >
> > This commit removes ext4_mb_load_buddy() from ext4_trim_fs() and rather
> > get the ext4_group_info via ext4_get_group_info() and use the bb_free
> > information directly from that. This avoids unnecessary call to load
> > buddy in the case the group does not have enough free space to trim.
> > Loading buddy is now moved to ext4_trim_all_free().
> >
> > Tested by me with xfstests 251.
> >
> > Signed-off-by: Lukas Czerner <lczerner@redhat.com>
> > ---
> >  fs/ext4/mballoc.c |   48 ++++++++++++++++++++++++++----------------------
> >  1 files changed, 26 insertions(+), 22 deletions(-)
> >
> > diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> > index d8a16ee..776d7a8 100644
> > --- a/fs/ext4/mballoc.c
> > +++ b/fs/ext4/mballoc.c
> > @@ -4760,20 +4760,25 @@ static int ext4_trim_extent(struct super_block *sb, int start, int count,
> >  * the group buddy bitmap. This is done until whole group is scanned.
> >  */
> >  static ext4_grpblk_t
> > -ext4_trim_all_free(struct super_block *sb, struct ext4_buddy *e4b,
> > -               ext4_grpblk_t start, ext4_grpblk_t max, ext4_grpblk_t minblocks)
> > +ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
> > +                  ext4_grpblk_t start, ext4_grpblk_t max,
> > +                  ext4_grpblk_t minblocks)
> >  {
> >        void *bitmap;
> >        ext4_grpblk_t next, count = 0;
> > -       ext4_group_t group;
> > +       struct ext4_buddy e4b;
> >        int ret = 0;
> >
> > -       BUG_ON(e4b == NULL);
> > +       ret = ext4_mb_load_buddy(sb, group, &e4b);
> > +       if (ret) {
> > +               ext4_error(sb, "Error in loading buddy "
> > +                               "information for %u", group);
> > +               return ret;
> > +       }
> >
> > -       bitmap = e4b->bd_bitmap;
> > -       group = e4b->bd_group;
> > -       start = (e4b->bd_info->bb_first_free > start) ?
> > -               e4b->bd_info->bb_first_free : start;
> > +       bitmap = e4b.bd_bitmap;
> > +       start = (e4b.bd_info->bb_first_free > start) ?
> > +               e4b.bd_info->bb_first_free : start;
> 
> not related to the patch, but bb_first_free sound like something that
> needs lock_group
> protection. I didn't check it though.
> other than that, patch looks fine to me.

Yes, you're right. I'll send the fix in separate patch based on this
commit.

Thanks for noticing.

-Lukas

> 
> >        ext4_lock_group(sb, group);
> >
> >        while (start < max) {
> > @@ -4784,7 +4789,7 @@ ext4_trim_all_free(struct super_block *sb, struct ext4_buddy *e4b,
> >
> >                if ((next - start) >= minblocks) {
> >                        ret = ext4_trim_extent(sb, start,
> > -                               next - start, group, e4b);
> > +                               next - start, group, &e4b);
> >                        if (ret < 0)
> >                                break;
> >                        count += next - start;
> > @@ -4802,10 +4807,11 @@ ext4_trim_all_free(struct super_block *sb, struct ext4_buddy *e4b,
> >                        ext4_lock_group(sb, group);
> >                }
> >
> > -               if ((e4b->bd_info->bb_free - count) < minblocks)
> > +               if ((e4b.bd_info->bb_free - count) < minblocks)
> >                        break;
> >        }
> >        ext4_unlock_group(sb, group);
> > +       ext4_mb_unload_buddy(&e4b);
> >
> >        ext4_debug("trimmed %d blocks in the group %d\n",
> >                count, group);
> > @@ -4830,11 +4836,11 @@ ext4_trim_all_free(struct super_block *sb, struct ext4_buddy *e4b,
> >  */
> >  int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
> >  {
> > -       struct ext4_buddy e4b;
> > +       struct ext4_group_info *grp;
> >        ext4_group_t first_group, last_group;
> >        ext4_group_t group, ngroups = ext4_get_groups_count(sb);
> >        ext4_grpblk_t cnt = 0, first_block, last_block;
> > -       uint64_t start, len, minlen, trimmed;
> > +       uint64_t start, len, minlen, trimmed = 0;
> >        ext4_fsblk_t first_data_blk =
> >                        le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block);
> >        int ret = 0;
> > @@ -4842,7 +4848,6 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
> >        start = range->start >> sb->s_blocksize_bits;
> >        len = range->len >> sb->s_blocksize_bits;
> >        minlen = range->minlen >> sb->s_blocksize_bits;
> > -       trimmed = 0;
> >
> >        if (unlikely(minlen > EXT4_BLOCKS_PER_GROUP(sb)))
> >                return -EINVAL;
> > @@ -4863,11 +4868,12 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
> >                return -EINVAL;
> >
> >        for (group = first_group; group <= last_group; group++) {
> > -               ret = ext4_mb_load_buddy(sb, group, &e4b);
> > -               if (ret) {
> > -                       ext4_error(sb, "Error in loading buddy "
> > -                                       "information for %u", group);
> > -                       break;
> > +               grp = ext4_get_group_info(sb, group);
> > +               /* We only do this if the grp has never been initialized */
> > +               if (unlikely(EXT4_MB_GRP_NEED_INIT(grp))) {
> > +                       ret = ext4_mb_init_group(sb, group);
> > +                       if (ret)
> > +                               break;
> >                }
> >
> >                /*
> > @@ -4880,16 +4886,14 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
> >                        last_block = first_block + len;
> >                len -= last_block - first_block;
> >
> > -               if (e4b.bd_info->bb_free >= minlen) {
> > -                       cnt = ext4_trim_all_free(sb, &e4b, first_block,
> > +               if (grp->bb_free >= minlen) {
> > +                       cnt = ext4_trim_all_free(sb, group, first_block,
> >                                                last_block, minlen);
> >                        if (cnt < 0) {
> >                                ret = cnt;
> > -                               ext4_mb_unload_buddy(&e4b);
> >                                break;
> >                        }
> >                }
> > -               ext4_mb_unload_buddy(&e4b);
> >                trimmed += cnt;
> >                first_block = 0;
> >        }
> > --
> > 1.7.4.2
> >
> > --
> > 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
> >
> --
> 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
> 

-- 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] ext4: protect bb_first_free in ext4_trim_all_free() with group lock
  2011-04-21  9:36   ` Lukas Czerner
@ 2011-04-21 10:26     ` Lukas Czerner
       [not found]       ` <20110421110120.GB11901@bitwizard.nl>
  2011-05-24 22:32       ` Ted Ts'o
  0 siblings, 2 replies; 7+ messages in thread
From: Lukas Czerner @ 2011-04-21 10:26 UTC (permalink / raw)
  To: linux-ext4; +Cc: tytso, amir73il, Lukas Czerner

We should protect reading bd_info->bb_first_free with the group lock
because otherwise we might miss some free blocks. This is not a big deal
at all, but the change to do right thing is really simple, so lets do
that.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
 fs/ext4/mballoc.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 776d7a8..804232a 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -4775,11 +4775,11 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
 				"information for %u", group);
 		return ret;
 	}

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] ext4: protect bb_first_free in ext4_trim_all_free() with group lock
       [not found]       ` <20110421110120.GB11901@bitwizard.nl>
@ 2011-04-21 11:10         ` Lukas Czerner
  0 siblings, 0 replies; 7+ messages in thread
From: Lukas Czerner @ 2011-04-21 11:10 UTC (permalink / raw)
  To: Rogier Wolff; +Cc: Lukas Czerner, linux-ext4

On Thu, 21 Apr 2011, Rogier Wolff wrote:

> 
> Hi Lukas, 

Hi Rogier,

> 
> IMHO, I think it was written intentionally like that. You do as much
> as you can outside "having the lock", especially these "search" things
> are written this way. Doing it this way means that there is less
> lock-contention when things get busy.
> 
> Now I agree that this one statement without any function calls is
> going to be reasonably fast on any modern hardware...
> 
> 	Roger. 
> 
> 
>  	bitmap = e4b.bd_bitmap;
> +
> +	/* we take the lock AFTER this statement because if it
> +	   gets modified under us we'll correct later. */ 

The comment is not right. We do not correct it later in the case that
some space was freed and we still have the old value, hence skipping the
difference between the old and the new bb_first_free. As I mentioned in
the description this is not a big deal, but the fix is simple enough and
there is absolutely no "slowdown" in moving one simple condition into
critical section.

Thanks!
-Lukas

>  	start = (e4b.bd_info->bb_first_free > start) ?
>  		e4b.bd_info->bb_first_free : start;
> 	ext4_lock_group(sb, group);
>  
>  	while (start < max) {
>  		start = mb_find_next_zero_bit(bitmap, max, start);
> 
> 
> On Thu, Apr 21, 2011 at 12:26:36PM +0200, Lukas Czerner wrote:
> > We should protect reading bd_info->bb_first_free with the group lock
> > because otherwise we might miss some free blocks. This is not a big deal
> > at all, but the change to do right thing is really simple, so lets do
> > that.
> > 
> > Signed-off-by: Lukas Czerner <lczerner@redhat.com>
> > ---
> >  fs/ext4/mballoc.c |    4 ++--
> >  1 files changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> > index 776d7a8..804232a 100644
> > --- a/fs/ext4/mballoc.c
> > +++ b/fs/ext4/mballoc.c
> > @@ -4775,11 +4775,11 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
> >  				"information for %u", group);
> >  		return ret;
> >  	}
> > -
> >  	bitmap = e4b.bd_bitmap;
> > +
> > +	ext4_lock_group(sb, group);
> >  	start = (e4b.bd_info->bb_first_free > start) ?
> >  		e4b.bd_info->bb_first_free : start;
> > -	ext4_lock_group(sb, group);
> >  
> >  	while (start < max) {
> >  		start = mb_find_next_zero_bit(bitmap, max, start);
> > -- 
> > 1.7.4.4
> > 
> > --
> > 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
> 
> 

-- 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] ext4: ext4_trim_fs() load buddy only when it is needed
  2011-04-18 16:32 [PATCH] ext4: ext4_trim_fs() load buddy only when it is needed Lukas Czerner
  2011-04-19 19:16 ` Amir Goldstein
@ 2011-05-24 22:18 ` Ted Ts'o
  1 sibling, 0 replies; 7+ messages in thread
From: Ted Ts'o @ 2011-05-24 22:18 UTC (permalink / raw)
  To: Lukas Czerner; +Cc: linux-ext4

On Mon, Apr 18, 2011 at 06:32:31PM +0200, Lukas Czerner wrote:
> Currently we are loading buddy ext4_mb_load_buddy() for every block
> group we are going through in ext4_trim_fs() in many cases just to find
> out that there is not enough space to be bothered with. As Amir Goldstein
> suggested we can use bb_free information directly from ext4_group_info.
> 
> This commit removes ext4_mb_load_buddy() from ext4_trim_fs() and rather
> get the ext4_group_info via ext4_get_group_info() and use the bb_free
> information directly from that. This avoids unnecessary call to load
> buddy in the case the group does not have enough free space to trim.
> Loading buddy is now moved to ext4_trim_all_free().
> 
> Tested by me with xfstests 251.
> 
> Signed-off-by: Lukas Czerner <lczerner@redhat.com>

I just added this patch to the ext4 tree.  Apologies for not noticing
it earlier.  I had to make a few adjustments to make the patch apply,
but nothing major.

						- Ted

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] ext4: protect bb_first_free in ext4_trim_all_free() with group lock
  2011-04-21 10:26     ` [PATCH] ext4: protect bb_first_free in ext4_trim_all_free() with group lock Lukas Czerner
       [not found]       ` <20110421110120.GB11901@bitwizard.nl>
@ 2011-05-24 22:32       ` Ted Ts'o
  1 sibling, 0 replies; 7+ messages in thread
From: Ted Ts'o @ 2011-05-24 22:32 UTC (permalink / raw)
  To: Lukas Czerner; +Cc: linux-ext4, amir73il

On Thu, Apr 21, 2011 at 12:26:36PM +0200, Lukas Czerner wrote:
> We should protect reading bd_info->bb_first_free with the group lock
> because otherwise we might miss some free blocks. This is not a big deal
> at all, but the change to do right thing is really simple, so lets do
> that.
> 
> Signed-off-by: Lukas Czerner <lczerner@redhat.com>

Added to the ext4 tree, thanks.

						- Ted

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-05-24 22:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-18 16:32 [PATCH] ext4: ext4_trim_fs() load buddy only when it is needed Lukas Czerner
2011-04-19 19:16 ` Amir Goldstein
2011-04-21  9:36   ` Lukas Czerner
2011-04-21 10:26     ` [PATCH] ext4: protect bb_first_free in ext4_trim_all_free() with group lock Lukas Czerner
     [not found]       ` <20110421110120.GB11901@bitwizard.nl>
2011-04-21 11:10         ` Lukas Czerner
2011-05-24 22:32       ` Ted Ts'o
2011-05-24 22:18 ` [PATCH] ext4: ext4_trim_fs() load buddy only when it is needed Ted Ts'o

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).