linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Ritesh Harjani <ritesh.list@gmail.com>
Cc: Jan Kara <jack@suse.cz>, Baokun Li <libaokun1@huawei.com>,
	linux-ext4@vger.kernel.org, tytso@mit.edu,
	adilger.kernel@dilger.ca, linux-kernel@vger.kernel.org,
	yi.zhang@huawei.com, yebin10@huawei.com, yukuai3@huawei.com
Subject: Re: [PATCH 2/2] ext4: correct the judgment of BUG in ext4_mb_normalize_request
Date: Tue, 24 May 2022 11:39:33 +0200	[thread overview]
Message-ID: <20220524093933.bittzsrrpddttnab@quack3.lan> (raw)
In-Reply-To: <20220524062655.ddiltnfxxhlelfgb@riteshh-domain>

On Tue 24-05-22 11:56:55, Ritesh Harjani wrote:
> On 22/05/23 11:08PM, Jan Kara wrote:
> > On Tue 24-05-22 01:38:44, Ritesh Harjani wrote:
> > > On 22/05/21 09:42PM, Baokun Li wrote:
> > > > When either of the "start + size <= ac->ac_o_ex.fe_logical" or
> > > > "start > ac->ac_o_ex.fe_logical" conditions is met, it indicates
> > > > that the fe_logical is not in the allocated range.
> > >
> > > Sounds about right to me based on the logic in ext4_mb_use_inode_pa().
> > > We try to allocate/preallocate such that ac->ac_o_ex.fe_logical should fall
> > > within the preallocated range. So if our start or start + size doesn't include
> > > fe_logical then it is a bug in the ext4_mb_normalize_request() logic.
> >
> > I agree ac->ac_o_ex.fe_logical is a goal block. But AFAIK it never was a
> > hard guarantee that we would allocate extent that includes that block. It
> 
> Agree that the guarantee is not about the extent which finally gets allocated.
> It is only within ext4_mb_normalize_request() that the "start" and "size"
> variable calculations is done in such a way that the ac->ac_o_ex.fe_logical
> block will always fall within the "start" & "end" boundaries after
> normalization.
> 
> That is how it also updates the goal block at the end too. ac->ac_g_ex.
> 
> > was always treated as a hint only. In particular if you look at the logic
> > in ext4_mb_normalize_request() it does shift the start of the allocation to
> > avoid preallocated ranges etc.
> 
> Yes, I checked the logic of ext4_mb_normalize_request() again.
> As I see it (I can be wrong, so please correct me), there is always an attempt
> to make "start" & "start + size" such that it covers ac->ac_o_ex.fe_logical
> except just one change where we are trimming the size of the request to only
> EXT4_BLOCKS_PER_GROUP.
> 
> For e.g. when it compares against preallocated ranges. It has a BUG() which
> checks if the ac->ac_o_ex.fe_logical already lies in the preallocated range.
> Because then we should never have come here to do allocation of a new block.
> 
> 4143                 /* PA must not overlap original request */
> 4144                 BUG_ON(!(ac->ac_o_ex.fe_logical >= pa_end ||
> 4145                         ac->ac_o_ex.fe_logical < pa->pa_lstart));
> <...>
> 4152                 BUG_ON(pa->pa_lstart <= start && pa_end >= end);
> 
> Then after skipping the preallocated regions which doesn't fall in between
> "start" and "end"...
> 
> 4147                 /* skip PAs this normalized request doesn't overlap with */
> 4148                 if (pa->pa_lstart >= end || pa_end <= start) {
> 4149                         spin_unlock(&pa->pa_lock);
> 4150                         continue;
> 4151                 }
> 
> ...it adjusts "start" and "end" boundary according to allocated PAs boundaries
> such that fe_logical is always in between "start" and "end".
> 
> 4154                 /* adjust start or end to be adjacent to this pa */
> 4155                 if (pa_end <= ac->ac_o_ex.fe_logical) {
> 4156                         BUG_ON(pa_end < start);
> 4157                         start = pa_end;
> 4158                 } else if (pa->pa_lstart > ac->ac_o_ex.fe_logical) {
> 4159                         BUG_ON(pa->pa_lstart > end);
> 4160                         end = pa->pa_lstart;
> 4161                 }
> 
> 
> 
> > so I don't see how we are guaranteed that
> > ext4_mb_normalize_request() will result in an allocation request that
> > includes ac->ac_o_ex.fe_logical.
> 
> It could be I am wrong, but looks like ext4_mb_normalize_request() keeps
> ac->ac_o_ex.fe_logical within "start" and "end" of allocation request.
> And then updates the goal block.
> 
> 4196         ac->ac_g_ex.fe_logical = start;
> 4197         ac->ac_g_ex.fe_len = EXT4_NUM_B2C(sbi, size);
> 
> Thoughts?

Right, after some more inspection the only thing I'm concerned about is:

        /* don't cover already allocated blocks in selected range */
        if (ar->pleft && start <= ar->lleft) {
                size -= ar->lleft + 1 - start;
                start = ar->lleft + 1;
        }

which can shift start beyond ac->ac_o_ex.fe_logical if the block would be
already allocated. But I guess in that case we should not be calling
ext4_mb_normalize_request()? ... some more code digging .. Yes, that is
guaranteed in how lleft is initialized in ext4_ext_map_blocks(). So OK, I
withdraw my objection to the stronger check but the changelog really needs
to do a better job to explain why the stronger condition should be true.

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2022-05-24  9:39 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-21 13:42 [PATCH 0/2] ext4: fix two bugs in ext4_mb_normalize_request Baokun Li
2022-05-21 13:42 ` [PATCH 1/2] ext4: fix bug_on ext4_mb_use_inode_pa Baokun Li
2022-05-23  9:29   ` Jan Kara
2022-05-23  9:58   ` Lukas Czerner
     [not found]     ` <2525e39a-5be9-bae1-b77d-60f583892868@huawei.com>
2022-05-24 12:11       ` Lukas Czerner
2022-05-24 12:42         ` Baokun Li
2022-05-23 19:51   ` Ritesh Harjani
2022-05-21 13:42 ` [PATCH 2/2] ext4: correct the judgment of BUG in ext4_mb_normalize_request Baokun Li
2022-05-23  9:40   ` Jan Kara
     [not found]     ` <3755e40b-f817-83df-b239-b0697976c272@huawei.com>
2022-05-24  9:30       ` Jan Kara
2022-05-24 13:44         ` Baokun Li
2022-05-25 11:29           ` Jan Kara
2022-05-26  1:16             ` Baokun Li
2022-05-23 10:05   ` Lukas Czerner
2022-05-23 20:08   ` Ritesh Harjani
2022-05-23 21:08     ` Jan Kara
2022-05-24  6:26       ` Ritesh Harjani
2022-05-24  9:39         ` Jan Kara [this message]
2022-05-24 17:31           ` Ritesh Harjani
2022-05-25 12:12             ` Jan Kara
2022-05-24  6:09     ` Baokun Li

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=20220524093933.bittzsrrpddttnab@quack3.lan \
    --to=jack@suse.cz \
    --cc=adilger.kernel@dilger.ca \
    --cc=libaokun1@huawei.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ritesh.list@gmail.com \
    --cc=tytso@mit.edu \
    --cc=yebin10@huawei.com \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai3@huawei.com \
    /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).