From: David Sterba <dsterba@suse.cz>
To: Josef Bacik <josef@toxicpanda.com>
Cc: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH] btrfs: do not block starts waiting on previous transaction commit
Date: Tue, 5 Sep 2023 00:32:57 +0200 [thread overview]
Message-ID: <20230904223257.GP14420@twin.jikos.cz> (raw)
In-Reply-To: <042d69d13a10b90a29b5e096db59b9669fac68d2.1692910751.git.josef@toxicpanda.com>
On Thu, Aug 24, 2023 at 04:59:22PM -0400, Josef Bacik wrote:
> Internally I got a report of very long stalls on normal operations like
> creating a new file when auto relocation was running. The reporter used
> the bpf offcputime tracer to show that we would get stuck in
> start_transaction for 5 to 30 seconds, and were always being woken up by
> the transaction commit.
>
> Using my timing-everything script, which times how long a function takes
> and what percentage of that total time is taken up by its children, I
> saw several traces like this
>
> 1083 took 32812902424 ns
> 29929002926 ns 91.2110% wait_for_commit_duration
> 25568 ns 7.7920e-05% commit_fs_roots_duration
> 1007751 ns 0.00307% commit_cowonly_roots_duration
> 446855602 ns 1.36182% btrfs_run_delayed_refs_duration
> 271980 ns 0.00082% btrfs_run_delayed_items_duration
> 2008 ns 6.1195e-06% btrfs_apply_pending_changes_duration
> 9656 ns 2.9427e-05% switch_commit_roots_duration
> 1598 ns 4.8700e-06% btrfs_commit_device_sizes_duration
> 4314 ns 1.3147e-05% btrfs_free_log_root_tree_duration
>
> Here I was only tracing functions that happen where we are between
> START_COMMIT and UNBLOCKED in order to see what would be keeping us
> blocked for so long. The wait_for_commit() we do is where we wait for a
> previous transaction that hasn't completed it's commit. This can
> include all of the unpin work and other cleanups, which tends to be the
> longest part of our transaction commit.
>
> There is no reason we should be blocking new things from entering the
> transaction at this point, it just adds to random latency spikes for no
> reason.
>
> Fix this by adding a PREP stage. This allows us to properly deal with
> multiple committers coming in at the same time, we retain the behavior
> that the winner waits on the previous transaction and the losers all
> wait for this transaction commit to occur. Nothing else is blocked
> during the PREP stage, and then once the wait is complete we switch to
> COMMIT_START and all of the same behavior as before is maintained.
>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Interesting, so splitting the state to 2 makes N threads race for the
first half and the winner proceed, not to race with any of the other
while progressing in the transaction flow. This resembles the MCS
spinlocks, the state is split into the owner of the state and the other
threads that have queued to acquire it. The transaction state is a bit
different, heavier than a spin lock, but still there's an atomic switch
once the winner finishes the work and lets the other threads race again.
Added to misc-next, thanks. As this is changing the core mechanism of a
transaction I'd rather let it get tested for a longer time so
technically this is a fix will wait a bit.
prev parent reply other threads:[~2023-09-04 22:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-24 20:59 [PATCH] btrfs: do not block starts waiting on previous transaction commit Josef Bacik
2023-08-25 11:51 ` Filipe Manana
2023-08-25 11:59 ` Filipe Manana
2023-08-25 18:38 ` Josef Bacik
2023-09-04 22:32 ` David Sterba [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=20230904223257.GP14420@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=josef@toxicpanda.com \
--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