linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: dsterba@suse.cz, Filipe Manana <fdmanana@kernel.org>,
	linux-btrfs@vger.kernel.org, dsterba@suse.com
Subject: Re: [PATCH 0/3] btrfs: fix a couple sleeps while holding a spinlock
Date: Fri, 15 Jul 2022 15:47:34 +0300	[thread overview]
Message-ID: <383472a6-75e2-8c70-2c1e-a27234e7b761@suse.com> (raw)
In-Reply-To: <20220715120129.GA13489@twin.jikos.cz>



On 15.07.22 г. 15:01 ч., David Sterba wrote:
> On Wed, Jul 13, 2022 at 02:59:55PM +0100, Filipe Manana wrote:
>> On Wed, Jul 06, 2022 at 10:09:44AM +0100, fdmanana@kernel.org wrote:
>>> From: Filipe Manana <fdmanana@suse.com>
>>>
>>> After the recent conversions of a couple radix trees to XArrays, we now
>>> can end up attempting to sleep while holding a spinlock. This happens
>>> because if xa_insert() allocates memory (using GFP_NOFS) it may need to
>>> sleep (more likely to happen when under memory pressure). In the old
>>> code this did not happen because we had radix_tree_preload() called
>>> before taking the spinlocks.
>>>
>>> Filipe Manana (3):
>>>    btrfs: fix sleep while under a spinlock when allocating delayed inode
>>>    btrfs: fix sleep while under a spinlock when inserting a fs root
>>>    btrfs: free qgroup metadata without holding the fs roots lock
>>
>> David, are you going to pick these up or revert the patches that did the
>> radix tree to xarray conversion?
> 
> Switching sping lock to mutex seems quite heavy weight, and reverting
> xarray conversion is intrusive, so it's choosing from two bad options,
> also that we haven't identified the problems earlier. Doing such changes
> in rc6 is quite unpleasant, I'll explore the options.


I'm actually in favor of using the mutexes. For example looking at the 
users of root->inode_lock:

btrfs_prune_dentries - we hold the inode_lock and iterate the root's 
in-memory inode list until we find a starting node to start pruning. 
Pointer chasing isn't terribly performant.

fin_next_inode iin relocation - basically the same as btrfs_prune_dentries.

inode_tree_add - again, pointer chasing searching for the correct place 
to add an inode.

inode_tree_del - thiis is indeed a short critsec, but given that mutexes 
have an optimistic spin mode i don't think it'd be a problem here.


btrfs_kill_all_delayed_nodes - rather long critsec where all delayed 
inodes for a root are being iterated -> slow.


btrfs_get_delayed_node - rather short critsec, possibly handled by the 
optimistic spin mode of the mutex

btrfs_get_or_create_delayed_node - xa_insert called under it, in case of 
memory allocation - slow

__btrfs_release_delayed_node - short critsec, handled by optimistic spin

All in all to me it seems that spinlock is the wrong lock type for the 
kind of critical section being protected by it.


btrfs_fs_info::fs_roots_lock - this one indeed seems to protect mostly 
short-lived critsec but the mutexe's optimistic spin mode should handle 
it. But also looking at it I think some of the uses can be eliminated 
altogether and rely simply on the internal locking of the xarray.

  reply	other threads:[~2022-07-15 12:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-06  9:09 [PATCH 0/3] btrfs: fix a couple sleeps while holding a spinlock fdmanana
2022-07-06  9:09 ` [PATCH 1/3] btrfs: fix sleep while under a spinlock when allocating delayed inode fdmanana
2022-07-06  9:09 ` [PATCH 2/3] btrfs: fix sleep while under a spinlock when inserting a fs root fdmanana
2022-07-06  9:09 ` [PATCH 3/3] btrfs: free qgroup metadata without holding the fs roots lock fdmanana
2022-07-07 16:31 ` [PATCH 0/3] btrfs: fix a couple sleeps while holding a spinlock David Sterba
2022-07-08  0:24   ` Matthew Wilcox
2022-07-12 11:45 ` Nikolay Borisov
2022-07-13 13:59 ` Filipe Manana
2022-07-15 12:01   ` David Sterba
2022-07-15 12:47     ` Nikolay Borisov [this message]
2022-07-15 16:52       ` 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=383472a6-75e2-8c70-2c1e-a27234e7b761@suse.com \
    --to=nborisov@suse.com \
    --cc=dsterba@suse.com \
    --cc=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;
as well as URLs for NNTP newsgroup(s).