All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Dilger <adilger@dilger.ca>
To: Lin Feng <linf@chinanetcenter.com>
Cc: "Theodore Ts'o" <tytso@mit.edu>,
	linux-ext4 <linux-ext4@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] ext4: mballoc.c: fix ac_g_ex and ac_f_ex misuse bug in EXT4_MB_HINT_TRY_GOAL path
Date: Tue, 7 Jun 2016 15:01:46 -0600	[thread overview]
Message-ID: <D4F0CA1E-2075-4EBE-A945-A56F6B7D6808@dilger.ca> (raw)
In-Reply-To: <1464868898-31336-1-git-send-email-linf@chinanetcenter.com>

[-- Attachment #1: Type: text/plain, Size: 2131 bytes --]

On Jun 2, 2016, at 6:01 AM, Lin Feng <linf@chinanetcenter.com> wrote:
> 
> Descriptions:
> ext4 block allocation core stack:
> ext4_mb_new_blocks
>  ext4_mb_normalize_request
>  ext4_mb_regular_allocator
>    ext4_mb_find_by_goal
>      mb_find_extent(e4b, ac->ac_g_ex.fe_start, ac->ac_g_ex.fe_len, &ex);
> 
> The start block searching hint for merging(use EXT4_MB_HINT_TRY_GOAL flag)
> set in ext4_mb_normalize_request is stored in ac_f_ex, while in
> EXT4_MB_HINT_TRY_GOAL path which falls in ext4_mb_find_by_goal always use
> ac_g_ex as a hint and the hint set in ext4_mb_normalize_request is never
> use.
> 
> We could hit this bug by writing a sparse file from backward mode and the
> file may get fragments even if the physical blocks in the hole is free,
> which is expected to be merged into a single extent.

This looks reasonable.  Do you have any kind of test case that shows the
effect of the change (e.g. fragmentation counts per file before/after)?

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

> Signed-off-by: Lin Feng <linf@chinanetcenter.com>
> ---
> fs/ext4/mballoc.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index c1ab3ec..e31fc63 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -3198,15 +3198,15 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
> 	if (ar->pright && (ar->lright == (start + size))) {
> 		/* merge to the right */
> 		ext4_get_group_no_and_offset(ac->ac_sb, ar->pright - size,
> -						&ac->ac_f_ex.fe_group,
> -						&ac->ac_f_ex.fe_start);
> +						&ac->ac_g_ex.fe_group,
> +						&ac->ac_g_ex.fe_start);
> 		ac->ac_flags |= EXT4_MB_HINT_TRY_GOAL;
> 	}
> 	if (ar->pleft && (ar->lleft + 1 == start)) {
> 		/* merge to the left */
> 		ext4_get_group_no_and_offset(ac->ac_sb, ar->pleft + 1,
> -						&ac->ac_f_ex.fe_group,
> -						&ac->ac_f_ex.fe_start);
> +						&ac->ac_g_ex.fe_group,
> +						&ac->ac_g_ex.fe_start);
> 		ac->ac_flags |= EXT4_MB_HINT_TRY_GOAL;
> 	}
> 
> --
> 1.9.3
> 
> 


Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2016-06-07 21:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-02 12:01 [PATCH] ext4: mballoc.c: fix ac_g_ex and ac_f_ex misuse bug in EXT4_MB_HINT_TRY_GOAL path Lin Feng
2016-06-06  2:23 ` Lin Feng
2016-06-07 21:01 ` Andreas Dilger [this message]
2016-06-08  6:08   ` Lin Feng
2016-06-08  6:15     ` Darrick J. Wong

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=D4F0CA1E-2075-4EBE-A945-A56F6B7D6808@dilger.ca \
    --to=adilger@dilger.ca \
    --cc=linf@chinanetcenter.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.