From: Zhang Yi <yi.zhang@huawei.com>
To: Jan Kara <jack@suse.cz>, Ritesh Harjani <ritesh.list@gmail.com>
Cc: <linux-ext4@vger.kernel.org>, <tytso@mit.edu>,
<adilger.kernel@dilger.ca>, <yukuai3@huawei.com>
Subject: Re: [PATCH] ext4: fix warning when submitting superblock in ext4_commit_super()
Date: Thu, 19 May 2022 20:33:16 +0800 [thread overview]
Message-ID: <87282095-5172-eeb0-e78f-367b19e11db4@huawei.com> (raw)
In-Reply-To: <20220519093035.2kazqodrv4nqauwf@quack3.lan>
On 2022/5/19 17:30, Jan Kara wrote:
> On Thu 19-05-22 11:59:29, Ritesh Harjani wrote:
>> On 22/05/19 11:13AM, Zhang Yi wrote:
>>> On 2022/5/19 1:06, Ritesh Harjani wrote:
>>>> On 22/05/18 10:10PM, Zhang Yi wrote:
>>>>> We have already check the io_error and uptodate flag before submitting
>>>>> the superblock buffer, and re-set the uptodate flag if it has been
>>>>> failed to write out. But it was lockless and could be raced by another
>>>>> ext4_commit_super(), and finally trigger '!uptodate' WARNING when
>>>>> marking buffer dirty. Fix it by submit buffer directly.
>>>>
>>>> I agree that there could be a race with multiple processes trying to call
>>>> ext4_commit_super(). Do you have a easy reproducer for this issue?
>>>>
>>>
>>> Sorry, I don't have a easy reproducer, but we can always reproduce it through
>>> inject delay and add filters into the ext4_commit_super().
>
> ...
>
>>>> Also do you think something like below should fix the problem too?
>>>> So if you lock the buffer from checking until marking the buffer dirty, that
>>>> should avoid the race too that you are reporting.
>>>> Thoughts?
>>>>
>>>
>>> Thanks for your suggestion. I've thought about this solution and yes it's simpler
>>> to fix the race, but I think we lock and unlock the sbh several times just for
>>> calling standard buffer write helpers is not so good. Opencode the submit
>>> procedure looks more clear to me.
>>
>> I agree your solution was cleaner since it does not has a lot of lock/unlock.
>> My suggestion came in from looking at the history.
>> This lock was added here [1] and I think it somehow got removed in this patch[2]
>>
>> [1]: https://lore.kernel.org/linux-ext4/1467285150-15977-2-git-send-email-pranjas@gmail.com/
>> [2]: https://lore.kernel.org/linux-ext4/20201216101844.22917-5-jack@suse.cz/
>
> So the reason why I've move unlock_buffer() into ext4_update_super() was
> mostly so that the function does not return with buffer lock (which is an
> odd calling convention) when I was adding another user of it
> (flush_stashed_error_work()).
>
>> Rather then solutions, I had few queries :)
>> 1. What are the implications of not using
>> mark_buffer_dirty()/__sync_dirty_buffer()
>
> Not much. Using submit_bh() directly is fine. Just the duplication of the
> checks is somewhat unpleasant.
>
>> 2. In your solution one thing which I was not clear of, was whether we
>> should call clear_buffer_dirty() before calling submit_bh(), in case if
>> somehow(?) the state of the buffer was already marked dirty? Not sure how
>> this can happen, but I see the logic in mark_buffer_dirty() which checks,
>> if the buffer is already marked dirty, it simply returns. Then
>> __sync_dirty_buffer() clears the buffer dirty state.
>
> It could happen e.g. if there was journalled update of the superblock
> before. I guess calling clear_buffer_dirty() before submit_bh() does no
> harm.
>
Thanks for point out and explain, I missed this case. Call clear_buffer_dirty()
before submit_bh() can avoid one more redundant submit by writeback process.
Thanks,
Yi.
prev parent reply other threads:[~2022-05-19 12:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-18 14:10 [PATCH] ext4: fix warning when submitting superblock in ext4_commit_super() Zhang Yi
2022-05-18 17:06 ` Ritesh Harjani
2022-05-19 3:13 ` Zhang Yi
2022-05-19 6:29 ` Ritesh Harjani
2022-05-19 9:30 ` Jan Kara
2022-05-19 10:08 ` Ritesh Harjani
2022-05-19 12:33 ` Zhang Yi [this message]
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=87282095-5172-eeb0-e78f-367b19e11db4@huawei.com \
--to=yi.zhang@huawei.com \
--cc=adilger.kernel@dilger.ca \
--cc=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
--cc=ritesh.list@gmail.com \
--cc=tytso@mit.edu \
--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