public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: fdmanana@kernel.org
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs: avoid taking the device_list_mutex in btrfs_run_dev_stats()
Date: Fri, 20 Mar 2026 22:24:35 +0100	[thread overview]
Message-ID: <20260320212435.GG5735@twin.jikos.cz> (raw)
In-Reply-To: <bf7c901abdf8279207fed149f76ce0ccc4718159.1773840032.git.fdmanana@suse.com>

On Wed, Mar 18, 2026 at 01:39:51PM +0000, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> btrfs_run_dev_stats() is called during the critical section of a
> transaction commit and it takes the device_list_mutex, which is also
> acquired by fitrim, which does discard operations while holding that
> mutex. Most of the time, if we are on a healthy filesystem, we don't have
> new stat updates to persist in the device tree, so blocking on the
> device_list_mutex is just wasting time and making any tasks that need to
> start a new transaction wait longer that necessary.
> 
> Since the device list is RCU safe/protected, make btrfs_run_dev_stats()
> do an initial check for device stat updates using RCU and quit without
> taking the device_list_mutex in case there are no new device stats that
> need to be persisted in the device tree.
> 
> Also note that adding/removing devices also requires starting a
> transaction, and since btrfs_run_dev_stats() is called from the critical
> section of a transaction commit, no one can be concurrently adding or
> removing a device while btrfs_run_dev_stats() is called.
> 
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Reviewed-by: David Sterba <dsterba@suse.com>

      reply	other threads:[~2026-03-20 21:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-18 13:39 [PATCH] btrfs: avoid taking the device_list_mutex in btrfs_run_dev_stats() fdmanana
2026-03-20 21:24 ` 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=20260320212435.GG5735@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=fdmanana@kernel.org \
    --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