From: Josef Bacik <josef@toxicpanda.com>
To: Boris Burkov <boris@bur.io>
Cc: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH v2] btrfs: wait for actual caching progress during allocation
Date: Tue, 25 Jul 2023 09:16:11 -0400 [thread overview]
Message-ID: <20230725131611.GA1433285@perftesting> (raw)
In-Reply-To: <20230721202817.GA558185@zen>
On Fri, Jul 21, 2023 at 01:28:17PM -0700, Boris Burkov wrote:
> On Fri, Jul 21, 2023 at 04:09:43PM -0400, Josef Bacik wrote:
> > Recently we've been having mysterious hangs while running generic/475 on
> > the CI system. This turned out to be something like this
> >
> > Task 1
> > dmsetup suspend --nolockfs
> > -> __dm_suspend
> > -> dm_wait_for_completion
> > -> dm_wait_for_bios_completion
> > -> Unable to complete because of IO's on a plug in Task 2
> >
> > Task 2
> > wb_workfn
> > -> wb_writeback
> > -> blk_start_plug
> > -> writeback_sb_inodes
> > -> Infinite loop unable to make an allocation
> >
> > Task 3
> > cache_block_group
> > ->read_extent_buffer_pages
> > ->Waiting for IO to complete that can't be submitted because Task 1
> > suspended the DM device
> >
> > The problem here is that we need Task 2 to be scheduled completely for
> > the blk plug to flush. Normally this would happen, we normally wait for
> > the block group caching to finish (Task 3), and this schedule would
> > result in the block plug flushing.
> >
> > However if there's enough free space available from the current caching
> > to satisfy the allocation we won't actually wait for the caching to
> > complete. This check however just checks that we have enough space, not
> > that we can make the allocation. In this particular case we were trying
> > to allocate 9mib, and we had 10mib of free space, but we didn't have
> > 9mib of contiguous space to allocate, and thus the allocation failed and
> > we looped.
> >
> > We specifically don't cycle through the FFE loop until we stop finding
> > cached block groups because we don't want to allocate new block groups
> > just because we're caching, so we short circuit the normal loop once we
> > hit LOOP_CACHING_WAIT and we found a caching block group.
> >
> > This is normally fine, except in this particular case where the caching
> > thread can't make progress because the dm device has been suspended.
> >
> > Fix this by not only waiting for free space to >= the amount of space we
> > want to allocate, but also that we make some progress in caching from
> > the time we start waiting. This will keep us from busy looping when the
> > caching is taking a while but still theoretically has enough space for
> > us to allocate from, and fixes this particular case by forcing us to
> > actually sleep and wait for forward progress, which will flush the plug.
> >
> > With this fix we're no longer hanging with generic/475.
> >
> > Signed-off-by: Josef Bacik <josef@toxicpanda.com>
>
> Reviewed-by: Boris Burkov <boris@bur.io>
>
> I like this fix a lot! I had missed we already block on a form of
> caching progress.
>
> One question, though:
> is the logic in release_block_group() to clear the retry bools enough to
> make sure we keep waiting on this through multiple passes so that we
> don't just fix the most common case while failing to guarantee that we
> truly always wait for forward progress?
Yes, because the bit in the update loop where if we find a block group that was
caching we'll return and keep searching through, so we won't actually progress
the loop until after all of the block groups have been completely cached.
Thanks,
Josef
next prev parent reply other threads:[~2023-07-25 13:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-21 20:09 [PATCH v2] btrfs: wait for actual caching progress during allocation Josef Bacik
2023-07-21 20:28 ` Boris Burkov
2023-07-25 13:16 ` Josef Bacik [this message]
2023-07-26 17:35 ` David Sterba
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=20230725131611.GA1433285@perftesting \
--to=josef@toxicpanda.com \
--cc=boris@bur.io \
--cc=kernel-team@fb.com \
--cc=linux-btrfs@vger.kernel.org \
/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).